Skip to content

Commit

Permalink
feature: allowing a copy widget to the code elements
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni committed Jun 14, 2024
1 parent 1fe23e7 commit 2cbeace
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/assets/doco.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ document.addEventListener("DOMContentLoaded", () => {
// Add highligthing to the code blocks
hljs.highlightAll();

document.querySelectorAll("pre").forEach((el) => {
let bt = document.createElement("button");
bt.appendChild(document.createTextNode("content_copy"));
bt.classList.add(
"material-symbols-outlined",
"absolute",
"top-4",
"right-2",
"p-1.5",
"bg-gray-50",
"hover:bg-gray-100",
"rounded",
);

bt.addEventListener("click", () => {
navigator.clipboard.writeText(el.textContent);
});

el.appendChild(bt);
el.classList.add("relative");
});

// Adding the mobile menu toggle
let toggles = document.querySelectorAll(".toggle-mobile-nav");
toggles.forEach((toggle) => {
Expand Down

0 comments on commit 2cbeace

Please sign in to comment.