diff --git a/controller.js b/controller.js index 38a14fc..6b140f2 100644 --- a/controller.js +++ b/controller.js @@ -1,5 +1,6 @@ var Controller = function() { - this.domElement; + this.domElement = document.createElement('div'); + this.domElement.setAttribute('class', 'guidat-controller'); this.object = arguments[0]; this.propertyName = arguments[1]; @@ -8,8 +9,10 @@ var Controller = function() { var NumberController = function() { Controller.apply(this, arguments); + + var _this = this; + this.isClicked = false; - this.py = this.y = 0; // TODO pass argument to inc this.inc = 0; @@ -19,33 +22,28 @@ var NumberController = function() { this.button.setAttribute('id', this.propertyName); this.button.setAttribute('type', 'number'); this.button.setAttribute('value', this.y); + this.domElement.appendChild(this.button); - // return this.button; - - this.addListeners = function() { - - this.onmousedown = function(e) { - this.isClicked = true; - }; - document.onmouseup = function(e) { - this.isClicked = false; - }; - document.onmousemove = function(e) { - if(this.isClicked) { - this.py = this.y; - var dy = this.y - this.py; - if(dy > 0) - this.button.setAttribute('value', this.inc++); - else - this.button.setAttribute('value', this.inc--); - this.y = e.offsetY; - } - }; + this.button.onmousedown = function(e) { + _this.isClicked = true; + }; + document.onmouseup = function(e) { + _this.isClicked = false; + }; + document.onmousemove = function(e) { + + if(_this.isClicked) { + + _this.py = _this.y; + _this.y = e.offsetY; + var dy = _this.y - _this.py; + + if(dy > 0) + _this.button.setAttribute('value', _this.inc++); + else + _this.button.setAttribute('value', _this.inc--); + } }; - - this.__defineGetter__("button", function(){ - return this.button; - }); }; NumberController.prototype = new Controller(); diff --git a/demo.html b/demo.html index a0c3a34..2cb5afb 100644 --- a/demo.html +++ b/demo.html @@ -1,6 +1,7 @@ +