Skip to content

Commit

Permalink
fix "click to copy" not copying content
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Fisher <[email protected]>
  • Loading branch information
bacongobbler committed Jul 30, 2024
1 parent a070f37 commit 660125c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions assets/js/click-to-copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
let codeListings = document.querySelectorAll('.highlight > pre');

const copyCode = (codeSample) => {
navigator.clipboard.writeText(codeSample.textContent.trim() + '\n');
};

for (let index = 0; index < codeListings.length; index++) {
const parentWrapper = codeListings[index].parentElement
const plausibleClass = parentWrapper.dataset.plausible
Expand Down Expand Up @@ -30,7 +34,7 @@ for (let index = 0; index < codeListings.length; index++) {

copyButton.onclick = () => {
copyCode(codeSample);
copyButton.setAttribute('data-bs-original-title', 'Copied');
copyButton.setAttribute('data-bs-original-title', 'Copied!');
tooltip.show();
};

Expand All @@ -44,7 +48,3 @@ for (let index = 0; index < codeListings.length; index++) {
buttonDiv.append(copyButton);
codeListings[index].insertBefore(buttonDiv, codeSample);
}

const copyCode = (codeSample) => {
navigator.clipboard.writeText(codeSample.textContent.trim() + '\n');
};

0 comments on commit 660125c

Please sign in to comment.