Format some js

This commit is contained in:
Richard Feldman 2023-11-09 22:20:07 -05:00
parent 365c16880c
commit fb17d89dfc
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B

View file

@ -69,17 +69,17 @@
try{ document.createEvent("TouchEvent"); return true; }
catch(e){ return false; }
}
// Select all <samp> elements that are children of <pre> elements
const codeBlocks = document.querySelectorAll("pre > samp");
// Iterate over each code block
codeBlocks.forEach((codeBlock) => {
// Create a "Copy" button
const copyButton = document.createElement("button");
copyButton.classList.add("copy-button");
copyButton.textContent = "Copy";
// Add event listener to copy button
copyButton.addEventListener("click", () => {
const codeText = codeBlock.innerText;
@ -91,16 +91,16 @@
copyButton.classList.remove('copy-button-copied');
});
});
// Create a container for the copy button and append it to the document
const buttonContainer = document.createElement("div");
buttonContainer.classList.add("button-container");
buttonContainer.appendChild(copyButton);
codeBlock.parentNode.insertBefore(buttonContainer, codeBlock);
// Hide the button container by default
buttonContainer.style.display = "none";
if (isTouchSupported()) {
// Show the button container on click for touch support (e.g. mobile)
document.addEventListener("click", (event) => {
@ -115,10 +115,10 @@
codeBlock.parentNode.addEventListener("mouseenter", () => {
buttonContainer.style.display = "block";
});
codeBlock.parentNode.addEventListener("mouseleave", () => {
buttonContainer.style.display = "none";
});
});
}
});
})();