forked from stepanvr/js-shortcuts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
160 lines (122 loc) · 4.48 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="index.css"/>
<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="fix-ie6.css"/><![endif]-->
<title>JavaScript Shortcuts Library (jQuery plugin)</title>
</head>
<body>
<div id="outer"><div id="content">
<h1>JavaScript Shortcuts Library <small>(jQuery plugin)</small></h1>
<div class="columns">
<div id="usage">
<h2>Usage</h2>
<h3>Add a shortcut to the "default" list:</h3>
<pre style='color:#000000;background:#ffffff;'>$.Shortcuts.add({
type: <span style='color:#2a00ff;'>'down'</span>,
mask: <span style='color:#2a00ff;'>'Ctrl+A'</span>,
handler: <span style='color:#7f0055; font-weight:bold;'>function</span>() {
debug(<span style='color:#2a00ff;'>'Ctrl+A'</span>);
}
});</pre>
<h3>Start reacting to shortcuts:</h3>
<pre style='color:#000000;background:#ffffff;'>$.Shortcuts.start();</pre>
<h3>Add a shortcut to "another" list:</h3>
<pre style='color:#000000;background:#ffffff;'>$.Shortcuts.add({
type: <span style='color:#2a00ff;'>'hold'</span>,
mask: <span style='color:#2a00ff;'>'Shift+Up'</span>,
handler: <span style='color:#7f0055; font-weight:bold;'>function</span>() {
debug(<span style='color:#2a00ff;'>'Shift+Up'</span>);
},
list: <span style='color:#2a00ff;'>'another'</span>
});</pre>
<h3>Activate "another" list:</h3>
<pre style='color:#000000;background:#ffffff;'>$.Shortcuts.start(<span style='color:#2a00ff;'>'another'</span>);</pre>
<h3>Remove a shortcut:</h3>
<pre style='color:#000000;background:#ffffff;'>$.Shortcuts.remove({
type: <span style='color:#2a00ff;'>'hold'</span>,
mask: <span style='color:#2a00ff;'>'Shift+Up'</span>,
list: <span style='color:#2a00ff;'>'another'</span>
});</pre>
<h3>Stop (unbind event listeners):</h3>
<pre style='color:#000000;background:#ffffff;'>$.Shortcuts.stop();</pre>
<h3>Supported Keys</h3>
<ul>
<li>Modifiers: <em>Ctrl, Shift, Alt</em></li>
<li>Numbers: <em>0—9</em></li>
<li>Letters: <em>A—Z (case-insensitive)</em></li>
<li>Special: <em>Backspace, Tab, Enter, Pause, CapsLock, Esc, Space, PageUp, PageDown, End, Home, Left, Up, Right, Down, Insert, Delete, F1—F12, ? (Question Mark)</em></li>
</ul>
</div>
<div id="example">
<h2>Download</h2>
<ul>
<li><a href="jquery.shortcuts.js">jquery.shortcuts.js</a> (7.8 KB, source code)</li>
<li><a href="jquery.shortcuts.min.js">jquery.shortcuts.min.js</a> (2.13 KB, minified)</li>
</ul>
<h2>Test example</h2>
<div class="list corners active">
<p>"default" list:</p>
<ul><li>Ctrl+A (down)</li><li>Shift+B (up)</li></ul>
<form><input type="hidden" name="list" value="default"/><input type="button" value="Activate"/></form>
</div>
<div class="list corners">
<p>"another" list:</p>
<ul><li>Shift+Up (hold)</li><li>Delete (down)</li></ul>
<form><input type="hidden" name="list" value="another"/><input type="button" value="Activate"/></form>
</div>
<p id="debug"><em>Debug output:</em> </p>
</div>
<div class="clear"></div>
</div>
</div></div>
<div id="footer"><p>Feedback: @ <a href="mailto:stepan.reznikov@gmail.com">Stepan Reznikov</a> | <a href="http://github.com/stepanvr/js-shortcuts">GitHub</a></p></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.shortcuts.min.js"></script>
<script type="text/javascript">
var debug = function(msg) {
var node = document.getElementById('debug');
node.innerHTML += msg + ' ';
};
$('.list input[type=button]').click(function() {
var name = $(this).closest('form').find('input[name=list]').val();
$.Shortcuts.start(name);
$('.list').removeClass('active');
$(this).closest('.list').addClass('active');
$(this).blur();
});
$.Shortcuts.add({
type: 'down',
mask: 'Ctrl+A',
handler: function() {
debug('Ctrl+A');
}
});
$.Shortcuts.add({
type: 'up',
mask: 'Shift+B',
handler: function() {
debug('Shift+B');
}
});
$.Shortcuts.add({
type: 'hold',
mask: 'Shift+Up',
handler: function() {
debug('Shift+Up');
},
list: 'another'
});
$.Shortcuts.add({
type: 'down',
mask: 'Delete',
handler: function() {
debug('Delete');
},
list: 'another'
});
$.Shortcuts.start();
</script>
</body>
</html>