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 --- app/views/assets/show.html.erb | 10 +++++++++- app/views/nodes/new.html.erb | 5 ++++- public/javascripts/admin_interface.js | 21 +++++++++++++++++++++ public/javascripts/admin_search.js | 6 ------ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/views/assets/show.html.erb b/app/views/assets/show.html.erb index 5717dd9..ff00883 100644 --- a/app/views/assets/show.html.erb +++ b/app/views/assets/show.html.erb @@ -20,7 +20,15 @@
<%= image_tag @asset.upload.url(:medium), style: "max-width: 300px; max-height: 300px;" %>
Public Path
-
<%= @asset.upload.url.sub(/\?\d+$/, "") %>
+
+ <% public_path = @asset.upload.url.sub(/\?\d+$/, "") %> + <%= link_to public_path, public_path, target: "_blank", rel: "noopener" %> + +
Content Type
<%= @asset.upload.content_type %>
diff --git a/app/views/nodes/new.html.erb b/app/views/nodes/new.html.erb index 890d46e..805fbc9 100644 --- a/app/views/nodes/new.html.erb +++ b/app/views/nodes/new.html.erb @@ -41,7 +41,10 @@
Resulting path
- + + This preview updates as you type. The final path can still be changed afterward by editing the title (for the last segment) or moving the node to a different parent (for everything before it).
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); + }); + }); + }); 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 = { $("#title").bind("input", function() { parent_search.update_resulting_path(); }); - - $("#copy_resulting_path").bind("click", function() { - var path = $("#resulting_path").text(); - if (path === "—" || !navigator.clipboard) return; - navigator.clipboard.writeText(path); - }); }, update_resulting_path : function() { -- cgit v1.3