mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
89 lines
2.1 KiB
JavaScript
89 lines
2.1 KiB
JavaScript
|
/**
|
||
|
* dat-gui JavaScript Controller Library
|
||
|
* http://code.google.com/p/dat-gui
|
||
|
*
|
||
|
* Copyright 2011 Data Arts Team, Google Creative Lab
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*/
|
||
|
|
||
|
define([
|
||
|
'dat/controllers/Controller',
|
||
|
'dat/dom/dom',
|
||
|
'dat/utils/common'
|
||
|
], function(Controller, dom, common) {
|
||
|
|
||
|
/**
|
||
|
* @class Provides a text input to alter the string property of an object.
|
||
|
*
|
||
|
* @extends dat.controllers.Controller
|
||
|
*
|
||
|
* @param {Object} object The object to be manipulated
|
||
|
* @param {string} property The name of the property to be manipulated
|
||
|
*
|
||
|
* @member dat.controllers
|
||
|
*/
|
||
|
var StringController = function(object, property) {
|
||
|
|
||
|
StringController.superclass.call(this, object, property);
|
||
|
|
||
|
var _this = this;
|
||
|
|
||
|
this.__input = document.createElement('input');
|
||
|
this.__input.setAttribute('type', 'text');
|
||
|
|
||
|
dom.bind(this.__input, 'keyup', onChange);
|
||
|
dom.bind(this.__input, 'change', onChange);
|
||
|
dom.bind(this.__input, 'blur', onBlur);
|
||
|
dom.bind(this.__input, 'keydown', function(e) {
|
||
|
if (e.keyCode === 13) {
|
||
|
this.blur();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
|
||
|
function onChange() {
|
||
|
_this.setValue(_this.__input.value);
|
||
|
}
|
||
|
|
||
|
function onBlur() {
|
||
|
if (_this.__onFinishChange) {
|
||
|
_this.__onFinishChange.call(_this, _this.getValue());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
this.updateDisplay();
|
||
|
|
||
|
this.domElement.appendChild(this.__input);
|
||
|
|
||
|
};
|
||
|
|
||
|
StringController.superclass = Controller;
|
||
|
|
||
|
common.extend(
|
||
|
|
||
|
StringController.prototype,
|
||
|
Controller.prototype,
|
||
|
|
||
|
{
|
||
|
|
||
|
updateDisplay: function() {
|
||
|
// Stops the caret from moving on account of:
|
||
|
// keyup -> setValue -> updateDisplay
|
||
|
if (!dom.isActive(this.__input)) {
|
||
|
this.__input.value = this.getValue();
|
||
|
}
|
||
|
return StringController.superclass.prototype.updateDisplay.call(this);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
);
|
||
|
|
||
|
return StringController;
|
||
|
|
||
|
});
|