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.setupListeners();
16 const isExpectedKey = (event) => event.key === 'Control' || event.key === 'Meta';
17 window.addEventListener('keydown', event => {
18 if (isExpectedKey(event)) {
19 this.addOpenQueryToLinks();
22 window.addEventListener('keyup', event => {
23 if (isExpectedKey(event)) {
24 this.removeOpenQueryFromLinks();
29 addOpenQueryToLinks() {
30 const links = this.container.querySelectorAll('a.attachment-file');
31 for (const link of links) {
32 if (link.href.split('?')[1] !== 'open=true') {
33 link.href = link.href + '?open=true';
34 link.setAttribute('target', '_blank');
39 removeOpenQueryFromLinks() {
40 const links = this.container.querySelectorAll('a.attachment-file');
41 for (const link of links) {
42 link.href = link.href.split('?')[0];
43 link.removeAttribute('target');