key events added to NumberController

This commit is contained in:
jonobr1 2011-01-24 12:53:33 -08:00
parent 723dbadb36
commit ee543a4402
2 changed files with 29 additions and 4 deletions

View File

@ -10,7 +10,7 @@ var NumberController = function() {
this.isClicked = false;
this.py = this.y = 0;
this.inc = 0; // TODO pass argument to inc
this.inc = 0;
// Get min and max
(arguments[2] != null) ? this.min = arguments[2] : this.min = null;
@ -18,13 +18,25 @@ var NumberController = function() {
this.button = document.createElement('input');
this.button.setAttribute('id', this.propertyName);
this.button.setAttribute('type', 'number');
this.button.setAttribute('type', this.type);
this.button.setAttribute('value', this.inc);
this.domElement.appendChild(this.button);
this.button.onmousedown = function(e) {
_this.isClicked = true;
};
this.button.onkeyup = function(e) {
var val = parseFloat(_this.button.value);
if(isNaN(val)) {
_this.inc = 0;
} else {
_this.inc = val;
}
_this.button.value = _this.inc;
_this.setValue(_this.inc);
};
document.onmouseup = function(e) {
_this.isClicked = false;
};
@ -32,6 +44,8 @@ var NumberController = function() {
if(_this.isClicked) {
e.preventDefault();
_this.py = _this.y;
_this.y = e.offsetY;
var dy = _this.y - _this.py;
@ -49,13 +63,15 @@ var NumberController = function() {
_this.inc--;
}
_this.button.setAttribute('value', _this.inc);
_this.button.value = _this.inc;
_this.setValue(_this.inc);
}
};
this.__defineSetter__("position", function(val) {
_this.inc = val;
_this.button.setAttribute('value', _this.inc);
_this.button.value = _this.inc;
_this.setValue(_this.inc);
});
};

View File

@ -20,6 +20,15 @@ var StringController = function() {
}, false);
this.domElement.appendChild(input);
input.onfocus = function(e) {
if(_this.contents == _this.object[_this.propertyName]) {
contents = "";
_this.input.setAttribute('value', contents);
}
};
input.onblur = function(e) {
};
};
StringController.prototype = new Controller();
StringController.prototype.constructor = StringController;