minor changes in keyboard controller
This commit is contained in:
parent
985b34ac72
commit
65cd5b8afa
1 changed files with 7 additions and 8 deletions
|
@ -15,6 +15,7 @@ Ox.Keyboard = (function() {
|
||||||
function keydown(event) {
|
function keydown(event) {
|
||||||
|
|
||||||
var focused = Ox.Focus.focused(),
|
var focused = Ox.Focus.focused(),
|
||||||
|
$focused = focused === null ? null : Ox.UI.elements[focused],
|
||||||
key,
|
key,
|
||||||
keyName = Ox.KEYS[event.keyCode] || '',
|
keyName = Ox.KEYS[event.keyCode] || '',
|
||||||
keyNames = keyName ? [keyName] : [],
|
keyNames = keyName ? [keyName] : [],
|
||||||
|
@ -30,27 +31,27 @@ Ox.Keyboard = (function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
key = keyNames.join('_');
|
key = keyNames.join('_');
|
||||||
if (focused === null || !Ox.UI.elements[focused].hasClass('OxInput')) {
|
if (focused !== null || !$focused.hasClass('OxInput')) {
|
||||||
bound.forEach(function(id) {
|
bound.forEach(function(id) {
|
||||||
Ox.UI.elements[id].triggerEvent('key_' + key);
|
Ox.UI.elements[id].triggerEvent('key_' + key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (focused !== null && bound.indexOf(focused) == -1) {
|
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
|
// prevent Chrome from scrolling, or going back in history
|
||||||
if (
|
if (
|
||||||
[
|
[
|
||||||
'backspace', 'down', 'left', 'right', 'space', 'up'
|
'backspace', 'down', 'left', 'right', 'space', 'up'
|
||||||
].indexOf(key) > -1
|
].indexOf(key) > -1
|
||||||
&& !Ox.UI.elements[focused].hasClass('OxInput')
|
&& !$focused.hasClass('OxInput')
|
||||||
&& !Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
|
&& !$focused.hasClass('OxAutocompleteMenu')
|
||||||
) {
|
) {
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
// prevent cursor in input field from moving to start or end
|
// prevent cursor in input field from moving to start or end
|
||||||
if (
|
if (
|
||||||
['down', 'up'].indexOf(key) > -1
|
['down', 'up'].indexOf(key) > -1
|
||||||
&& Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
|
&& $focused.hasClass('OxAutocompleteMenu')
|
||||||
) {
|
) {
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
@ -64,9 +65,7 @@ Ox.Keyboard = (function() {
|
||||||
clearTimeout(triggerTimeout);
|
clearTimeout(triggerTimeout);
|
||||||
triggerTimeout = setTimeout(function() {
|
triggerTimeout = setTimeout(function() {
|
||||||
if (focused !== null) {
|
if (focused !== null) {
|
||||||
Ox.UI.elements[focused].triggerEvent('keys', {
|
$focused.triggerEvent('keys', {keys: buffer});
|
||||||
keys: buffer
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue