1 import {Component} from './component';
5 * Adds '?open=true' query to file attachment links
6 * when ctrl/cmd is pressed down.
8 export class AttachmentsList extends Component {
11 this.container = this.$el;
12 this.fileLinks = this.$manyRefs.linkTypeFile;
14 this.setupListeners();
18 const isExpectedKey = event => event.key === 'Control' || event.key === 'Meta';
19 window.addEventListener('keydown', event => {
20 if (isExpectedKey(event)) {
21 this.addOpenQueryToLinks();
24 window.addEventListener('keyup', event => {
25 if (isExpectedKey(event)) {
26 this.removeOpenQueryFromLinks();
31 addOpenQueryToLinks() {
32 for (const link of this.fileLinks) {
33 if (link.href.split('?')[1] !== 'open=true') {
34 link.href += '?open=true';
35 link.setAttribute('target', '_blank');
40 removeOpenQueryFromLinks() {
41 for (const link of this.fileLinks) {
42 link.href = link.href.split('?')[0];
43 link.removeAttribute('target');