From 6acfd2fc836a094636fdabecee58ead6778391fa Mon Sep 17 00:00:00 2001 From: boyska Date: Sat, 7 Dec 2024 20:08:34 +0100 Subject: [PATCH] refactor /list JS --- caricari/static/list.js | 27 +++++++++++++++++++++++++++ caricari/templates/list.html | 29 +---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 caricari/static/list.js diff --git a/caricari/static/list.js b/caricari/static/list.js new file mode 100644 index 0000000..ad36640 --- /dev/null +++ b/caricari/static/list.js @@ -0,0 +1,27 @@ +function live (eventType, elementQuerySelector, cb) { + document.addEventListener(eventType, function (event) { + + var qs = document.querySelectorAll(elementQuerySelector); + + if (qs) { + var el = event.target, index = -1; + while (el && ((index = Array.prototype.indexOf.call(qs, el)) === -1)) { + el = el.parentElement; + } + + if (index > -1) { + cb.call(el, event); + } + } + }); +} +if (navigator && navigator.clipboard && navigator.clipboard.writeText) { // supported + live('click', 'button.copy', + function copy(evt) { + const url = evt.target.dataset.text; + navigator.clipboard.writeText(url); + }); +} else { + document.querySelectorAll(".filelist tbody td.name button.copy").forEach(function(el) { el.remove() }) +} + diff --git a/caricari/templates/list.html b/caricari/templates/list.html index 08f7cae..138f620 100644 --- a/caricari/templates/list.html +++ b/caricari/templates/list.html @@ -22,32 +22,5 @@ {% endfor %} - + {% endblock body %}