Skip to content

Commit

Permalink
Rewrite heading permalink code to use vanilla JS
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Feb 7, 2021
1 parent 215f73f commit 116e29a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions assets/js/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ $(document).ready(function() {
});

// Add anchors for headings
$('.page__content').find('h1, h2, h3, h4, h5, h6').each(function() {
var id = $(this).attr('id');
document.querySelector('.page__content').querySelectorAll('h1, h2, h3, h4, h5, h6').forEach(function(element) {
var id = element.getAttribute('id');
if (id) {
var anchor = document.createElement("a");
anchor.className = 'header-link';
anchor.href = '#' + id;
anchor.innerHTML = '<span class=\"sr-only\">Permalink</span><i class=\"fas fa-link\"></i>';
anchor.title = "Permalink";
$(this).append(anchor);
element.appendChild(anchor);
}
});

Expand Down
2 changes: 1 addition & 1 deletion assets/js/main.min.js

Large diffs are not rendered by default.

0 comments on commit 116e29a

Please sign in to comment.