diff --git a/source/Ox.UI/js/Core/Keyboard.js b/source/Ox.UI/js/Core/Keyboard.js index 011e87e4..58cdd230 100644 --- a/source/Ox.UI/js/Core/Keyboard.js +++ b/source/Ox.UI/js/Core/Keyboard.js @@ -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); }