From ed38584ab20ff062775dcc257ab28c9f300fe54d Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 16 Feb 2026 21:32:00 -0500 Subject: [PATCH] updated js to copy clicked link text. Also don't need id tags any more. --- app/views/vehicles/_details.html.erb | 2 +- app/views/vehicles/_list.html.erb | 2 +- assets/javascripts/copy.js | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/vehicles/_details.html.erb b/app/views/vehicles/_details.html.erb index 097a6f4..cc0c538 100644 --- a/app/views/vehicles/_details.html.erb +++ b/app/views/vehicles/_details.html.erb @@ -18,7 +18,7 @@ <%= t(:field_vin) %> - + <%= @vin[0] if @vin %><%=@vin[1] if @vin%> diff --git a/app/views/vehicles/_list.html.erb b/app/views/vehicles/_list.html.erb index f8ce393..096e6a1 100644 --- a/app/views/vehicles/_list.html.erb +++ b/app/views/vehicles/_list.html.erb @@ -12,7 +12,7 @@
- <%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%> + <%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%>
diff --git a/assets/javascripts/copy.js b/assets/javascripts/copy.js index 4329800..adf0bf3 100644 --- a/assets/javascripts/copy.js +++ b/assets/javascripts/copy.js @@ -1,17 +1,25 @@ async function handleCopy(event) { console.log("Copy link clicked"); + // 1. Prevent the link from actually navigating event.preventDefault(); - - // 2. Grab the text from our span - const text = document.getElementById('vin').innerText; + + let text; + let link; + // 2. Grab the text from our clicked link + if(event.target.tagName.toLowerCase() === 'b'){ + text = event.target.parentElement.innerText; + link = event.target.parentElement; + } else { + text = event.target.innerText; + link = event.target; + } try { // 3. Write to clipboard await navigator.clipboard.writeText(text); // 4. Update the UI to show it worked - const link = event.target; const originalText = link.innerText; link.innerHTML = "Copied!"; link.style.color = "#4CAF50"; // Turn green