From 08d02a8591ee8047cb708646092cd4bdb7492c33 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 19 Jul 2026 22:19:22 +0200 Subject: Add copy-url button to assets; unified the mechanism across views --- public/javascripts/admin_interface.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'public/javascripts/admin_interface.js') diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index b7bdc10..e9f96c2 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js @@ -86,6 +86,27 @@ $(document).ready(function () { if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); }); + document.addEventListener('click', function (event) { + var button = event.target.closest('.copy_button'); + if (!button) return; + + var text = button.dataset.copyUrl; + if (text === undefined && button.dataset.copyTarget) { + var target = document.querySelector(button.dataset.copyTarget); + text = target ? target.textContent : undefined; + } + + if (!text || text === '—' || !navigator.clipboard) return; + + navigator.clipboard.writeText(text).then(function () { + var label = button.querySelector('.copy_button_label'); + if (!label) return; + var original = label.textContent; + label.textContent = 'Copied!'; + setTimeout(function () { label.textContent = original; }, 1500); + }); + }); + }); -- cgit v1.3