-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
106 lines (84 loc) · 2.76 KB
/
index.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!doctype html>
<html>
<head>
<script src='javascript/jquery-1.9.1.min.js'></script>
<script src='javascript/jquery.keynav.js'></script>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<h1 id="jquerykeyboardnavigationplugin">jQuery Keyboard Navigation plugin</h1>
<p>This plugin allows you to navigate a set of links layed out in a matrix from keyboard:</p>
<p class="navigation" id="navigation">
Keyboard Navigation:
<a href="#link" id="enable" class="selected">Enabled</a>
<a href="#link" id="disable">Disabled</a>
</p>
<ul class="nav_holder clearfix">
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
<li>
<a href="#link">Navigation Item</a>
</li>
</ul>
<p>The rows should have the same vertical offset. You can mark one element with <code>.selected</code> class, or the first one will be selected.</p>
<p>Enter key replaces <code>window.location.href</code> with the current <code>href</code> value.</p>
<h2 id="usage:">Usage:</h2>
<pre><code>$('#navigation a').keynav();
</code></pre>
<p>This will enable keyboard navigation for the links in <code>#navigation</code> container. If you need to have some control on the state of plugin you can pass the additional function as a single parameter:</p>
<pre><code>$('#navigation a').keynav(function(){
return window.keyNavigationDisabled;
});
</code></pre>
<p>Note: If the function passed returns <code>true</code> - keyboard navigation stops.</p>
<script>
$(function(){
updateControls = function() {
$('#navigation a').removeClass();
$((window.keyNavigationDisabled?'#disable':'#enable')).addClass('selected');
}
a=$('.nav_holder a').keynav(function() {
return window.keyNavigationDisabled;
});
$('#disable').click(function(){
window.keyNavigationDisabled=true;
updateControls();
});
$('#enable').click(function(){
window.keyNavigationDisabled=false;
updateControls();
});
});
</script>
<a class="selected download" href="https://github.com/firedev/jquery.keynav/blob/master/javascript/jquery.keynav.js">Download from GitHub</a>
<a href="https://github.com/firedev/jquery.keynav"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub"></a>
</body>
</html>