changed locality for variables in NumberController

This commit is contained in:
jonobr1 2011-01-24 13:22:09 -08:00
parent e96f7110f7
commit ea8d324f1e
2 changed files with 41 additions and 45 deletions

View File

@ -8,70 +8,65 @@ var NumberController = function() {
var _this = this; var _this = this;
this.isClicked = false; var isClicked = false;
this.py = this.y = this.initialValue = this.object[this.propertyName]; var y, py, initialValue, inc;
this.inc = 0;
// Get min and max py = y = 0;
(arguments[2] != null) ? this.min = arguments[2] : this.min = null; inc = initialValue = this.object[this.propertyName];
(arguments[3] != null) ? this.max = arguments[3] : this.max = null;
this.button = document.createElement('input'); var min, max;
this.button.setAttribute('id', this.propertyName); (arguments[2] != null) ? min = arguments[2] : min = null;
(arguments[3] != null) ? max = arguments[3] : max = null;
this.button.setAttribute('type', this.type); var button = document.createElement('input');
this.button.setAttribute('value', this.inc); button.setAttribute('id', this.propertyName);
this.domElement.appendChild(this.button); button.setAttribute('type', this.type);
button.setAttribute('value', inc)
this.domElement.appendChild(button);
this.button.onmousedown = function(e) { button.onmousedown = function(e) {
_this.isClicked = true; isClicked = true;
}; };
this.button.onkeyup = function(e) { button.onkeyup = function(e) {
var val = parseFloat(this.value);
var val = parseFloat(_this.button.value);
if(isNaN(val)) { if(isNaN(val)) {
_this.inc = _this.initialValue; inc = initialValue;
} else { } else {
_this.inc = val; inc = val;
} }
_this.button.value = _this.inc; this.value = inc;
_this.setValue(_this.inc); _this.setValue(inc);
}; }
document.onmouseup = function(e) { document.onmouseup = function(e) {
_this.isClicked = false; isClicked = false;
}; };
document.onmousemove = function(e) { document.onmousemove = function(e) {
if(isClicked) {
if(_this.isClicked) {
e.preventDefault(); e.preventDefault();
py = y;
_this.py = _this.y; y = e.offsetY;
_this.y = e.offsetY; var dy = y - py;
var dy = _this.y - _this.py; if(dy < 0) {
if(max != null)
if(dy > 0) { (inc >= max) ? inc = max : inc++;
if(_this.max != null)
(_this.inc >= _this.max) ? _this.inc = _this.max : _this.inc++;
else else
_this.inc++; inc++;
} else if(dy < 0) { } else if(dy > 0) {
if(_this.min != null) if(min != null)
(_this.inc <= _this.min) ? _this.inc = _this.min : _this.inc--; (inc <= min) ? inc = min : inc--;
else else
_this.inc--; inc--;
} }
button.value = inc;
_this.button.value = _this.inc; _this.setValue(inc);
_this.setValue(_this.inc);
} }
}; };
this.__defineSetter__("position", function(val) { this.__defineSetter__("position", function(val) {
_this.inc = val; inc = val;
_this.button.value = _this.inc; button.value = inc;
_this.setValue(_this.inc); _this.setValue(inc);
// possibly push to an array here so that // possibly push to an array here so that
// we have a record of "defined" / "presets" // we have a record of "defined" / "presets"
// ???? // ????

View File

@ -15,6 +15,7 @@ var controllableObject =
numberProperty: 20, numberProperty: 20,
constrainedNum: 0, constrainedNum: 0,
textProperty: "a string", textProperty: "a string",
anotherTextProperty: "another string",
booleanProperty: false, booleanProperty: false,
functionProperty: function() { functionProperty: function() {
alert("I am a function!"); alert("I am a function!");