comparison src/DML/VendorAssetsBundle/Resources/assets/jquery.hotkeys/0.8/jquery.hotkeys.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 /*!
2 * jQuery Hotkeys Plugin
3 * Copyright 2010, John Resig
4 * Dual licensed under the MIT or GPL Version 2 licenses.
5 *
6 * Based upon the plugin by Tzury Bar Yochay:
7 * http://github.com/tzuryby/hotkeys
8 *
9 * Original idea by:
10 * Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
11 */
12
13 /*
14 * One small change is: now keys are passed by object { keys: '...' }
15 * Might be useful, when you want to pass some other data to your handler
16 */
17
18 (function(jQuery) {
19
20 jQuery.hotkeys = {
21 version: "0.8",
22
23 specialKeys: {
24 8: "backspace",
25 9: "tab",
26 10: "return",
27 13: "return",
28 16: "shift",
29 17: "ctrl",
30 18: "alt",
31 19: "pause",
32 20: "capslock",
33 27: "esc",
34 32: "space",
35 33: "pageup",
36 34: "pagedown",
37 35: "end",
38 36: "home",
39 37: "left",
40 38: "up",
41 39: "right",
42 40: "down",
43 45: "insert",
44 46: "del",
45 59: ";",
46 61: "=",
47 96: "0",
48 97: "1",
49 98: "2",
50 99: "3",
51 100: "4",
52 101: "5",
53 102: "6",
54 103: "7",
55 104: "8",
56 105: "9",
57 106: "*",
58 107: "+",
59 109: "-",
60 110: ".",
61 111: "/",
62 112: "f1",
63 113: "f2",
64 114: "f3",
65 115: "f4",
66 116: "f5",
67 117: "f6",
68 118: "f7",
69 119: "f8",
70 120: "f9",
71 121: "f10",
72 122: "f11",
73 123: "f12",
74 144: "numlock",
75 145: "scroll",
76 173: "-",
77 186: ";",
78 187: "=",
79 188: ",",
80 189: "-",
81 190: ".",
82 191: "/",
83 192: "`",
84 219: "[",
85 220: "\\",
86 221: "]",
87 222: "'"
88 },
89
90 shiftNums: {
91 "`": "~",
92 "1": "!",
93 "2": "@",
94 "3": "#",
95 "4": "$",
96 "5": "%",
97 "6": "^",
98 "7": "&",
99 "8": "*",
100 "9": "(",
101 "0": ")",
102 "-": "_",
103 "=": "+",
104 ";": ": ",
105 "'": "\"",
106 ",": "<",
107 ".": ">",
108 "/": "?",
109 "\\": "|"
110 },
111
112 // excludes: button, checkbox, file, hidden, image, password, radio, reset, search, submit, url
113 textAcceptingInputTypes: [
114 "text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime",
115 "datetime-local", "search", "color", "tel"],
116
117 options: {
118 filterTextInputs: true
119 }
120 };
121
122 function keyHandler(handleObj) {
123 if (typeof handleObj.data === "string") {
124 handleObj.data = {
125 keys: handleObj.data
126 };
127 }
128
129 // Only care when a possible input has been specified
130 if (!handleObj.data || !handleObj.data.keys || typeof handleObj.data.keys !== "string") {
131 return;
132 }
133
134 var origHandler = handleObj.handler,
135 keys = handleObj.data.keys.toLowerCase().split(" ");
136
137 handleObj.handler = function(event) {
138 // Don't fire in text-accepting inputs that we didn't directly bind to
139 if (this !== event.target && (/textarea|select/i.test(event.target.nodeName) ||
140 (jQuery.hotkeys.options.filterTextInputs &&
141 jQuery.inArray(event.target.type, jQuery.hotkeys.textAcceptingInputTypes) > -1))) {
142 return;
143 }
144
145 var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[event.which],
146 character = String.fromCharCode(event.which).toLowerCase(),
147 modif = "",
148 possible = {};
149
150 jQuery.each(["alt", "ctrl", "shift"], function(index, specialKey) {
151
152 if (event[specialKey + 'Key'] && special !== specialKey) {
153 modif += specialKey + '+';
154 }
155 });
156
157 // metaKey is triggered off ctrlKey erronously
158 if (event.metaKey && !event.ctrlKey && special !== "meta") {
159 modif += "meta+";
160 }
161
162 if (event.metaKey && special !== "meta" && modif.indexOf("alt+ctrl+shift+") > -1) {
163 modif = modif.replace("alt+ctrl+shift+", "hyper+");
164 }
165
166 if (special) {
167 possible[modif + special] = true;
168 }
169 else {
170 possible[modif + character] = true;
171 possible[modif + jQuery.hotkeys.shiftNums[character]] = true;
172
173 // "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
174 if (modif === "shift+") {
175 possible[jQuery.hotkeys.shiftNums[character]] = true;
176 }
177 }
178
179 for (var i = 0, l = keys.length; i < l; i++) {
180 if (possible[keys[i]]) {
181 return origHandler.apply(this, arguments);
182 }
183 }
184 };
185 }
186
187 jQuery.each(["keydown", "keyup", "keypress"], function() {
188 jQuery.event.special[this] = {
189 add: keyHandler
190 };
191 });
192
193 })(jQuery || this.jQuery || window.jQuery);