Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropzone: Add "Copy link" button for new uploads #22517

Merged
merged 4 commits into from Jan 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions web_src/js/features/common-global.js
Expand Up @@ -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
let newNode = document.createElement('a');
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
newNode.className = 'dz-remove';
newNode.href = '#';
newNode.innerHTML = '<i class="fa fa-copy"></i> Copy link';
newNode.onclick = (e) => {
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`;
if (file.type.startsWith('image/')) {
fileMarkdown = `!${fileMarkdown}`;
}
navigator.clipboard.writeText(fileMarkdown);
}
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
file.previewTemplate.appendChild(newNode);
});
this.on('removedfile', (file) => {
$(`#${file.uuid}`).remove();
Expand Down