mirror of
https://github.com/ekmas/cs16.css
synced 2026-04-10 21:53:24 +00:00
added js for code blocks
This commit is contained in:
parent
b3fcced804
commit
30d135b352
1 changed files with 27 additions and 1 deletions
28
src/main.js
28
src/main.js
|
|
@ -1 +1,27 @@
|
||||||
import "./cs16.css";
|
document.querySelectorAll(".toggle-vision").forEach((button) => {
|
||||||
|
button.addEventListener("click", function () {
|
||||||
|
const codeBlock = this.closest(".code-block").querySelector(".inner");
|
||||||
|
codeBlock.classList.toggle("hidden");
|
||||||
|
this.textContent = codeBlock.classList.contains("hidden")
|
||||||
|
? "Show code"
|
||||||
|
: "Hide code";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll(".inner .cs-btn").forEach((button) => {
|
||||||
|
button.addEventListener("click", function () {
|
||||||
|
const codeElement = this.closest(".inner").querySelector("code");
|
||||||
|
const codeToCopy = codeElement.textContent;
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(codeToCopy)
|
||||||
|
.then(() => {
|
||||||
|
this.textContent = "Copied!";
|
||||||
|
setTimeout(() => {
|
||||||
|
this.textContent = "Copy";
|
||||||
|
}, 2000);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error("Failed to copy code: ", err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue