Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use human-readable keys

  • Loading branch information...
commit 7693224fe10a324c414bdf5c896056b01a21e19d 1 parent 13ccc70
@etrepum etrepum authored
Showing with 31 additions and 8 deletions.
  1. +31 −8 priv/static/erldocs.js
View
39 priv/static/erldocs.js
@@ -1,4 +1,24 @@
var ErlDocs = (function(index) {
+ /* Human readable keyCode index */
+ var KEY = {'BACKSPACE': 8, 'TAB': 9, 'NUM_PAD_CLEAR': 12, 'ENTER': 13, 'SHIFT': 16, 'CTRL': 17, 'ALT': 18, 'PAUSE': 19, 'CAPS_LOCK': 20, 'ESCAPE': 27, 'SPACEBAR': 32, 'PAGE_UP': 33, 'PAGE_DOWN': 34, 'END': 35, 'HOME': 36, 'ARROW_LEFT': 37, 'ARROW_UP': 38, 'ARROW_RIGHT': 39, 'ARROW_DOWN': 40, 'PRINT_SCREEN': 44, 'INSERT': 45, 'DELETE': 46, 'SEMICOLON': 59, 'WINDOWS_LEFT': 91, 'WINDOWS_RIGHT': 92, 'SELECT': 93, 'NUM_PAD_ASTERISK': 106, 'NUM_PAD_PLUS_SIGN': 107, 'NUM_PAD_HYPHEN-MINUS': 109, 'NUM_PAD_FULL_STOP': 110, 'NUM_PAD_SOLIDUS': 111, 'NUM_LOCK': 144, 'SCROLL_LOCK': 145, 'SEMICOLON': 186, 'EQUALS_SIGN': 187, 'COMMA': 188, 'HYPHEN-MINUS': 189, 'FULL_STOP': 190, 'SOLIDUS': 191, 'GRAVE_ACCENT': 192, 'LEFT_SQUARE_BRACKET': 219, 'REVERSE_SOLIDUS': 220, 'RIGHT_SQUARE_BRACKET': 221, 'APOSTROPHE': 222};
+ (function () {
+ /* 0 - 9 */
+ for (var i = 48; i <= 57; i++) {
+ KEY['' + (i - 48)] = i;
+ }
+ /* A - Z */
+ for (i = 65; i <= 90; i++) {
+ KEY['' + String.fromCharCode(i)] = i;
+ }
+ /* NUM_PAD_0 - NUM_PAD_9 */
+ for (i = 96; i <= 105; i++) {
+ KEY['NUM_PAD_' + (i - 96)] = i;
+ }
+ /* F1 - F12 */
+ for (i = 112; i <= 123; i++) {
+ KEY['F' + (i - 112 + 1)] = i;
+ }
+ })();
var $search = $("#search"),
$results = $("#results"),
@@ -61,17 +81,18 @@ var ErlDocs = (function(index) {
function keypress(e) {
- var tmp, blockedKeys = [0, 9, 17, 18, 91, 192];
+ var tmp, blockedKeys = [0, KEY.TAB, KEY.CTRL, KEY.ALT,
+ KEY.WINDOWS_LEFT, KEY.GRAVE_ACCENT];
if (!($.inArray(e.keyCode, blockedKeys) === -1)) {
return;
}
- if (e.keyCode === 40) { setSelected(selected + 1);
- } else if (e.keyCode === 38) { setSelected(selected - 1);
- } else if (e.keyCode === 34) { setSelected(selected + 7);
- } else if (e.keyCode === 33) { setSelected(selected - 7);
- } else if (e.keyCode === 13) { //ENTER
+ if (e.keyCode === KEY.ARROW_DOWN) { setSelected(selected + 1);
+ } else if (e.keyCode === KEY.ARROW_UP) { setSelected(selected - 1);
+ } else if (e.keyCode === KEY.PAGE_DOWN) { setSelected(selected + 7);
+ } else if (e.keyCode === KEY.PAGE_UP) { setSelected(selected - 7);
+ } else if (e.keyCode === KEY.ENTER) {
tmp = $results.children(".selected");
if (tmp.length > 0) {
document.location.href = tmp.find("a").attr("href");
@@ -219,7 +240,9 @@ var ErlDocs = (function(index) {
// // Set up a timer to repeat (holding down arrow keys etc)
var timer = null, timeout = null,
- repeatKeys = [33, 34, 38, 40, 8],
+ repeatKeys = [KEY.PAGE_UP, KEY.PAGE_DOWN,
+ KEY.ARROW_UP, KEY.ARROW_DOWN,
+ KEY.BACKSPACE],
set_interval = function () {
timer = setInterval(function () { keypress(e); }, 60);
};
@@ -258,7 +281,7 @@ var ErlDocs = (function(index) {
$(document).bind("keypress", function(e) {
- if (e.keyCode === 9) {
+ if (e.keyCode === KEY.TAB) {
e.preventDefault();
e.stopPropagation();
Please sign in to comment.
Something went wrong with that request. Please try again.