minor changes in keyboard controller

This commit is contained in:
rolux 2012-11-03 17:19:35 +01:00
parent 985b34ac72
commit 65cd5b8afa

View file

@ -15,6 +15,7 @@ Ox.Keyboard = (function() {
function keydown(event) {
var focused = Ox.Focus.focused(),
$focused = focused === null ? null : Ox.UI.elements[focused],
key,
keyName = Ox.KEYS[event.keyCode] || '',
keyNames = keyName ? [keyName] : [],
@ -30,27 +31,27 @@ Ox.Keyboard = (function() {
}
});
key = keyNames.join('_');
if (focused === null || !Ox.UI.elements[focused].hasClass('OxInput')) {
if (focused !== null || !$focused.hasClass('OxInput')) {
bound.forEach(function(id) {
Ox.UI.elements[id].triggerEvent('key_' + key);
});
}
if (focused !== null && bound.indexOf(focused) == -1) {
Ox.UI.elements[focused].triggerEvent('key_' + key);
$focused.triggerEvent('key_' + key);
// prevent Chrome from scrolling, or going back in history
if (
[
'backspace', 'down', 'left', 'right', 'space', 'up'
].indexOf(key) > -1
&& !Ox.UI.elements[focused].hasClass('OxInput')
&& !Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
&& !$focused.hasClass('OxInput')
&& !$focused.hasClass('OxAutocompleteMenu')
) {
ret = false;
}
// prevent cursor in input field from moving to start or end
if (
['down', 'up'].indexOf(key) > -1
&& Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
&& $focused.hasClass('OxAutocompleteMenu')
) {
ret = false;
}
@ -64,9 +65,7 @@ Ox.Keyboard = (function() {
clearTimeout(triggerTimeout);
triggerTimeout = setTimeout(function() {
if (focused !== null) {
Ox.UI.elements[focused].triggerEvent('keys', {
keys: buffer
});
$focused.triggerEvent('keys', {keys: buffer});
}
}, 250);
}