in-page TOC

This commit is contained in:
scotty 2016-02-11 11:43:55 -08:00
parent 36718f647a
commit ee34d01383
5 changed files with 233 additions and 865 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
.DS_Store .DS_Store
_includes/.DS_Store _includes/.DS_Store
docs.html

View File

@ -6,8 +6,8 @@
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'> <link href='https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/styles.css"/> <link rel="stylesheet" href="/css/styles.css"/>
<script src="/js/script.js"></script> <script src="/js/script.js"></script>
<script src="/js/jquery-2.2.0.min.js"></script> <!--<script src="/js/jquery-2.2.0.min.js"></script>-->
<script src="/js/non-mini.js"></script> <!--<script src="/js/non-mini.js"></script>-->
<title>Kubernetes - {{ page.title }}</title> <title>Kubernetes - {{ page.title }}</title>
</head> </head>
<body> <body>

File diff suppressed because one or more lines are too long

View File

@ -1,46 +1,46 @@
// credit to: http://jsfiddle.net/s8m2t/8/ //// credit to: http://jsfiddle.net/s8m2t/8/
var buildRec; //var buildRec;
buildRec = function(headingNodes, $elm, lv) { //buildRec = function(headingNodes, $elm, lv) {
var cnt, curLv, li, node; // var cnt, curLv, li, node;
node = headingNodes.splice(0, 1); // node = headingNodes.splice(0, 1);
if (node && node.length > 0) { // if (node && node.length > 0) {
curLv = parseInt(node[0].tagName.substring(1)); // curLv = parseInt(node[0].tagName.substring(1));
if (curLv === lv) { // if (curLv === lv) {
cnt = 0; // cnt = 0;
} else if (curLv < lv) { // } else if (curLv < lv) {
cnt = 0; // cnt = 0;
while (true) { // while (true) {
$elm = $elm.parent().parent(); // $elm = $elm.parent().parent();
cnt--; // cnt--;
if (!(cnt > (curLv - lv))) { // if (!(cnt > (curLv - lv))) {
break; // break;
} // }
} // }
} else if (curLv > lv) { // } else if (curLv > lv) {
cnt = 0; // cnt = 0;
while (true) { // while (true) {
li = $elm.children().last(); // li = $elm.children().last();
if (!($elm.children().last().length > 0)) { // if (!($elm.children().last().length > 0)) {
$elm.append($("<li>")); // $elm.append($("<li>"));
li = $elm.children().last(); // li = $elm.children().last();
} // }
li.append($('<ul style="list-style-type: none;">')); // li.append($('<ul style="list-style-type: none;">'));
$elm = li.children().last(); // $elm = li.children().last();
cnt++; // cnt++;
if (!(cnt < (curLv - lv))) { // if (!(cnt < (curLv - lv))) {
break; // break;
} // }
} // }
} // }
$elm.append($("<li>")); // $elm.append($("<li>"));
li = $elm.children().last(); // li = $elm.children().last();
li.html("<a href=#" + node[0].id + ">" + node[0].innerHTML + "</a>"); // li.html("<a href=#" + node[0].id + ">" + node[0].innerHTML + "</a>");
return buildRec(headingNodes, $elm, lv + cnt); // return buildRec(headingNodes, $elm, lv + cnt);
} // }
}; //};
$(document).ready(function(){ //$(document).ready(function(){
var headingNodes = $('#docsContent').children().filter(":header"); // var headingNodes = $('#docsContent').children().filter(":header");
var result = $('<ul style="list-style-type: none; padding-left:0px;">'); // var result = $('<ul style="list-style-type: none; padding-left:0px;">');
buildRec(headingNodes,result,1); // buildRec(headingNodes,result,1);
$("#pageTOC").append(result); // $("#pageTOC").append(result);
}); //});

File diff suppressed because one or more lines are too long