diff --git a/controller.number.js b/controller.number.js index 373fa55..8236236 100644 --- a/controller.number.js +++ b/controller.number.js @@ -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); }); }; diff --git a/controller.string.js b/controller.string.js index 6d66891..4288cf4 100644 --- a/controller.string.js +++ b/controller.string.js @@ -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; \ No newline at end of file