changed event to blur not keyup on NumberController

This commit is contained in:
jonobr1 2011-01-24 14:24:35 -08:00
parent 8cf2f47f5a
commit b0b22e56c5

View File

@ -1,5 +1,3 @@
// Only works on the last one
var NumberController = function() { var NumberController = function() {
this.type = "number"; this.type = "number";
@ -27,23 +25,26 @@ var NumberController = function() {
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);
button.setAttribute('step', amt);
this.domElement.appendChild(button); this.domElement.appendChild(button);
var slider = document.createElement('input'); var slider = document.createElement('input');
slider.setAttribute('id', this.propertyName + "-slider");
slider.setAttribute('type', 'range');
slider.setAttribute('value', inc);
if(min != null && max != null) { if(min != null && max != null) {
slider.setAttribute('min', min); slider.setAttribute('id', this.propertyName + "-slider");
slider.setAttribute('max', max); 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);
} }
slider.setAttribute('step', amt);
this.domElement.appendChild(slider);
button.addEventListener('mousedown', function(e) { button.addEventListener('mousedown', function(e) {
isClicked = true; isClicked = true;
}, false); }, false);
button.addEventListener('keyup', function(e) { button.addEventListener('blur', function(e) {
var val = parseFloat(this.value); var val = parseFloat(this.value);
if(isNaN(val)) { if(isNaN(val)) {
inc = initialValue; inc = initialValue;
@ -66,25 +67,48 @@ var NumberController = function() {
y = e.offsetY; y = e.offsetY;
var dy = y - py; var dy = y - py;
if(dy < 0) { if(dy < 0) {
if(max != null)
(inc >= max) ? inc = max : inc+=amt; if(max != null) {
else if(inc >= max) {
inc = max;
return;
} else {
inc+=amt;
updateValue(inc);
}
} else {
inc++; inc++;
updateValue(inc);
}
} else if(dy > 0) { } else if(dy > 0) {
if(min != null) if(min != null) {
(inc <= min) ? inc = min : inc-=amt; if(inc <= min) {
else inc = min;
return;
} else {
inc-=amt;
updateValue(inc);
}
} else {
inc--; inc--;
updateValue(inc);
}
} }
updateValue(inc);
} else if(isDragged) { } else if(isDragged) {
if(inc != slider.value) inc = slider.value; if(inc != slider.value) inc = slider.value;
updateValue(inc);
} }
updateValue(inc);
}, false); }, false);
function updateValue(val) { function updateValue(val) {
if(inc != val) inc = val; if(inc != val) inc = val;
if(inc > max && max != null) {
inc = max;
} else if(inc < min && min != null) {
inc = min;
}
button.value = val; button.value = val;
slider.value = val; slider.value = val;
_this.setValue(val); _this.setValue(val);