mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-17 18:40:36 -05:00
VIN click-to-copy: shared snippet, last 8 bold only for 17-char VINs
- New vehicles/_vin partial used on the issue page, vehicle page and vehicle lists (replaces three copies of the markup, inline onclick handlers and a fixed id="copyLink") - 17-character VINs show the last 8 in bold (what dealerships ask for when ordering parts); older or short VINs are shown plain - Copies the VIN from a data attribute, restores the exact display afterwards, shows "Copied!" or "Couldn't copy", falls back when the Clipboard API isn't available, and supports Enter/Space; pointer cursor and "Click to copy" tooltip - The copy script is written into the page by the layout hook instead of served as copy.js, so it can't 404 when Redmine's asset manifest is out of date; one listener handles every VIN on the page - Issue PDFs split 17-character VINs before the last 8; others whole Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
11 files changed
+111
-53
No files matched your search
@@ -1,45 +0,0 @@
|
||||
async function handleCopy(event) {
|
||||
console.log("Copy link clicked");
|
||||
|
||||
let text;
|
||||
let link;
|
||||
// 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;
|
||||
}
|
||||
|
||||
// If the text is already "Copied!", don't do anything
|
||||
if (text == "Copied!") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Write to clipboard
|
||||
await navigator.clipboard.writeText(text);
|
||||
|
||||
// Update the UI to show it worked
|
||||
const originalText = link.innerText;
|
||||
link.innerHTML = "<b>Copied!</b>";
|
||||
link.style.color = "#4CAF50"; // Turn green
|
||||
|
||||
// Reset after 2 seconds
|
||||
setTimeout(() => {
|
||||
// Check if the text is long enough to prevent errors
|
||||
if (originalText.length >= 8) {
|
||||
const firstPart = originalText.slice(0, -8);
|
||||
const lastEight = originalText.slice(-8);
|
||||
link.innerHTML = `${firstPart}<b>${lastEight}</b>`;
|
||||
} else {
|
||||
link.innerText = originalText;
|
||||
}
|
||||
link.style.color = "";
|
||||
}, 2000);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Unable to copy', err);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user