summaryrefslogtreecommitdiff
path: root/client/lib/keys.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/lib/keys.js')
-rw-r--r--client/lib/keys.js66
1 files changed, 38 insertions, 28 deletions
diff --git a/client/lib/keys.js b/client/lib/keys.js
index c9e51ac..84f8103 100644
--- a/client/lib/keys.js
+++ b/client/lib/keys.js
@@ -1,39 +1,49 @@
-const keys = {}
-const key_numbers = {}
-const letters = "zxcvbnmasdfghjklqwertyuiop"
-const numbers = "1234567890"
+/**
+ * Keyboard helper
+ * @module lib/keys.js;
+ */
-let callback = function(){}
+const keys = {};
+const key_numbers = {};
+const letters = "zxcvbnmasdfghjklqwertyuiop";
+const numbers = "1234567890";
-letters.toUpperCase().split("").map(function(k,i){
- keys[k.charCodeAt(0)] = i
-})
+let callback = function () {};
-numbers.split("").map(function(k,i){
- keys[k.charCodeAt(0)] = i+letters.length
- key_numbers[k.charCodeAt(0)] = true
-})
+letters
+ .toUpperCase()
+ .split("")
+ .map(function (k, i) {
+ keys[k.charCodeAt(0)] = i;
+ });
-window.addEventListener("keydown", keydown, true)
-function keydown (e) {
+numbers.split("").map(function (k, i) {
+ keys[k.charCodeAt(0)] = i + letters.length;
+ key_numbers[k.charCodeAt(0)] = true;
+});
+
+window.addEventListener("keydown", keydown, true);
+function keydown(e) {
if (e.altKey || e.ctrlKey || e.metaKey) {
- e.stopPropagation()
- return
+ e.stopPropagation();
+ return;
}
- if (document.activeElement instanceof HTMLInputElement &&
- (e.keyCode in key_numbers)) {
- e.stopPropagation()
- return
+ if (
+ document.activeElement instanceof HTMLInputElement &&
+ e.keyCode in key_numbers
+ ) {
+ e.stopPropagation();
+ return;
}
- if (! (e.keyCode in keys)) return
- var index = keys[e.keyCode]
- if (e.shiftKey) index += letters.length
- index -= 7
- callback(index)
+ if (!(e.keyCode in keys)) return;
+ var index = keys[e.keyCode];
+ if (e.shiftKey) index += letters.length;
+ index -= 7;
+ callback(index);
}
-function listen (fn) {
- callback = fn
+function listen(fn) {
+ callback = fn;
}
-export default { listen } \ No newline at end of file
+export default { listen };