-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make docs nav sidebar sticky, add on-page nav
- Loading branch information
1 parent
3c8a53a
commit b666395
Showing
4 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
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
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,58 @@ | ||
(function() { | ||
var headings = []; | ||
var current; | ||
|
||
Array.prototype.slice | ||
.call(document.querySelectorAll("article h2, article h3")) | ||
.forEach(function(heading) { | ||
var anchor = heading.querySelector("a.hash-link"); | ||
if (!anchor) return; | ||
|
||
var id = anchor.getAttribute("href"); | ||
var isSubHeading = heading.tagName.toUpperCase() !== "H2"; | ||
|
||
var value = { | ||
id: id, | ||
text: heading.textContent, | ||
children: [], | ||
}; | ||
|
||
if (!isSubHeading) { | ||
headings.push(value); | ||
current = value; | ||
} else { | ||
current && current.children.push(value); | ||
} | ||
}); | ||
|
||
function renderHeadings(headings) { | ||
var template = ""; | ||
|
||
headings.forEach(function(heading) { | ||
template += '<li><a href="' + heading.id + '">' + heading.text + "</a>"; | ||
|
||
if (heading.children.length) { | ||
template += "<ul>"; | ||
template += renderHeadings(heading.children); | ||
template += "</ul>"; | ||
} | ||
|
||
navContent += "</li>"; | ||
}, this); | ||
|
||
return template; | ||
} | ||
|
||
var navContent = renderHeadings(headings); | ||
|
||
var pageNav = this.document.createElement("div"); | ||
pageNav.className = "pageNav"; | ||
pageNav.innerHTML = "<ul>" + navContent + "</ul>"; | ||
|
||
document.querySelector(".docMainWrapper").appendChild(pageNav); | ||
|
||
var elements = document.querySelectorAll( | ||
".sideNavVisible .docsNavContainer, .pageNav" | ||
); | ||
Stickyfill.add(elements); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.