-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b71c94a
commit 8306a1a
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,26 @@ | ||
import ClipboardJS from 'clipboard'; | ||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
// Get all the headers with anchor links | ||
const headers = document.querySelectorAll("a.anchor-header"); | ||
|
||
headers.forEach((header) => { | ||
header.style.cursor = "pointer"; | ||
const clipboard = new ClipboardJS(header, { | ||
text: function(trigger) { | ||
const anchorLink = trigger.getAttribute('href'); | ||
return window.location.href.split('#')[0] + anchorLink; | ||
} | ||
}); | ||
|
||
clipboard.on('success', function(e) { | ||
// Provide user feedback (e.g., alert or tooltip) here | ||
// You can customize the feedback based on your preference | ||
alert("Link copied to clipboard: " + e.text); | ||
}); | ||
|
||
clipboard.on('error', function(e) { | ||
console.error("Unable to copy to clipboard: " + e.text); | ||
}); | ||
}); | ||
}); |