2011-02-01 18:45:22 +00:00
|
|
|
GUI.BooleanController = function() {
|
2011-01-29 04:28:12 +00:00
|
|
|
|
2011-02-10 20:50:57 +00:00
|
|
|
this.type = "boolean";
|
|
|
|
GUI.Controller.apply(this, arguments);
|
2011-01-25 08:22:04 +00:00
|
|
|
|
2011-02-10 20:50:57 +00:00
|
|
|
var _this = this;
|
2011-01-25 08:22:04 +00:00
|
|
|
var input = document.createElement('input');
|
|
|
|
input.setAttribute('type', 'checkbox');
|
2011-02-10 20:50:57 +00:00
|
|
|
|
2011-03-26 18:11:28 +00:00
|
|
|
if(arguments[3]) {
|
|
|
|
input.checked = true;
|
|
|
|
this.setValue(true);
|
|
|
|
} else {
|
|
|
|
input.checked = false;
|
|
|
|
this.setValue(false);
|
|
|
|
}
|
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.domElement.addEventListener('click', function(e) {
|
2011-02-10 20:50:57 +00:00
|
|
|
input.checked = !input.checked;
|
|
|
|
e.preventDefault();
|
|
|
|
_this.setValue(input.checked);
|
2011-01-25 08:22:04 +00:00
|
|
|
}, false);
|
2011-02-10 20:50:57 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
input.addEventListener('mouseup', function(e) {
|
2011-02-10 20:50:57 +00:00
|
|
|
input.checked = !input.checked; // counteracts default.
|
2011-01-25 08:22:04 +00:00
|
|
|
}, false);
|
2011-02-10 20:50:57 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.domElement.style.cursor = "pointer";
|
|
|
|
this.propertyNameElement.style.cursor = "pointer";
|
|
|
|
this.domElement.appendChild(input);
|
2011-02-10 20:50:57 +00:00
|
|
|
|
2011-01-29 04:04:33 +00:00
|
|
|
this.updateDisplay = function() {
|
2011-02-10 20:50:57 +00:00
|
|
|
input.checked = _this.getValue();
|
2011-01-29 04:04:33 +00:00
|
|
|
};
|
2011-02-10 20:50:57 +00:00
|
|
|
|
|
|
|
|
2011-01-31 15:47:07 +00:00
|
|
|
this.setValue = function(val) {
|
2011-02-10 20:50:57 +00:00
|
|
|
if (typeof val != "boolean") {
|
|
|
|
try {
|
|
|
|
val = eval(val);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
return GUI.Controller.prototype.setValue.call(this, val);
|
2011-02-10 21:00:01 +00:00
|
|
|
};
|
2011-01-25 08:22:04 +00:00
|
|
|
|
|
|
|
};
|
2011-02-10 20:50:57 +00:00
|
|
|
GUI.extendController(GUI.BooleanController);
|