Remove onclick because CSP doesn't allow it

This commit is contained in:
Gabriel Augendre 2020-08-28 22:09:50 +02:00
parent 9813b4252b
commit 6c3ab47a9b
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4

View file

@ -1,5 +1,5 @@
function copy(data) {
navigator.clipboard.writeText(data).then(() => {
navigator.clipboard.writeText(data.data).then(() => {
console.log("Copied");
})
}
@ -7,14 +7,18 @@ function copy(data) {
$(document).ready(function() {
const $ = django.jQuery;
const fileUrls = $('td.field-processed_file_url, td.field-original_file_url');
let id = 0;
for (let fileUrl of fileUrls) {
fileUrl = $(fileUrl);
const existingText = fileUrl.text().trim();
if (!existingText) {
continue;
}
const copyButton = `<a class='copy-button' href='#' onclick="copy(\'${existingText}\')">&#128203;</a>`;
const buttonId = `copy-button-${id}`;
const copyButton = `<a class="copy-button" id="${buttonId}" href="#">&#128203;</a>`;
let innerHTML = `<span>${existingText}</span> ${copyButton}`;
fileUrl.html(innerHTML);
$(`#${buttonId}`).on("click", null, existingText, copy);
id++;
}
});