2011-01-25 08:22:04 +00:00
|
|
|
var Controller = function() {
|
|
|
|
|
2011-01-26 01:55:59 +00:00
|
|
|
var onChange = null;
|
|
|
|
|
2011-01-29 00:38:58 +00:00
|
|
|
this.parent = null;
|
|
|
|
|
|
|
|
this.setName = function(n) {
|
|
|
|
this.propertyNameElement.innerHTML = n;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-01-29 01:23:20 +00:00
|
|
|
this.setWatched = function() {
|
|
|
|
this.parent.watchController(this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getValue = function() {
|
|
|
|
return this.object[this.propertyName];
|
|
|
|
}
|
|
|
|
|
2011-01-29 00:38:58 +00:00
|
|
|
this.setValue = function(n) {
|
|
|
|
this.object[this.propertyName] = n;
|
|
|
|
if (onChange != null) {
|
|
|
|
onChange.call(this, n);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-01-29 01:23:20 +00:00
|
|
|
this.watchValue = function() {
|
|
|
|
this.updateValue(this.object[this.propertyName]);
|
2011-01-29 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.onChange = function(fnc) {
|
|
|
|
onChange = fnc;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.makeUnselectable = function(elem) {
|
|
|
|
elem.onselectstart = function() { return false; };
|
|
|
|
elem.style.MozUserSelect = "none";
|
|
|
|
elem.style.KhtmlUserSelect = "none";
|
|
|
|
elem.unselectable = "on";
|
|
|
|
}
|
2011-01-29 00:38:58 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.makeSelectable = function(elem) {
|
|
|
|
elem.onselectstart = function() { };
|
|
|
|
elem.style.MozUserSelect = "auto";
|
|
|
|
elem.style.KhtmlUserSelect = "auto";
|
|
|
|
elem.unselectable = "off";
|
|
|
|
}
|
2011-01-29 00:38:58 +00:00
|
|
|
|
|
|
|
this.domElement = document.createElement('div');
|
|
|
|
this.domElement.setAttribute('class', 'guidat-controller ' + this.type);
|
|
|
|
|
|
|
|
this.object = arguments[0];
|
|
|
|
this.propertyName = arguments[1];
|
|
|
|
|
|
|
|
this.propertyNameElement = document.createElement('span');
|
|
|
|
this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
|
|
|
|
this.setName(this.propertyName);
|
|
|
|
this.domElement.appendChild(this.propertyNameElement);
|
|
|
|
|
|
|
|
this.makeUnselectable(this.domElement);
|
|
|
|
|
|
|
|
};
|