mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-04-02 07:01:59 -04:00
updated js to copy clicked link text. Also don't need id tags any more.
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t(:field_vin) %></th>
|
<th><%= t(:field_vin) %></th>
|
||||||
<td id="vin">
|
<td>
|
||||||
<a href="#" onclick="handleCopy(event)"><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></a>
|
<a href="#" onclick="handleCopy(event)"><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="label-sub">
|
<div class="label-sub">
|
||||||
<%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b>
|
<a href="#" onclick="handleCopy(event)"><%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
async function handleCopy(event) {
|
async function handleCopy(event) {
|
||||||
console.log("Copy link clicked");
|
console.log("Copy link clicked");
|
||||||
|
|
||||||
// 1. Prevent the link from actually navigating
|
// 1. Prevent the link from actually navigating
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// 2. Grab the text from our span
|
let text;
|
||||||
const text = document.getElementById('vin').innerText;
|
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 {
|
try {
|
||||||
// 3. Write to clipboard
|
// 3. Write to clipboard
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(text);
|
||||||
|
|
||||||
// 4. Update the UI to show it worked
|
// 4. Update the UI to show it worked
|
||||||
const link = event.target;
|
|
||||||
const originalText = link.innerText;
|
const originalText = link.innerText;
|
||||||
link.innerHTML = "<b>Copied!</b>";
|
link.innerHTML = "<b>Copied!</b>";
|
||||||
link.style.color = "#4CAF50"; // Turn green
|
link.style.color = "#4CAF50"; // Turn green
|
||||||
|
|||||||
Reference in New Issue
Block a user