From 90873c648b306cbe5b21fe2dc25251d92c855f1a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 30 Aug 2020 17:53:11 -0700 Subject: [PATCH] Move hotkey listener from anonymous to named function. --- .../etiquette_flask/static/js/hotkeys.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/frontends/etiquette_flask/static/js/hotkeys.js b/frontends/etiquette_flask/static/js/hotkeys.js index aa39a6a..859972f 100644 --- a/frontends/etiquette_flask/static/js/hotkeys.js +++ b/frontends/etiquette_flask/static/js/hotkeys.js @@ -57,19 +57,19 @@ function show_all_hotkeys() alert(lines); } -window.addEventListener( - "keydown", - function(event) +hotkeys.hotkeys_listener = +function hotkeys_listener(event) +{ + if (hotkeys.should_prevent_hotkey(event)) { return; } + identifier = hotkeys.hotkey_identifier(event.key, event.ctrlKey, event.shiftKey, event.altKey); + console.log(identifier); + if (identifier in hotkeys.HOTKEYS) { - if (hotkeys.should_prevent_hotkey(event)) { return; } - identifier = hotkeys.hotkey_identifier(event.key, event.ctrlKey, event.shiftKey, event.altKey); - console.log(identifier); - if (identifier in hotkeys.HOTKEYS) - { - hotkeys.HOTKEYS[identifier]["action"](); - event.preventDefault(); - } + hotkeys.HOTKEYS[identifier]["action"](); + event.preventDefault(); } -); +} + +window.addEventListener("keydown", hotkeys.hotkeys_listener); hotkeys.register_hotkey("/", 0, 0, 0, hotkeys.show_all_hotkeys, "Show hotkeys.");