3 * Adds '?open=true' query to file attachment links
4 * when ctrl/cmd is pressed down.
7 class AttachmentsList {
10 this.container = this.$el;
11 this.setupListeners();
15 const isExpectedKey = (event) => event.key === 'Control' || event.key === 'Meta';
16 window.addEventListener('keydown', event => {
17 if (isExpectedKey(event)) {
18 this.addOpenQueryToLinks();
21 window.addEventListener('keyup', event => {
22 if (isExpectedKey(event)) {
23 this.removeOpenQueryFromLinks();
28 addOpenQueryToLinks() {
29 const links = this.container.querySelectorAll('a.attachment-file');
30 for (const link of links) {
31 if (link.href.split('?')[1] !== 'open=true') {
32 link.href = link.href + '?open=true';
33 link.setAttribute('target', '_blank');
38 removeOpenQueryFromLinks() {
39 const links = this.container.querySelectorAll('a.attachment-file');
40 for (const link of links) {
41 link.href = link.href.split('?')[0];
42 link.removeAttribute('target');
47 export default AttachmentsList;