annotate src/DML/VendorAssetsBundle/Resources/assets/jquery.hotkeys/0.8/jquery.hotkeys.js @ 1:f38015048f48 tip

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