fix a bug where 'global' keyboard events would trigger while an input element has focus

This commit is contained in:
rlx 2011-11-02 00:46:42 +00:00
parent 7761b9dea4
commit 90eaf97fec
2 changed files with 11 additions and 9 deletions

View file

@ -19,7 +19,7 @@ Ox.JQueryElement = function($element) {
that.ox = Ox.VERSION; that.ox = Ox.VERSION;
//@ $element <object> The jQuery-wrapped DOM element //@ $element <object> The jQuery-wrapped DOM element
that.$element = $element.data({ that.$element = $element.data({
oxid: that.id // FIXME: Can this be just "id"? oxid: that.id
}); });
// FIXME: the following two lines should make it possible to do // FIXME: the following two lines should make it possible to do
// $('<div>').appendTo($element) ... check if it works, then replace all // $('<div>').appendTo($element) ... check if it works, then replace all

View file

@ -28,25 +28,27 @@ Ox.Keyboard = (function() {
} }
}); });
key = keyNames.join('_'); key = keyNames.join('_');
bound.forEach(function(id) { if (focused === null || !Ox.UI.elements[focused].hasClass('OxInput')) {
Ox.UI.elements[id].triggerEvent('key_' + key); bound.forEach(function(id) {
}); 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); Ox.UI.elements[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') && && !Ox.UI.elements[focused].hasClass('OxInput')
!Ox.UI.elements[focused].hasClass('OxAutocompleteMenu') && !Ox.UI.elements[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') && Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
) { ) {
ret = false; ret = false;
} }