Functional boolean, function and string controllers.

This commit is contained in:
George Michael Brower 2011-01-24 13:28:13 -07:00
parent 0554c7ea98
commit 723dbadb36
4 changed files with 15 additions and 2 deletions

View File

@ -13,7 +13,7 @@ var BooleanController = function() {
}, false); }, false);
input.addEventListener('mouseup', function(e) { input.addEventListener('mouseup', function(e) {
input.checked = !input.checked; input.checked = !input.checked; // counteracts default.
}, false); }, false);
this.domElement.style.cursor = 'pointer'; this.domElement.style.cursor = 'pointer';

View File

@ -1,8 +1,13 @@
var FunctionController = function() { var FunctionController = function() {
this.type = "function"; this.type = "function";
var _this = this;
Controller.apply(this, arguments); Controller.apply(this, arguments);
var input = document.createElement('input'); var input = document.createElement('input');
input.setAttribute('type', 'submit'); input.setAttribute('type', 'submit');
this.domElement.addEventListener('click', function() {
_this.object[_this.propertyName].call(_this.object);
}, false);
this.domElement.style.cursor = "pointer";
this.domElement.appendChild(input); this.domElement.appendChild(input);
}; };
FunctionController.prototype = new Controller(); FunctionController.prototype = new Controller();

View File

@ -19,5 +19,12 @@ var Controller = function() {
this.setName(this.propertyName); this.setName(this.propertyName);
this.domElement.appendChild(this.propertyNameElement); this.domElement.appendChild(this.propertyNameElement);
makeUnselectable(this.domElement);
function makeUnselectable(elem) {
elem.onselectstart = function() { return false; };
elem.style.MozUserSelect = "none";
elem.style.KhtmlUserSelect = "none";
elem.unselectable = "on";
}
}; };

View File

@ -9,8 +9,9 @@ var StringController = function() {
var input = document.createElement('input'); var input = document.createElement('input');
input.setAttribute('value', this.object[this.propertyName]); input.setAttribute('value', this.object[this.propertyName]);
this.domElement.addEventListener('mouseover', function() { this.domElement.addEventListener('mouseup', function() {
input.focus(); input.focus();
input.select();
}, false); }, false);
input.addEventListener('keyup', function() { input.addEventListener('keyup', function() {