dat.gui/src/DAT/GUI/ControllerBoolean.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

DAT.GUI.ControllerBoolean = function() {
2011-04-18 19:06:19 +00:00
this.type = "boolean";
DAT.GUI.Controller.apply(this, arguments);
var _this = this;
var input = document.createElement('input');
input.setAttribute('type', 'checkbox');
2011-04-18 19:15:51 +00:00
input.checked = this.getValue();
this.setValue(this.getValue());
2011-04-18 19:06:19 +00:00
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);
this.updateDisplay = function() {
input.checked = _this.getValue();
};
this.setValue = function(val) {
if (typeof val != "boolean") {
try {
val = eval(val);
} catch (e) {
}
}
2011-04-18 19:06:19 +00:00
return DAT.GUI.Controller.prototype.setValue.call(this, val);
};
};
DAT.GUI.extendController(DAT.GUI.ControllerBoolean);