refactor /list JS

This commit is contained in:
boyska 2024-12-07 20:08:34 +01:00
parent 280223df75
commit 6acfd2fc83
2 changed files with 28 additions and 28 deletions

27
caricari/static/list.js Normal file
View file

@ -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() })
}

View file

@ -22,32 +22,5 @@
{% endfor %}
</tbody>
</table>
<script>
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() })
}
</script>
<script src="/static/list.js"></script>
{% endblock body %}