mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 12:01:17 -04:00
Update clipboard.js
This commit is contained in:
@@ -11,20 +11,20 @@ document.querySelectorAll("div.highlight").forEach((highlightDiv) => {
|
|||||||
const button = document.createElement("button");
|
const button = document.createElement("button");
|
||||||
button.className = "copy-button";
|
button.className = "copy-button";
|
||||||
button.textContent = defaultText;
|
button.textContent = defaultText;
|
||||||
button.addEventListener("click", async () => {
|
button.addEventListener("click", () => {
|
||||||
// prevent unintentional double-clicks by unfocusing button
|
// prevent unintentional double-clicks by unfocusing button
|
||||||
button.blur();
|
button.blur();
|
||||||
|
|
||||||
// actual code element will have class "language-*", even if plaintext
|
// actual code element will have class "language-*", even if plaintext
|
||||||
await copy(trimNewlines(highlightDiv.querySelector('code[class^="language-"]').textContent));
|
if (copy(trimNewlines(highlightDiv.querySelector('code[class^="language-"]').textContent))) {
|
||||||
|
// show a subtle indication of success
|
||||||
|
button.textContent = successText;
|
||||||
|
|
||||||
// show a subtle indication of success
|
// reset button to original text after 2 seconds
|
||||||
button.textContent = successText;
|
setTimeout(() => {
|
||||||
|
button.textContent = defaultText;
|
||||||
// reset button to original text after 2 seconds
|
}, 2000);
|
||||||
setTimeout(() => {
|
}
|
||||||
button.textContent = defaultText;
|
|
||||||
}, 2000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// add Hugo's code block to a new wrapper element, and insert the copy button as a sibling to it
|
// add Hugo's code block to a new wrapper element, and insert the copy button as a sibling to it
|
||||||
|
Reference in New Issue
Block a user