From 1d0f0a08c11045e823fdb06f848afbf7b0722da3 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Wed, 24 Sep 2014 22:45:34 +0200 Subject: [PATCH] fix keyboard handler --- source/Ox.UI/js/Core/Event.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/Core/Event.js b/source/Ox.UI/js/Core/Event.js index 309a5ad2..0ec5f08b 100644 --- a/source/Ox.UI/js/Core/Event.js +++ b/source/Ox.UI/js/Core/Event.js @@ -75,7 +75,7 @@ } function onKeydown(e) { - var $element = Ox.Focus.focusedElement() || Ox.$body, + var $element = Ox.Focus.focusedElement(), isInput = Ox.Focus.focusedElementIsInput(), keyName = Ox.KEYS[e.keyCode], keyBasename = keyName.split('.')[0], @@ -86,11 +86,11 @@ }).concat(keyName).join('_'), event = 'key.' + key, triggerEvent = function() { - if (Ox.Focus.focusedElement()) { + if ($element) { $element.triggerEvent.apply($element, arguments); } else if (!isInput) { Ox.Event.trigger.apply( - $element, [{}].concat(Ox.slice(arguments)) + Ox.$body, [{}].concat(Ox.slice(arguments)) ); } }; @@ -114,9 +114,12 @@ resetTimeout = setTimeout(function() { keys = ''; }, 1000); - if ( - Ox.contains(keyboardCallbacks[$element.oxid || 0] || [], event) - ) { + if (Ox.contains(keyboardCallbacks[0], event) || ( + $element && keyboardCallbacks[$element.oxid] + && Ox.contains(keyboardCallbacks[$element.oxid], event) + )) { + // if there is a global handler for this keyboard event, or a + // handler on the focused element, then prevent default e.preventDefault(); } }