X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/09c6a3c2405742ea6003e9a8a30e7ad212ab6977..21ccfa97ddfe6309ff735aafbc8138cf34782563:/resources/js/components/attachments-list.js diff --git a/resources/js/components/attachments-list.js b/resources/js/components/attachments-list.js index 5004f9357..665904f86 100644 --- a/resources/js/components/attachments-list.js +++ b/resources/js/components/attachments-list.js @@ -1,4 +1,4 @@ -import {Component} from "./component"; +import {Component} from './component'; /** * Attachments List @@ -9,15 +9,17 @@ 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)) { @@ -27,22 +29,19 @@ export class AttachmentsList extends Component { } 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 +}