fix keyboard handler

This commit is contained in:
rlx 2014-09-24 22:45:34 +02:00
parent b665bb54d1
commit 1d0f0a08c1

View file

@ -75,7 +75,7 @@
} }
function onKeydown(e) { function onKeydown(e) {
var $element = Ox.Focus.focusedElement() || Ox.$body, var $element = Ox.Focus.focusedElement(),
isInput = Ox.Focus.focusedElementIsInput(), isInput = Ox.Focus.focusedElementIsInput(),
keyName = Ox.KEYS[e.keyCode], keyName = Ox.KEYS[e.keyCode],
keyBasename = keyName.split('.')[0], keyBasename = keyName.split('.')[0],
@ -86,11 +86,11 @@
}).concat(keyName).join('_'), }).concat(keyName).join('_'),
event = 'key.' + key, event = 'key.' + key,
triggerEvent = function() { triggerEvent = function() {
if (Ox.Focus.focusedElement()) { if ($element) {
$element.triggerEvent.apply($element, arguments); $element.triggerEvent.apply($element, arguments);
} else if (!isInput) { } else if (!isInput) {
Ox.Event.trigger.apply( Ox.Event.trigger.apply(
$element, [{}].concat(Ox.slice(arguments)) Ox.$body, [{}].concat(Ox.slice(arguments))
); );
} }
}; };
@ -114,9 +114,12 @@
resetTimeout = setTimeout(function() { resetTimeout = setTimeout(function() {
keys = ''; keys = '';
}, 1000); }, 1000);
if ( if (Ox.contains(keyboardCallbacks[0], event) || (
Ox.contains(keyboardCallbacks[$element.oxid || 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(); e.preventDefault();
} }
} }