Skip to content

Commit

Permalink
in-page TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
scotty committed Feb 11, 2016
1 parent 36718f6 commit ee34d01
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 865 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.DS_Store

_includes/.DS_Store

docs.html
4 changes: 2 additions & 2 deletions _layouts/headerfooter.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 rel="stylesheet" href="/css/styles.css"/>
<script src="/js/script.js"></script>
<script src="/js/jquery-2.2.0.min.js"></script>
<script src="/js/non-mini.js"></script>
<!--<script src="/js/jquery-2.2.0.min.js"></script>-->
<!--<script src="/js/non-mini.js"></script>-->
<title>Kubernetes - {{ page.title }}</title>
</head>
<body>
Expand Down
225 changes: 41 additions & 184 deletions css/styles.css

Large diffs are not rendered by default.

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

0 comments on commit ee34d01

Please sign in to comment.