Skip to content

Commit 2bc49e9

Browse files
author
tzury
committed
John Resig's changes applied
1 parent 9c83eea commit 2bc49e9

File tree

3 files changed

+6348
-307
lines changed

3 files changed

+6348
-307
lines changed

README.md

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
11
#About
2-
**jQuery.hotkeys** is a plug-in that lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.
2+
**jQuery Hotkeys** is a plug-in that lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.
33

4-
It is based on a library [Shortcut.js](http://www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js) written by [Binny V A](http://www.openjs.com/).
4+
This plugin is based off of the plugin by Tzury Bar Yochay: [jQuery.hotkeys](http://github.com/tzuryby/hotkeys)
55

66
The syntax is as follows:
7-
<pre>
8-
$(expression).bind(<types>,<options>, <handler>);
9-
$(expression).unbind(<types>,<options>, <handler>);
107

11-
$(document).bind('keydown', 'Ctrl+a', fn);
12-
13-
// e.g. replace '$' sign with 'EUR'
14-
$('input.foo').bind('keyup', '$', function(){
15-
this.value = this.value.replace('$', 'EUR');
16-
});
17-
18-
$('div.foo').unbind('keydown', 'Ctrl+a', fn);
19-
</pre>
20-
## [Live Demo](http://jshotkeys.googlepages.com/test-static-01.html)
8+
$(expression).bind(types, keys, handler);
9+
$(expression).unbind(types, handler);
10+
11+
$(document).bind('keydown', 'ctrl+a', fn);
12+
13+
// e.g. replace '$' sign with 'EUR'
14+
$('input.foo').bind('keyup', '$', function(){
15+
this.value = this.value.replace('$', 'EUR');
16+
});
2117

2218
## Types
2319
Supported types are `'keydown'`, `'keyup'` and `'keypress'`
2420

25-
## Options
26-
The options are `'combi'` i.e. the key combination, and `'disableInInput'` which allow your code not to be executed when the cursor is located inside an input ( `$(elem).is('input') || $(elem).is('textarea')` ).
27-
28-
As you can see, the key combination can be passed as string or as an object. You may pass an object in case you wish to override the default option for `disableInInput` which is set to `false`:
29-
<pre>
30-
$(document).bind('keydown', {combi:'a', disableinInput: true}, fn);
31-
</pre>
32-
I.e. when cursor is within an input field, `'a'` will be inserted into the input field without interfering.
21+
## Notes
3322

3423
If you want to use more than one modifiers (e.g. alt+ctrl+z) you should define them by an alphabetical order e.g. alt+ctrl+shift
3524

36-
Modifiers are case insensitive, i.e. 'Ctrl+a' 'ctrl+a'.
37-
38-
## Handler
39-
In previous versions there was an option propagate which is removed now and implemented at the user code level.
40-
41-
When using jQuery, if an event handler returns false, jQuery will call `stopPropagation()` and `preventDefault()`
25+
Hotkeys aren't tracked if you're inside of an input element (unless you explicitly bind the hotkey directly to the input). This helps to avoid conflict with normal user typing.
4226

4327
## jQuery Compatibility
44-
Tested with *jQuery 1.2.6*
28+
29+
Works with jQuery 1.4.2 and newer.
4530

4631
It known to be working with all the major browsers on all available platforms (Win/Mac/Linux)
4732

@@ -51,43 +36,10 @@ It known to be working with all the major browsers on all available platforms (W
5136
* Safari-3
5237
* Chrome-0.2
5338

54-
## Features added in this version (0.7.x)
55-
* Implemented as $.fn - let you use `this`.
56-
* jQuery selectors are supported.
57-
* Extending `$.fn.bind` and `$.fn.unbind` so you get a single interface for binding events to handlers
58-
59-
## Overriding jQuery
60-
The plugin wraps the following jQuery methods:
61-
* $.fn.bind
62-
* $.fn.unbind
63-
* $.find
64-
65-
Even though the plugin overrides these methods, the original methods will *always* be called.
66-
67-
The plugin will add functionality only for the `keydown`, `keyup` and `keypress` event types. Any other types are passed untouched to the original `'bind()'` and `'unbind()'` methods.
68-
69-
Moreover, if you call `bind()` without passing the shortcut key combination e.g. `$(document).bind('keydown', fn)` only the original `'bind()'` method will be executed.
70-
71-
I also modified the `$.fn.find` method by adding a single line at the top of the function body. here is the code:
72-
73-
<pre>
74-
jQuery.fn.find = function( selector ) {
75-
// the line I added
76-
this.query=selector;
77-
// call jQuery original find
78-
return jQuery.fn.__find__.apply(this, arguments);
79-
};
80-
</pre>
81-
82-
You can read about this at [jQuery's User Group](http://groups.google.com/group/jquery-en/browse_thread/thread/18f9825e8d22f18d)
83-
84-
###Notes
39+
### Addendum
8540

8641
Firefox is the most liberal one in the manner of letting you capture all short-cuts even those that are built-in in the browser such as `Ctrl-t` for new tab, or `Ctrl-a` for selecting all text. You can always bubble them up to the browser by returning `true` in your handler.
8742

8843
Others, (IE) either let you handle built-in short-cuts, but will add their functionality after your code has executed. Or (Opera/Safari) will *not* pass those events to the DOM at all.
8944

9045
*So, if you bind `Ctrl-Q` or `Alt-F4` and your Safari/Opera window is closed don't be surprised.*
91-
92-
93-
###Current Version is: beta 0.7

0 commit comments

Comments
 (0)