public
Description: jQuery hotkeys plugin.
Clone URL: git://github.com/github/jquery-hotkeys.git
Search Repo:
first commit
defunkt (author)
Sat May 10 21:52:11 -0700 2008
commit  7ac85b19ff47fa4971ec93db345837181579d319
tree    c3b31f29552533901efe181eae3afa9b94d3e44b
0
...
 
 
 
...
1
2
3
0
@@ -0,0 +1,3 @@
0
+This project is an extraction from GitHub.
0
+
0
+For this and other extractions, see http://github.com/github
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
0
@@ -0,0 +1,41 @@
0
+////
0
+// simple hotkeys plugin.
0
+//
0
+// <a href="link" hotkey="a">all</a>
0
+//
0
+// $.hotkey('a', function() { window.location = 'somewhere' })
0
+//
0
+// $.hotkeys({
0
+// 'a': function() { window.location = 'somewhere' },
0
+// 'b': function() { alert('something else') }
0
+// })
0
+//
0
+(function($) {
0
+ $.hotkeys = function(options) {
0
+ for(key in options) $.hotkey(key, options[key])
0
+ return this
0
+ }
0
+
0
+ // accepts a function or url
0
+ $.hotkey = function(key, value) {
0
+ $.hotkeys.cache[key.charCodeAt(0) - 32] = value
0
+ return this
0
+ }
0
+
0
+ $.hotkeys.cache = {}
0
+})(jQuery)
0
+
0
+jQuery(document).ready(function($) {
0
+ $('a[hotkey]').each(function() {
0
+ $.hotkey($(this).attr('hotkey'), $(this).attr('href'))
0
+ })
0
+
0
+ $(document).bind('keydown.hotkey', function(e) {
0
+ // don't hotkey when typing in an input
0
+ if ($(e.target).is(':input')) return
0
+ // no modifiers supported
0
+ if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return true
0
+ var el = $.hotkeys.cache[e.keyCode]
0
+ if (el) $.isFunction(el) ? el.call(this) : window.location = el
0
+ })
0
+});

Comments

    No one has commented yet.