From 26aeb4348ec38f76ed2a212a4d17b5f2e2548427 Mon Sep 17 00:00:00 2001 From: gil Date: Fri, 25 May 2012 10:34:39 -0300 Subject: [PATCH 1/3] event namespace prefix configuration, to avoid conflicts --- jquery.hotkeys.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jquery.hotkeys.js b/jquery.hotkeys.js index d046a71..680019e 100644 --- a/jquery.hotkeys.js +++ b/jquery.hotkeys.js @@ -15,6 +15,8 @@ jQuery.hotkeys = { version: "0.8+", + prefix: "", + specialKeys: { 8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause", 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", @@ -58,7 +60,7 @@ // Keypress represents characters, not special keys var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ], character = String.fromCharCode( event.which ).toLowerCase(), - key, modif = "", possible = {}; + key, prefix = jQuery.hotkeys.prefix, modif = prefix, possible = {}; // check combinations (alt|ctrl|shift+anything) if ( event.altKey && special !== "alt" ) { @@ -92,7 +94,7 @@ } for ( var i = 0, l = keys.length; i < l; i++ ) { - if ( possible[ keys[i] ] ) { + if ( possible[ keys[i] ] || ( prefix.length > 0 && keys[i].indexOf( prefix ) != 0 ) ) { return origHandler.apply( this, arguments ); } } @@ -103,4 +105,4 @@ jQuery.event.special[ this ] = { add: keyHandler }; }); -})( jQuery ); +})( jQuery ); \ No newline at end of file From f7df9de88e262caabfa535d398903c2f1a8f73f0 Mon Sep 17 00:00:00 2001 From: gil Date: Fri, 25 May 2012 10:56:27 -0300 Subject: [PATCH 2/3] updating the readme with event namespace prefix instructions --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1ee3276..6fcda44 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,14 @@ The syntax is as follows: this.value = this.value.replace('$', 'EUR'); }); +You can also configure some prefix for your events namespace, to avoid conflicts with other namespaces: + + // Configure the prefix somewhere in your code + jQuery.hotkeys.prefix = "hk_"; + + // Then bind the hotkey + $(document).bind('keydown.hk_ctrl_a', fn); + ## Types Supported types are `'keydown'`, `'keyup'` and `'keypress'` From 09acb867b5e3055b0870012a1493702ce63e4c29 Mon Sep 17 00:00:00 2001 From: fhackenberger Date: Tue, 20 Nov 2012 17:56:00 +0100 Subject: [PATCH 3/3] Fixed a jQuery compatibility mode bug Made sure we use jQuery instead of $ within the plugin --- jquery.hotkeys.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.hotkeys.js b/jquery.hotkeys.js index 680019e..b1d0f98 100644 --- a/jquery.hotkeys.js +++ b/jquery.hotkeys.js @@ -53,7 +53,7 @@ // Don't fire in text-accepting inputs that we didn't directly bind to // important to note that $.fn.prop is only available on jquery 1.6+ if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) || - event.target.type === "text" || $(event.target).prop('contenteditable') == 'true' )) { + event.target.type === "text" || jQuery(event.target).prop('contenteditable') == 'true' )) { return; }