1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt-doc.git synced 2025-04-25 03:57:11 -07:00

Better TOC.

This commit is contained in:
Cedric Beust 2015-12-01 19:50:37 -08:00
parent 0a6d74672c
commit e52dfcc1da
2 changed files with 33 additions and 10 deletions

View file

@ -1,3 +1,17 @@
#table-of-contents {
border: solid 1px #cccccc;
border-radius: 10px;
}
.toc-item {
padding: 2px;
}
.toc-item a:hover {
background: #48D1CC;
display: block;
}
.bs-callout { .bs-callout {
padding: 20px; padding: 20px;
margin: 20px 0; margin: 20px 0;

View file

@ -71,6 +71,14 @@ function generateNavBar(index) {
// Table of contents // Table of contents
// //
function indent(n) {
var result = "";
for (var i = 0; i < n; i++) {
result += "&nbsp;&nbsp;&nbsp;&nbsp;"
}
return result;
}
function generateToc() { function generateToc() {
var sections = document.getElementsByClassName("section"); var sections = document.getElementsByClassName("section");
@ -87,16 +95,17 @@ function generateToc() {
ind = indentAttribute.textContent; ind = indentAttribute.textContent;
} }
if (! ind) ind = 0; if (! ind) ind = 0;
if (ind > currentLevel) { var content = indent(ind) + section.innerHTML;
if (ind == 0) { //if (ind > currentLevel) {
toc += '<ul class="nav">\n'; // if (ind == 0) {
} else { // toc += '<ul class="nav">\n';
toc += '<ul>\n'; // } else {
} // toc += '<ul>\n';
} else if (ind < currentLevel) { // }
toc += '</ul>\n'; //} else if (ind < currentLevel) {
} // toc += '</ul>\n';
toc += '<li><a href="#' + section.id + '">' + section.innerHTML + '</a></li>\n'; //}
toc += '<div class="toc-item"><a href="#' + section.id + '">' + content + '</a></div>\n';
currentLevel = ind; currentLevel = ind;
} }
toc += "</ul>\n"; toc += "</ul>\n";