-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copy button to codeblocks on install pages
- Loading branch information
1 parent
f875f6e
commit 8a19b02
Showing
11 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - Arch | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on Arch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - Fedora | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on Fedora | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - FreeBSD | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on FreeBSD | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - macOS | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on macOS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - Nix | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on Nix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - OpenSUSE | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on OpenSUSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - Termux | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on Termux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Install - Ubuntu | ||
js: ["copy-button.js"] | ||
--- | ||
|
||
# Installing Ronin on Ubuntu | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use strict"; | ||
|
||
function initCopyButtons() { | ||
// Make sure browser supports clipboard functionality | ||
if (!window.navigator?.clipboard) { | ||
return; | ||
} | ||
|
||
const codeBlocks = document.querySelectorAll(".highlighter-rouge > .highlight"); | ||
|
||
codeBlocks.forEach((elem) => { | ||
const code = elem.querySelector(".highlight > code"); | ||
if (!code) { | ||
return; | ||
} | ||
|
||
let timeout; | ||
const button = document.createElement("button"); | ||
button.type = "button"; | ||
button.textContent = "Copy to clipboard"; | ||
button.className = "copy-button"; | ||
button.addEventListener("click", async () => { | ||
try { | ||
await window.navigator.clipboard.writeText(code.textContent.trim()); | ||
button.classList.add("copied"); | ||
|
||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
timeout = setTimeout(() => { | ||
button.classList.remove("copied"); | ||
}, 1500); | ||
} catch (error) { | ||
console.error("Failed to copy to clipboard:", error); | ||
} | ||
}); | ||
|
||
elem.insertBefore(button, elem.querySelector(":scope > .highlight")); | ||
}); | ||
} | ||
|
||
(() => { | ||
function ready(callback) { | ||
if (document.readyState != "loading") { | ||
callback(); | ||
} else { | ||
document.addEventListener("DOMContentLoaded", callback); | ||
} | ||
} | ||
|
||
ready(initCopyButtons); | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters