From 96d5ad5ff163714b2a67097c6f0a19ddb54e6dc3 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Mon, 16 Aug 2021 09:22:51 -0400 Subject: [PATCH] slightly faster attachment of clipboard.js to DOM --- assets/js/src/clipboard.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/assets/js/src/clipboard.js b/assets/js/src/clipboard.js index 10f7cc34..4720cb50 100644 --- a/assets/js/src/clipboard.js +++ b/assets/js/src/clipboard.js @@ -14,25 +14,25 @@ if (ClipboardJS.isSupported()) { // insert button as a sibling to Hugo's code fence highlightDiv.insertBefore(button, highlightDiv.firstChild); + }); - new ClipboardJS(button, { - text: (trigger) => { - // actual code element will (should) have class "language-*", even if plaintext - const fenceElement = trigger.parentElement.querySelector('code[class^="language-"]'); // eslint-disable-line quotes + new ClipboardJS("button.copy-button", { + text: (trigger) => { + // actual code element will (should) have class "language-*", even if plaintext + const fenceElement = trigger.parentElement.querySelector('code[class^="language-"]'); // eslint-disable-line quotes - return fenceElement ? trimNewlines(fenceElement.innerText) : false; - }, - }).on("success", (e) => { - // show a subtle indication of success - e.trigger.innerText = "✓"; + return fenceElement ? trimNewlines(fenceElement.innerText) : false; + }, + }).on("success", (e) => { + // show a subtle indication of success + e.trigger.innerText = "✓"; - // reset button to original text after 2 seconds - setTimeout(() => { - e.trigger.innerText = copyTerm; - }, 2000); + // reset button to original text after 2 seconds + setTimeout(() => { + e.trigger.innerText = copyTerm; + }, 2000); - // text needed to be auto-selected to copy, unselect immediately - e.clearSelection(); - }); + // text needed to be auto-selected to copy, unselect immediately + e.clearSelection(); }); }