This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/attachments/static/attachments/js/copy_url.js

25 lines
790 B
JavaScript
Raw Normal View History

2020-08-28 21:49:15 +02:00
function copy(data) {
navigator.clipboard.writeText(data.data).then(() => {
2020-08-28 21:49:15 +02:00
console.log("Copied");
})
}
$(document).ready(function() {
const $ = django.jQuery;
const fileUrls = $('td.field-processed_file_url, td.field-original_file_url');
let id = 0;
2020-08-28 21:49:15 +02:00
for (let fileUrl of fileUrls) {
fileUrl = $(fileUrl);
2020-08-28 21:58:18 +02:00
const existingText = fileUrl.text().trim();
if (!existingText) {
continue;
}
const buttonId = `copy-button-${id}`;
const copyButton = `<a class="copy-button" id="${buttonId}" href="#">&#128203;</a>`;
2020-08-28 21:49:15 +02:00
let innerHTML = `<span>${existingText}</span> ${copyButton}`;
fileUrl.html(innerHTML);
$(`#${buttonId}`).on("click", null, existingText, copy);
id++;
2020-08-28 21:49:15 +02:00
}
});