Skip to content

Commit

Permalink
Add JS to linkify in-page H1-H6 (#9751)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misty Linville authored and k8s-ci-robot committed Aug 18, 2018
1 parent 00cb289 commit f8e4d35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions layouts/docs/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,22 @@
</div>
{{ partialCached "footer.html" . }}
{{ partialCached "footer-scripts.html" . }}
<script>
// This script turns in-page headers into clickable and shareable
(function addHeadingLinks(){
var article = document.getElementById('docsContent');
var headings = article.querySelectorAll('h1, h2, h3, h4, h5, h6');
headings.forEach(function(heading){
if(heading.id){
var a = document.createElement('a');
a.text = heading.innerHTML;
a.href = '#'+heading.id;
a.classList.add('inpage_heading');
heading.innerHTML = '';
heading.appendChild(a);
}
});
})();
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions static/css/custom-jekyll/tags.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@
visibility: visible;
opacity: 1;
}

/* In-page section heading permalinks */
a.inpage_heading {
color: #000;
text-decoration: none !important;
}

a.inpage_heading:hover {
text-decoration: underline !important;
opacity: .8;
}

0 comments on commit f8e4d35

Please sign in to comment.