min and max added to NumberController

This commit is contained in:
jonobr1 2011-01-23 16:47:26 -08:00
parent 8eafa82deb
commit 9394f945bd
3 changed files with 36 additions and 8 deletions

View File

@ -17,6 +17,12 @@ var NumberController = function() {
this.inc = 0; // TODO pass argument to inc this.inc = 0; // TODO pass argument to inc
this.button; this.button;
console.log(arguments);
// Get min and max
(arguments[2] != null) ? this.min = arguments[2] : this.min = null;
(arguments[3] != null) ? this.max = arguments[3] : this.max = null;
this.button = document.createElement('input'); this.button = document.createElement('input');
this.button.setAttribute('id', this.propertyName); this.button.setAttribute('id', this.propertyName);
this.button.setAttribute('type', 'number'); this.button.setAttribute('type', 'number');
@ -37,12 +43,27 @@ var NumberController = function() {
_this.y = e.offsetY; _this.y = e.offsetY;
var dy = _this.y - _this.py; var dy = _this.y - _this.py;
if(dy > 0) if(dy > 0) {
_this.button.setAttribute('value', _this.inc++); if(_this.max != null)
else if(dy < 0) (_this.inc >= _this.max) ? _this.inc = _this.max : _this.inc++;
_this.button.setAttribute('value', _this.inc--); else
_this.inc++;
} else if(dy < 0) {
if(_this.min != null)
(_this.inc <= _this.min) ? _this.inc = _this.min : _this.inc--;
else
_this.inc--;
}
_this.button.setAttribute('value', _this.inc);
} }
}; };
this.__defineSetter__("position", function(val) {
_this.inc = val;
_this.button.setAttribute('value', _this.inc);
});
}; };
NumberController.prototype = new Controller(); NumberController.prototype = new Controller();

11
gui.js
View File

@ -57,8 +57,7 @@ var GUI = new function() {
var addHandlers = { var addHandlers = {
"number": function() { "number": function() {
var n = new NumberController(arguments); return construct(NumberController, arguments);
return n;
}, },
"string": function() { "string": function() {
@ -86,6 +85,14 @@ var GUI = new function() {
} }
}; };
var construct = function(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
};
// GUI ... GUI // GUI ... GUI