added slider still need to style it

This commit is contained in:
jonobr1 2011-01-24 14:02:28 -08:00
parent 58447b25c1
commit 79b183fd0b

View File

@ -9,6 +9,7 @@ var NumberController = function() {
var _this = this; var _this = this;
var isClicked = false; var isClicked = false;
var isDragged = false;
var y, py, initialValue, inc; var y, py, initialValue, inc;
py = y = 0; py = y = 0;
@ -25,9 +26,20 @@ var NumberController = function() {
var button = document.createElement('input'); var button = document.createElement('input');
button.setAttribute('id', this.propertyName); button.setAttribute('id', this.propertyName);
button.setAttribute('type', this.type); button.setAttribute('type', this.type);
button.setAttribute('value', inc) button.setAttribute('value', inc);
this.domElement.appendChild(button); this.domElement.appendChild(button);
var slider = document.createElement('input');
slider.setAttribute('id', this.propertyName + "-slider");
slider.setAttribute('type', 'range');
slider.setAttribute('value', inc);
if(min != null && max != null) {
slider.setAttribute('min', min);
slider.setAttribute('max', max);
}
slider.setAttribute('step', amt);
this.domElement.appendChild(slider);
button.addEventListener('mousedown', function(e) { button.addEventListener('mousedown', function(e) {
isClicked = true; isClicked = true;
}, false); }, false);
@ -38,11 +50,14 @@ var NumberController = function() {
} else { } else {
inc = val; inc = val;
} }
this.value = inc; updateValue(inc);
_this.setValue(inc); }, false);
slider.addEventListener('mousedown', function(e) {
isDragged = true;
}, false); }, false);
document.addEventListener('mouseup', function(e) { document.addEventListener('mouseup', function(e) {
isClicked = false; isClicked = false;
isDragged = false;
}, false); }, false);
document.addEventListener('mousemove', function(e) { document.addEventListener('mousemove', function(e) {
if(isClicked) { if(isClicked) {
@ -62,15 +77,22 @@ var NumberController = function() {
else else
inc--; inc--;
} }
button.value = inc; } else if(isDragged) {
_this.setValue(inc); if(inc != slider.value) inc = slider.value;
} }
updateValue(inc);
}, false); }, false);
function updateValue(val) {
if(inc != val) inc = val;
button.value = val;
slider.value = val;
_this.setValue(val);
}
this.__defineSetter__("position", function(val) { this.__defineSetter__("position", function(val) {
inc = val; inc = val;
button.value = inc; updateValue(val);
_this.setValue(inc);
// possibly push to an array here so that // possibly push to an array here so that
// we have a record of "defined" / "presets" // we have a record of "defined" / "presets"
// ???? // ????
@ -79,4 +101,3 @@ var NumberController = function() {
NumberController.prototype = new Controller(); NumberController.prototype = new Controller();
NumberController.prototype.constructor = NumberController; NumberController.prototype.constructor = NumberController;