2011-01-24 19:38:52 +00:00
|
|
|
|
|
|
|
// Only works on the last one
|
|
|
|
var NumberController = function() {
|
|
|
|
|
|
|
|
this.type = "number";
|
|
|
|
|
|
|
|
Controller.apply(this, arguments);
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
2011-01-24 21:22:09 +00:00
|
|
|
var isClicked = false;
|
|
|
|
var y, py, initialValue, inc;
|
2011-01-24 19:38:52 +00:00
|
|
|
|
2011-01-24 21:22:09 +00:00
|
|
|
py = y = 0;
|
|
|
|
inc = initialValue = this.object[this.propertyName];
|
2011-01-24 19:38:52 +00:00
|
|
|
|
2011-01-24 21:22:09 +00:00
|
|
|
var min, max;
|
|
|
|
(arguments[2] != null) ? min = arguments[2] : min = null;
|
|
|
|
(arguments[3] != null) ? max = arguments[3] : max = null;
|
2011-01-24 20:53:33 +00:00
|
|
|
|
2011-01-24 21:36:08 +00:00
|
|
|
var amt;
|
|
|
|
(arguments[4] != null) ? amt = arguments[4] : amt = (max - min) * .01;
|
|
|
|
if(amt == 0) amt = 1;
|
|
|
|
|
2011-01-24 21:22:09 +00:00
|
|
|
var button = document.createElement('input');
|
|
|
|
button.setAttribute('id', this.propertyName);
|
|
|
|
button.setAttribute('type', this.type);
|
|
|
|
button.setAttribute('value', inc)
|
|
|
|
this.domElement.appendChild(button);
|
2011-01-24 19:38:52 +00:00
|
|
|
|
2011-01-24 21:27:45 +00:00
|
|
|
button.addEventListener('mousedown', function(e) {
|
2011-01-24 21:22:09 +00:00
|
|
|
isClicked = true;
|
2011-01-24 21:27:45 +00:00
|
|
|
}, false);
|
|
|
|
button.addEventListener('keyup', function(e) {
|
2011-01-24 21:22:09 +00:00
|
|
|
var val = parseFloat(this.value);
|
2011-01-24 20:53:33 +00:00
|
|
|
if(isNaN(val)) {
|
2011-01-24 21:22:09 +00:00
|
|
|
inc = initialValue;
|
2011-01-24 20:53:33 +00:00
|
|
|
} else {
|
2011-01-24 21:22:09 +00:00
|
|
|
inc = val;
|
2011-01-24 20:53:33 +00:00
|
|
|
}
|
2011-01-24 21:22:09 +00:00
|
|
|
this.value = inc;
|
|
|
|
_this.setValue(inc);
|
2011-01-24 21:27:45 +00:00
|
|
|
}, false);
|
|
|
|
document.addEventListener('mouseup', function(e) {
|
2011-01-24 21:22:09 +00:00
|
|
|
isClicked = false;
|
2011-01-24 21:27:45 +00:00
|
|
|
}, false);
|
|
|
|
document.addEventListener('mousemove', function(e) {
|
2011-01-24 21:22:09 +00:00
|
|
|
if(isClicked) {
|
2011-01-24 20:53:33 +00:00
|
|
|
e.preventDefault();
|
2011-01-24 21:22:09 +00:00
|
|
|
py = y;
|
|
|
|
y = e.offsetY;
|
|
|
|
var dy = y - py;
|
|
|
|
if(dy < 0) {
|
|
|
|
if(max != null)
|
2011-01-24 21:36:08 +00:00
|
|
|
(inc >= max) ? inc = max : inc+=amt;
|
2011-01-24 19:38:52 +00:00
|
|
|
else
|
2011-01-24 21:22:09 +00:00
|
|
|
inc++;
|
|
|
|
} else if(dy > 0) {
|
|
|
|
|
|
|
|
if(min != null)
|
2011-01-24 21:36:08 +00:00
|
|
|
(inc <= min) ? inc = min : inc-=amt;
|
2011-01-24 19:38:52 +00:00
|
|
|
else
|
2011-01-24 21:22:09 +00:00
|
|
|
inc--;
|
2011-01-24 19:38:52 +00:00
|
|
|
}
|
2011-01-24 21:22:09 +00:00
|
|
|
button.value = inc;
|
|
|
|
_this.setValue(inc);
|
2011-01-24 19:38:52 +00:00
|
|
|
}
|
2011-01-24 21:27:45 +00:00
|
|
|
}, false);
|
2011-01-24 19:38:52 +00:00
|
|
|
|
|
|
|
this.__defineSetter__("position", function(val) {
|
2011-01-24 21:22:09 +00:00
|
|
|
inc = val;
|
|
|
|
button.value = inc;
|
|
|
|
_this.setValue(inc);
|
2011-01-24 21:09:55 +00:00
|
|
|
// possibly push to an array here so that
|
|
|
|
// we have a record of "defined" / "presets"
|
|
|
|
// ????
|
2011-01-24 19:38:52 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
NumberController.prototype = new Controller();
|
|
|
|
NumberController.prototype.constructor = NumberController;
|
|
|
|
|