diff --git a/controller.js b/controller.js index e6f6551..e51803b 100644 --- a/controller.js +++ b/controller.js @@ -8,6 +8,10 @@ var Controller = function() { this.object[this.propertyName] = n; } + this.getValue = function() { + return this.object[this.propertyName]; + } + this.domElement = document.createElement('div'); this.domElement.setAttribute('class', 'guidat-controller ' + this.type); diff --git a/controller.number.js b/controller.number.js index 8236236..238c3ff 100644 --- a/controller.number.js +++ b/controller.number.js @@ -9,7 +9,7 @@ var NumberController = function() { var _this = this; this.isClicked = false; - this.py = this.y = 0; + this.py = this.y = this.initialValue = this.object[this.propertyName]; this.inc = 0; // Get min and max @@ -30,7 +30,7 @@ var NumberController = function() { var val = parseFloat(_this.button.value); if(isNaN(val)) { - _this.inc = 0; + _this.inc = _this.initialValue; } else { _this.inc = val; } @@ -72,6 +72,9 @@ var NumberController = function() { _this.inc = val; _this.button.value = _this.inc; _this.setValue(_this.inc); + // possibly push to an array here so that + // we have a record of "defined" / "presets" + // ???? }); }; diff --git a/controller.string.js b/controller.string.js index 4288cf4..07b6b86 100644 --- a/controller.string.js +++ b/controller.string.js @@ -8,27 +8,26 @@ var StringController = function() { var input = document.createElement('input'); - input.setAttribute('value', this.object[this.propertyName]); + var initialValue = this.getValue(); + + input.setAttribute('value', initialValue); this.domElement.addEventListener('mouseup', function() { input.focus(); input.select(); }, false); input.addEventListener('keyup', function() { - console.log(input.value); - _this.setValue(input.value); + _this.setValue(input.value); }, 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) { + if(_this.getValue() == '') { + _this.setValue(initialValue); + this.value = initialValue; } }; - input.onblur = function(e) { - }; + + this.domElement.appendChild(input); }; StringController.prototype = new Controller(); StringController.prototype.constructor = StringController; \ No newline at end of file