mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-06-19 15:20:31 +00:00
feat: add anchor link to headers
This commit is contained in:
parent
64f732ec17
commit
b6c8ef14e0
2 changed files with 42 additions and 0 deletions
static/js
|
@ -55,4 +55,31 @@ images.each(function(index){
|
|||
}
|
||||
});
|
||||
|
||||
// Stick the top to the top of the screen when scrolling
|
||||
$("#top-bar").stick_in_parent();
|
||||
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
// Add link button for every
|
||||
var text, clip = new Clipboard('.anchor');
|
||||
$("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){
|
||||
var element = $(this);
|
||||
var url = document.location.origin + document.location.pathname;
|
||||
var link = url + "#"+element[0].id;
|
||||
console.log(link);
|
||||
return " <span class='anchor' data-clipboard-text='"+link+"'>" +
|
||||
"<i class='fa fa-link fa-lg'></i>" +
|
||||
"</span>"
|
||||
;
|
||||
});
|
||||
|
||||
$(".anchor").on('mouseleave', function(e) {
|
||||
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
||||
});
|
||||
|
||||
clip.on('success', function(e) {
|
||||
e.clearSelection();
|
||||
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue