Skip to content

Instantly share code, notes, and snippets.

@oxchronxo
Created October 6, 2010 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxchronxo/613789 to your computer and use it in GitHub Desktop.
Save oxchronxo/613789 to your computer and use it in GitHub Desktop.
if (typeof(KONtx.control.Keyboard._createValueManager) == "undefined") {
KONtx.control.Keyboard.implement({
initialize: function () {
if (this.config.manageValue !== false) {
this._createValueManager();
this.parent();
this._remapKeyboardEvents();
this._remapKeyboardMethods();
} else {
this.parent();
}
},
_createValueManager: function () {
this._valueManager = new KeyboardInput.KeyboardValueManager({
maxLength: this.config.maxLength
});
this._valueManager.addEventListener("valuechanged", function (event) {
this.fire("onValueChanged", { value: event.payload.value });
}.bindTo(this));
},
_remapKeyboardEvents: function () {
this.__keyboard.onKeyDown = function (event) {
if (event.keyCode == 9) {
var spaces = ' ';
this._valueManager.insertCharacters(spaces);
this._valueManager.cursorPosition = this._valueManager.cursorPosition + spaces.length;
} else {
this._valueManager.handleExternalKeyInput({type: event.type, payload: event});
}
this.fire('onKeyDown', event, (event.type ? event : null));
}.bindTo(this);
},
_remapKeyboardMethods: function () {
var self = this;
this.__keyboard.getValue = function () {
return self._valueManager.value;
};
this.__keyboard.setValue = function (value) {
self._valueManager.value = value;
};
this.__keyboard.clearValue = function (value) {
self._valueManager.value = "";
self._valueManager.cursorPosition = 0;
};
this.__keyboard.appendToValue = function (value) {
self._valueManager.insertCharacters(value);
self._valueManager.cursorPosition = self._valueManager.cursorPosition + value.length;
};
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment