if (!commandList) return console.warn('Component not defined!');
- if (typeof commandList.ltr === 'undefined') { // this component does not differentiate between ltr and rtl
+ // Ignore the event if it was already handled
+ if (event.zfIsKeyHandled === true) return;
+
+ // This component does not differentiate between ltr and rtl
+ if (typeof commandList.ltr === 'undefined') {
cmds = commandList; // use plain list
} else { // merge ltr and rtl: if document is rtl, rtl overwrites ltr and vice versa
if (Rtl()) cmds = $.extend({}, commandList.ltr, commandList.rtl);
command = cmds[keyCode];
fn = functions[command];
- if (fn && typeof fn === 'function') { // execute function if exists
+ // Execute the handler if found
+ if (fn && typeof fn === 'function') {
var returnValue = fn.apply();
- if (functions.handled || typeof functions.handled === 'function') { // execute function when event was handled
+
+ // Mark the event as "handled" to prevent future handlings
+ event.zfIsKeyHandled = true;
+
+ // Execute function when event was handled
+ if (functions.handled || typeof functions.handled === 'function') {
functions.handled(returnValue);
}
} else {
- if (functions.unhandled || typeof functions.unhandled === 'function') { // execute function when event was not handled
+ // Execute function when event was not handled
+ if (functions.unhandled || typeof functions.unhandled === 'function') {
functions.unhandled();
}
}