From 3247cb6015db05423d59463dd2c7e38588a8edc0 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 18 Jan 2023 23:02:49 +0100 Subject: [PATCH 1/3] Dropzone: Add "Copy link" button for new uploads Once an attachment is successfully uploaded via Dropzone, display a "Copy link" under the "Remove file" button. Once the button is clicked, depending if the attachment is an image or a file, the appropriate markup is written to the clipboard, so it can be conveniently pasted in the description. --- web_src/js/features/common-global.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 2504f3be0acaf..37aa6694a9dad 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -167,6 +167,21 @@ export function initGlobalDropzone() { file.uuid = data.uuid; const input = $(``).val(data.uuid); $dropzone.find('.files').append(input); + // Create a "Copy Link" element, to conveniently copy the image + // or file link as Markdown to the clipboard + let newNode = document.createElement('a'); + newNode.className = 'dz-remove'; + newNode.href = '#'; + newNode.innerHTML = ' Copy link'; + newNode.onclick = (e) => { + e.preventDefault(); + let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`; + if (file.type.startsWith('image/')) { + fileMarkdown = `!${fileMarkdown}`; + } + navigator.clipboard.writeText(fileMarkdown); + } + file.previewTemplate.appendChild(newNode); }); this.on('removedfile', (file) => { $(`#${file.uuid}`).remove(); From 824bd688460347c7f94cb61f7554bc4e75c473ca Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 18 Jan 2023 23:13:28 +0100 Subject: [PATCH 2/3] Address lint-frontend errors --- web_src/js/features/common-global.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 37aa6694a9dad..e8be31daf741d 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -167,20 +167,20 @@ export function initGlobalDropzone() { file.uuid = data.uuid; const input = $(``).val(data.uuid); $dropzone.find('.files').append(input); - // Create a "Copy Link" element, to conveniently copy the image - // or file link as Markdown to the clipboard - let newNode = document.createElement('a'); - newNode.className = 'dz-remove'; - newNode.href = '#'; - newNode.innerHTML = ' Copy link'; - newNode.onclick = (e) => { + // Create a "Copy Link" element, to conveniently copy the image + // or file link as Markdown to the clipboard + const copyLinkElement = document.createElement('a'); + copyLinkElement.className = 'dz-remove'; + copyLinkElement.href = '#'; + copyLinkElement.innerHTML = ' Copy link'; + copyLinkElement.addEventListener('click', (e) => { e.preventDefault(); let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`; if (file.type.startsWith('image/')) { fileMarkdown = `!${fileMarkdown}`; } navigator.clipboard.writeText(fileMarkdown); - } + }); file.previewTemplate.appendChild(newNode); }); this.on('removedfile', (file) => { From 9e77dce147a9316448089823428071e3b03f1b85 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 18 Jan 2023 23:28:36 +0100 Subject: [PATCH 3/3] Address lint-frontend errors --- web_src/js/features/common-global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index e8be31daf741d..ab45267b84323 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -181,7 +181,7 @@ export function initGlobalDropzone() { } navigator.clipboard.writeText(fileMarkdown); }); - file.previewTemplate.appendChild(newNode); + file.previewTemplate.appendChild(copyLinkElement); }); this.on('removedfile', (file) => { $(`#${file.uuid}`).remove();