From 660125c75c6e9cb1a36a3a181072205bf7304670 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Tue, 30 Jul 2024 11:25:30 -0700 Subject: [PATCH 1/2] fix "click to copy" not copying content Signed-off-by: Matthew Fisher --- assets/js/click-to-copy.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/js/click-to-copy.js b/assets/js/click-to-copy.js index ebca6b6e..d41c10a3 100644 --- a/assets/js/click-to-copy.js +++ b/assets/js/click-to-copy.js @@ -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 @@ -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(); }; @@ -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'); -}; \ No newline at end of file From 8c2d3970174706623272c550a3e3a15a14bf6940 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Tue, 30 Jul 2024 11:33:01 -0700 Subject: [PATCH 2/2] add only if plausibleClass is truthy Signed-off-by: Matthew Fisher --- assets/js/click-to-copy.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/js/click-to-copy.js b/assets/js/click-to-copy.js index d41c10a3..c9963255 100644 --- a/assets/js/click-to-copy.js +++ b/assets/js/click-to-copy.js @@ -27,9 +27,13 @@ for (let index = 0; index < codeListings.length; index++) { 'btn', 'btn-dark', 'btn-sm', - 'td-click-to-copy', - plausibleClass ? `plausible-event-name=${plausibleClass}` : "" + 'td-click-to-copy' ); + + if (plausibleClass) { + copyButton.classList.add(`plausible-event-name=${plausibleClass}`); + } + const tooltip = new bootstrap.Tooltip(copyButton); copyButton.onclick = () => {