]> BookStack Code Mirror - bookstack/commitdiff
Merge pull request #4193 from BookStackApp/custom_dropzone
authorDan Brown <redacted>
Thu, 27 Apr 2023 12:43:38 +0000 (13:43 +0100)
committerGitHub <redacted>
Thu, 27 Apr 2023 12:43:38 +0000 (13:43 +0100)
Custom dropzone implementation

.gitignore
resources/js/components/shortcuts.js

index 5f3aa6600066ce2dcd5e702153da2a8f856ae418..ba4ccafc6fa0b8cdcf4ae2c642c89fe9b5d47cb8 100644 (file)
@@ -1,5 +1,6 @@
 /vendor
 /node_modules
+/.vscode
 Homestead.yaml
 .env
 .idea
index 8e927e34cfcd05d2c371eca42ce1c1585fd84396..1d5bd51d7849a1b57c107b45802d90daf2fcbc38 100644 (file)
@@ -18,6 +18,7 @@ export class Shortcuts extends Component {
         this.hintsShowing = false;
 
         this.hideHints = this.hideHints.bind(this);
+        this.hintAbortController = null;
 
         this.setupListeners();
     }
@@ -33,8 +34,11 @@ export class Shortcuts extends Component {
 
         window.addEventListener('keydown', event => {
             if (event.key === '?') {
-                const action = this.hintsShowing ? this.hideHints : this.showHints;
-                action();
+                if (this.hintsShowing) {
+                    this.hideHints();
+                } else {
+                    this.showHints();
+                }
             }
         });
     }
@@ -111,10 +115,12 @@ export class Shortcuts extends Component {
             displayedIds.add(id);
         }
 
-        window.addEventListener('scroll', this.hideHints);
-        window.addEventListener('focus', this.hideHints);
-        window.addEventListener('blur', this.hideHints);
-        window.addEventListener('click', this.hideHints);
+        this.hintAbortController = new AbortController();
+        const signal = this.hintAbortController.signal;
+        window.addEventListener('scroll', this.hideHints, {signal});
+        window.addEventListener('focus', this.hideHints, {signal});
+        window.addEventListener('blur', this.hideHints, {signal});
+        window.addEventListener('click', this.hideHints, {signal});
 
         this.hintsShowing = true;
     }
@@ -149,12 +155,7 @@ export class Shortcuts extends Component {
     hideHints() {
         const wrapper = this.container.querySelector('.shortcut-container');
         wrapper.remove();
-
-        window.removeEventListener('scroll', this.hideHints);
-        window.removeEventListener('focus', this.hideHints);
-        window.removeEventListener('blur', this.hideHints);
-        window.removeEventListener('click', this.hideHints);
-
+        this.hintAbortController?.abort();
         this.hintsShowing = false;
     }