aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Siddi <francesco.siddi@gmail.com>2023-01-19 06:33:40 +0100
committerGitHub <noreply@github.com>2023-01-19 13:33:40 +0800
commit9f919cf08339e8ec8f6b0b2a0dcafb3ea905fbec (patch)
treed895e3adef5372b03bd76e7e8244b9a09ccf52d1
parent151b1a9508d9a407163edbf3d726b4785afef5ce (diff)
downloadgitea-9f919cf08339e8ec8f6b0b2a0dcafb3ea905fbec.tar.gz
gitea-9f919cf08339e8ec8f6b0b2a0dcafb3ea905fbec.zip
Dropzone: Add "Copy link" button for new uploads (#22517)
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.
-rw-r--r--web_src/js/features/common-global.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js
index 2504f3be0a..ab45267b84 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 = $(`<input id="${data.uuid}" name="files" type="hidden">`).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
+ const copyLinkElement = document.createElement('a');
+ copyLinkElement.className = 'dz-remove';
+ copyLinkElement.href = '#';
+ copyLinkElement.innerHTML = '<i class="fa fa-copy"></i> 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(copyLinkElement);
});
this.on('removedfile', (file) => {
$(`#${file.uuid}`).remove();