Parcourir la source

Call preventDefault() when a keyboard shortcut is executed

Frédéric Guillot il y a 7 ans
Parent
commit
9440bf47a5
4 fichiers modifiés avec 16 ajouts et 12 suppressions
  1. 4 3
      ui/static/js.go
  2. 1 1
      ui/static/js/bootstrap.js
  3. 10 4
      ui/static/js/keyboard_handler.js
  4. 1 4
      ui/static/js/nav_handler.js

Fichier diff supprimé car celui-ci est trop grand
+ 4 - 3
ui/static/js.go


+ 1 - 1
ui/static/js/bootstrap.js

@@ -29,7 +29,7 @@ document.addEventListener("DOMContentLoaded", function() {
     keyboardHandler.on("f", () => navHandler.toggleBookmark());
     keyboardHandler.on("f", () => navHandler.toggleBookmark());
     keyboardHandler.on("?", () => navHandler.showKeyboardShortcuts());
     keyboardHandler.on("?", () => navHandler.showKeyboardShortcuts());
     keyboardHandler.on("#", () => navHandler.unsubscribeFromFeed());
     keyboardHandler.on("#", () => navHandler.unsubscribeFromFeed());
-    keyboardHandler.on("/", (e) => navHandler.setFocusToSearchInput(e));
+    keyboardHandler.on("/", () => navHandler.setFocusToSearchInput());
     keyboardHandler.on("Escape", () => ModalHandler.close());
     keyboardHandler.on("Escape", () => ModalHandler.close());
     keyboardHandler.listen();
     keyboardHandler.listen();
 
 

+ 10 - 4
ui/static/js/keyboard_handler.js

@@ -21,14 +21,12 @@ class KeyboardHandler {
                 let keys = combination.split(" ");
                 let keys = combination.split(" ");
 
 
                 if (keys.every((value, index) => value === this.queue[index])) {
                 if (keys.every((value, index) => value === this.queue[index])) {
-                    this.queue = [];
-                    this.shortcuts[combination](event);
+                    this.execute(combination, event);
                     return;
                     return;
                 }
                 }
 
 
                 if (keys.length === 1 && key === keys[0]) {
                 if (keys.length === 1 && key === keys[0]) {
-                    this.queue = [];
-                    this.shortcuts[combination](event);
+                    this.execute(combination, event);
                     return;
                     return;
                 }
                 }
             }
             }
@@ -39,6 +37,14 @@ class KeyboardHandler {
         };
         };
     }
     }
 
 
+    execute(combination, event) {
+        event.preventDefault();
+        event.stopPropagation();
+
+        this.queue = [];
+        this.shortcuts[combination](event);
+    }
+
     isEventIgnored(event) {
     isEventIgnored(event) {
         return event.target.tagName === "INPUT" || event.target.tagName === "TEXTAREA";
         return event.target.tagName === "INPUT" || event.target.tagName === "TEXTAREA";
     }
     }

+ 1 - 4
ui/static/js/nav_handler.js

@@ -1,8 +1,5 @@
 class NavHandler {
 class NavHandler {
-    setFocusToSearchInput(event) {
-        event.preventDefault();
-        event.stopPropagation();
-
+    setFocusToSearchInput() {
         let toggleSwitchElement = document.querySelector(".search-toggle-switch");
         let toggleSwitchElement = document.querySelector(".search-toggle-switch");
         if (toggleSwitchElement) {
         if (toggleSwitchElement) {
             toggleSwitchElement.style.display = "none";
             toggleSwitchElement.style.display = "none";

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff