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