mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 07:45:26 -05:00
138 lines
4.3 KiB
JavaScript
Executable file
138 lines
4.3 KiB
JavaScript
Executable file
/*! @license
|
|
==========================================================================
|
|
SproutCore -- JavaScript Application Framework
|
|
copyright 2006-2009, Sprout Systems Inc., Apple Inc. and contributors.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
copy of this software and associated documentation files (the "Software"),
|
|
to deal in the Software without restriction, including without limitation
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
SproutCore and the SproutCore logo are trademarks of Sprout Systems, Inc.
|
|
|
|
For more information about SproutCore, visit http://www.sproutcore.com
|
|
|
|
|
|
==========================================================================
|
|
@license */
|
|
|
|
// Most of the following code is taken from SproutCore with a few changes.
|
|
|
|
define(function(require, exports, module) {
|
|
"use strict";
|
|
|
|
var oop = require("./oop");
|
|
|
|
/*
|
|
* Helper functions and hashes for key handling.
|
|
*/
|
|
var Keys = (function() {
|
|
var ret = {
|
|
MODIFIER_KEYS: {
|
|
16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta'
|
|
},
|
|
|
|
KEY_MODS: {
|
|
"ctrl": 1, "alt": 2, "option" : 2,
|
|
"shift": 4, "meta": 8, "command": 8, "cmd": 8
|
|
},
|
|
|
|
FUNCTION_KEYS : {
|
|
8 : "Backspace",
|
|
9 : "Tab",
|
|
13 : "Return",
|
|
19 : "Pause",
|
|
27 : "Esc",
|
|
32 : "Space",
|
|
33 : "PageUp",
|
|
34 : "PageDown",
|
|
35 : "End",
|
|
36 : "Home",
|
|
37 : "Left",
|
|
38 : "Up",
|
|
39 : "Right",
|
|
40 : "Down",
|
|
44 : "Print",
|
|
45 : "Insert",
|
|
46 : "Delete",
|
|
96 : "Numpad0",
|
|
97 : "Numpad1",
|
|
98 : "Numpad2",
|
|
99 : "Numpad3",
|
|
100: "Numpad4",
|
|
101: "Numpad5",
|
|
102: "Numpad6",
|
|
103: "Numpad7",
|
|
104: "Numpad8",
|
|
105: "Numpad9",
|
|
'-13': "NumpadEnter",
|
|
112: "F1",
|
|
113: "F2",
|
|
114: "F3",
|
|
115: "F4",
|
|
116: "F5",
|
|
117: "F6",
|
|
118: "F7",
|
|
119: "F8",
|
|
120: "F9",
|
|
121: "F10",
|
|
122: "F11",
|
|
123: "F12",
|
|
144: "Numlock",
|
|
145: "Scrolllock"
|
|
},
|
|
|
|
PRINTABLE_KEYS: {
|
|
32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
|
|
54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
|
|
66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
|
|
73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
|
|
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
|
|
87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
|
|
188: ',', 190: '.', 191: '/', 192: '`', 219: '[', 220: '\\',
|
|
221: ']', 222: '\''
|
|
}
|
|
};
|
|
|
|
// A reverse map of FUNCTION_KEYS
|
|
for (var i in ret.FUNCTION_KEYS) {
|
|
var name = ret.FUNCTION_KEYS[i].toLowerCase();
|
|
ret[name] = parseInt(i, 10);
|
|
}
|
|
|
|
// Add the MODIFIER_KEYS, FUNCTION_KEYS and PRINTABLE_KEYS to the KEY
|
|
// variables as well.
|
|
oop.mixin(ret, ret.MODIFIER_KEYS);
|
|
oop.mixin(ret, ret.PRINTABLE_KEYS);
|
|
oop.mixin(ret, ret.FUNCTION_KEYS);
|
|
|
|
// aliases
|
|
ret.enter = ret["return"];
|
|
ret.escape = ret.esc;
|
|
ret.del = ret["delete"];
|
|
|
|
// workaround for firefox bug
|
|
ret[173] = '-';
|
|
|
|
return ret;
|
|
})();
|
|
oop.mixin(exports, Keys);
|
|
|
|
exports.keyCodeToString = function(keyCode) {
|
|
return (Keys[keyCode] || String.fromCharCode(keyCode)).toLowerCase();
|
|
}
|
|
|
|
});
|