A simple ticketing application written in Python/Django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.hotkeys.js 4.5KB

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