-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
41 lines (20 loc) · 1.12 KB
/
README
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
A simple way to add key handling to jquery
To start just add
$.keyNav();
Then you can do fancy stuff like:
$.whenPressed('j',function(){ alert('you pressed j');});
$('h1').whenPressed('h',function(){ $(this).hide();});
if you pass it a string it will look through its dictionary for the keycode. If passed an integer, it will assume thats the keycode and use that
I also added some helper methods:
$('a:first').navigateTo();
will set the pages location to anchor's href.
there's also tests for the keycode
$.isLetter(keyCode) will check to see if the key code is a letter
$.isNumber(keyCode) will check to see if the key is a number, including the numpad
$('div').scrollTo() will scroll to fit the element in the window if its outside the viewable area
$('div').find('h1').or('p') will return h1 if it exists, if not it will look for p
You can also suspend watching the keys (it does automatically when you enter an input field) with
$.keyNav.unwatchKeys();
then start again
$.keyNav.watchKeys();
Oh and this is a product of Downtown Cartel (http://downtowncartel.com) and is in use(or will be soon) on http://hashtags.org