2011-02-01 18:45:22 +00:00
|
|
|
GUI.StringController = function() {
|
2011-01-29 02:25:48 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.type = "string";
|
2011-01-29 04:28:12 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
var _this = this;
|
2011-02-01 18:45:22 +00:00
|
|
|
GUI.Controller.apply(this, arguments);
|
2011-01-25 08:22:04 +00:00
|
|
|
|
|
|
|
var input = document.createElement('input');
|
|
|
|
|
|
|
|
var initialValue = this.getValue();
|
|
|
|
|
|
|
|
input.setAttribute('value', initialValue);
|
|
|
|
input.setAttribute('spellcheck', 'false');
|
2011-01-29 04:28:12 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.domElement.addEventListener('mouseup', function() {
|
|
|
|
input.focus();
|
|
|
|
input.select();
|
|
|
|
}, false);
|
|
|
|
|
2011-01-31 23:15:29 +00:00
|
|
|
// TODO: getting messed up on ctrl a
|
2011-02-09 19:39:18 +00:00
|
|
|
input.addEventListener('keyup', function(e) {
|
|
|
|
if (e.keyCode == 13 && _this.finishChangeFunction != null) {
|
|
|
|
_this.finishChangeFunction.call(this, _this.getValue());
|
|
|
|
}
|
2011-01-25 08:22:04 +00:00
|
|
|
_this.setValue(input.value);
|
|
|
|
}, false);
|
|
|
|
|
2011-02-09 19:39:18 +00:00
|
|
|
input.addEventListener('blur', function() {
|
|
|
|
if (_this.finishChangeFunction != null) {
|
|
|
|
_this.finishChangeFunction.call(this, _this.getValue());
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2011-01-29 04:04:33 +00:00
|
|
|
this.updateDisplay = function() {
|
|
|
|
input.value = _this.getValue();
|
|
|
|
}
|
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
this.domElement.appendChild(input);
|
2011-01-29 04:28:12 +00:00
|
|
|
|
2011-01-25 08:22:04 +00:00
|
|
|
};
|
2011-01-29 04:28:12 +00:00
|
|
|
|
2011-02-01 18:45:22 +00:00
|
|
|
GUI.extendController(GUI.StringController);
|