mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-02-14 09:43:59 -05:00
added js to copy vin on click
This commit is contained in:
28
assets/javascripts/copy.js
Normal file
28
assets/javascripts/copy.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
|
||||
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.innerText = "Copied!";
|
||||
link.style.color = "#4CAF50"; // Turn green
|
||||
|
||||
// 5. Reset after 2 seconds
|
||||
setTimeout(() => {
|
||||
link.innerText = originalText;
|
||||
link.style.color = "";
|
||||
}, 2000);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Unable to copy', err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user