Add JS to linkify in-page H1-H6 (#9751)

This commit is contained in:
Misty Linville
2018-08-18 07:36:42 -07:00
committed by k8s-ci-robot
parent 00cb28927b
commit f8e4d35c5f
2 changed files with 28 additions and 0 deletions
+17
View File
@@ -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
View File
@@ -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;
}