]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/attachments-list.js
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / resources / js / components / attachments-list.js
index 34979c2e7a8207d376aa12534b0d3745e3a34d7d..665904f86163998503bd2cdd23c341f3c07d6aa4 100644 (file)
@@ -1,22 +1,25 @@
+import {Component} from './component';
+
 /**
  * Attachments List
  * Adds '?open=true' query to file attachment links
  * when ctrl/cmd is pressed down.
- * @extends {Component}
  */
-class AttachmentsList {
+export class AttachmentsList extends Component {
 
     setup() {
         this.container = this.$el;
+        this.fileLinks = this.$manyRefs.linkTypeFile;
+
         this.setupListeners();
     }
 
     setupListeners() {
-        const isExpectedKey = (event) => event.key === 'Control' || event.key === 'Meta';
+        const isExpectedKey = event => event.key === 'Control' || event.key === 'Meta';
         window.addEventListener('keydown', event => {
-             if (isExpectedKey(event)) {
+            if (isExpectedKey(event)) {
                 this.addOpenQueryToLinks();
-             }
+            }
         }, {passive: true});
         window.addEventListener('keyup', event => {
             if (isExpectedKey(event)) {
@@ -26,22 +29,19 @@ class AttachmentsList {
     }
 
     addOpenQueryToLinks() {
-        const links = this.container.querySelectorAll('a.attachment-file');
-        for (const link of links) {
+        for (const link of this.fileLinks) {
             if (link.href.split('?')[1] !== 'open=true') {
-                link.href = link.href + '?open=true';
+                link.href += '?open=true';
                 link.setAttribute('target', '_blank');
             }
         }
     }
 
     removeOpenQueryFromLinks() {
-        const links = this.container.querySelectorAll('a.attachment-file');
-        for (const link of links) {
+        for (const link of this.fileLinks) {
             link.href = link.href.split('?')[0];
             link.removeAttribute('target');
         }
     }
-}
 
-export default AttachmentsList;
\ No newline at end of file
+}