diff options
author | 2018-10-21 18:32:07 -0700 | |
---|---|---|
committer | 2018-10-21 18:32:07 -0700 | |
commit | 9440bf47a521a61c91073425bd613710cf7dd1cb (patch) | |
tree | 976d5d56cc569e7c3c1aa50531138e03728e7fe4 /ui/static/js | |
parent | 8c65c78904225e92df045cac43700210936ca148 (diff) |
Call preventDefault() when a keyboard shortcut is executed
Diffstat (limited to 'ui/static/js')
-rw-r--r-- | ui/static/js/bootstrap.js | 2 | ||||
-rw-r--r-- | ui/static/js/keyboard_handler.js | 14 | ||||
-rw-r--r-- | ui/static/js/nav_handler.js | 5 |
3 files changed, 12 insertions, 9 deletions
diff --git a/ui/static/js/bootstrap.js b/ui/static/js/bootstrap.js index 5c0bfac..1327a22 100644 --- a/ui/static/js/bootstrap.js +++ b/ui/static/js/bootstrap.js @@ -29,7 +29,7 @@ document.addEventListener("DOMContentLoaded", function() { keyboardHandler.on("f", () => navHandler.toggleBookmark()); keyboardHandler.on("?", () => navHandler.showKeyboardShortcuts()); keyboardHandler.on("#", () => navHandler.unsubscribeFromFeed()); - keyboardHandler.on("/", (e) => navHandler.setFocusToSearchInput(e)); + keyboardHandler.on("/", () => navHandler.setFocusToSearchInput()); keyboardHandler.on("Escape", () => ModalHandler.close()); keyboardHandler.listen(); diff --git a/ui/static/js/keyboard_handler.js b/ui/static/js/keyboard_handler.js index df6eefc..e30b0dd 100644 --- a/ui/static/js/keyboard_handler.js +++ b/ui/static/js/keyboard_handler.js @@ -21,14 +21,12 @@ class KeyboardHandler { let keys = combination.split(" "); if (keys.every((value, index) => value === this.queue[index])) { - this.queue = []; - this.shortcuts[combination](event); + this.execute(combination, event); return; } if (keys.length === 1 && key === keys[0]) { - this.queue = []; - this.shortcuts[combination](event); + this.execute(combination, event); return; } } @@ -39,6 +37,14 @@ class KeyboardHandler { }; } + execute(combination, event) { + event.preventDefault(); + event.stopPropagation(); + + this.queue = []; + this.shortcuts[combination](event); + } + isEventIgnored(event) { return event.target.tagName === "INPUT" || event.target.tagName === "TEXTAREA"; } diff --git a/ui/static/js/nav_handler.js b/ui/static/js/nav_handler.js index dd10607..689f206 100644 --- a/ui/static/js/nav_handler.js +++ b/ui/static/js/nav_handler.js @@ -1,8 +1,5 @@ class NavHandler { - setFocusToSearchInput(event) { - event.preventDefault(); - event.stopPropagation(); - + setFocusToSearchInput() { let toggleSwitchElement = document.querySelector(".search-toggle-switch"); if (toggleSwitchElement) { toggleSwitchElement.style.display = "none"; |