diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-19 22:19:22 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-19 22:19:22 +0200 |
| commit | 08d02a8591ee8047cb708646092cd4bdb7492c33 (patch) | |
| tree | 6b98f8e2d8f98f728394215da57bc9a08de56818 /public/javascripts | |
| parent | 318c0ec9793beba1a6ac0e18168c774fce15dd37 (diff) | |
Add copy-url button to assets; unified the mechanism across views
Diffstat (limited to 'public/javascripts')
| -rw-r--r-- | public/javascripts/admin_interface.js | 21 | ||||
| -rw-r--r-- | public/javascripts/admin_search.js | 6 |
2 files changed, 21 insertions, 6 deletions
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 () { | |||
| 86 | if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); | 86 | if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); |
| 87 | }); | 87 | }); |
| 88 | 88 | ||
| 89 | document.addEventListener('click', function (event) { | ||
| 90 | var button = event.target.closest('.copy_button'); | ||
| 91 | if (!button) return; | ||
| 92 | |||
| 93 | var text = button.dataset.copyUrl; | ||
| 94 | if (text === undefined && button.dataset.copyTarget) { | ||
| 95 | var target = document.querySelector(button.dataset.copyTarget); | ||
| 96 | text = target ? target.textContent : undefined; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (!text || text === '—' || !navigator.clipboard) return; | ||
| 100 | |||
| 101 | navigator.clipboard.writeText(text).then(function () { | ||
| 102 | var label = button.querySelector('.copy_button_label'); | ||
| 103 | if (!label) return; | ||
| 104 | var original = label.textContent; | ||
| 105 | label.textContent = 'Copied!'; | ||
| 106 | setTimeout(function () { label.textContent = original; }, 1500); | ||
| 107 | }); | ||
| 108 | }); | ||
| 109 | |||
| 89 | }); | 110 | }); |
| 90 | 111 | ||
| 91 | 112 | ||
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index b53c931..ad368cb 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js | |||
| @@ -202,12 +202,6 @@ parent_search = { | |||
| 202 | $("#title").bind("input", function() { | 202 | $("#title").bind("input", function() { |
| 203 | parent_search.update_resulting_path(); | 203 | parent_search.update_resulting_path(); |
| 204 | }); | 204 | }); |
| 205 | |||
| 206 | $("#copy_resulting_path").bind("click", function() { | ||
| 207 | var path = $("#resulting_path").text(); | ||
| 208 | if (path === "—" || !navigator.clipboard) return; | ||
| 209 | navigator.clipboard.writeText(path); | ||
| 210 | }); | ||
| 211 | }, | 205 | }, |
| 212 | 206 | ||
| 213 | update_resulting_path : function() { | 207 | update_resulting_path : function() { |
