blob: a6f8c34282124d2043e567b2ba375f4af11318fc [file] [log] [blame]
Brian Silverman72890c22015-09-19 14:37:37 -04001
2// generate a table of contents in the side-nav based on the h1/h2 tags of the current page.
3function generate_autotoc() {
4 var headers = $("h1, h2");
5 if(headers.length > 1) {
6 var toc = $("#side-nav").append('<div id="nav-toc" class="toc"><h3>Table of contents</h3></div>');
7 toc = $("#nav-toc");
8 var footerHeight = footer.height();
9 toc = toc.append('<ul></ul>');
10 toc = toc.find('ul');
11 var indices = new Array();
12 indices[0] = 0;
13 indices[1] = 0;
14
15 var h1counts = $("h1").length;
16 headers.each(function(i) {
17 var current = $(this);
18 var levelTag = current[0].tagName.charAt(1);
19 if(h1counts==0)
20 levelTag--;
21 var cur_id = current.attr("id");
22
23 indices[levelTag-1]+=1;
24 var prefix = indices[0];
25 if (levelTag >1) {
26 prefix+="."+indices[1];
27 }
28
29 // Uncomment to add number prefixes
30 // current.html(prefix + " " + current.html());
31 for(var l = levelTag; l < 2; ++l){
32 indices[l] = 0;
33 }
34
35 if(cur_id == undefined) {
36 current.attr('id', 'title' + i);
37 current.addClass('anchor');
38 toc.append("<li class='level" + levelTag + "'><a id='link" + i + "' href='#title" +
39 i + "' title='" + current.prop("tagName") + "'>" + current.text() + "</a></li>");
40 } else {
41 toc.append("<li class='level" + levelTag + "'><a id='" + cur_id + "' href='#title" +
42 i + "' title='" + current.prop("tagName") + "'>" + current.text() + "</a></li>");
43 }
44 });
45 resizeHeight();
46 }
47}
48
49
50var global_navtree_object;
51
52// Overloaded to remove links to sections/subsections
53function getNode(o, po)
54{
55 po.childrenVisited = true;
56 var l = po.childrenData.length-1;
57 for (var i in po.childrenData) {
58 var nodeData = po.childrenData[i];
59 if((!nodeData[1]) || (nodeData[1].indexOf('#')==-1)) // <- we added this line
60 po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2], i==l);
61 }
62}
63
64// Overloaded to adjust the size of the navtree wrt the toc
65function resizeHeight()
66{
Austin Schuh189376f2018-12-20 22:11:15 +110067 var header = $("#top");
68 var sidenav = $("#side-nav");
69 var content = $("#doc-content");
70 var navtree = $("#nav-tree");
71 var footer = $("#nav-path");
72 var toc = $("#nav-toc");
73
74 var headerHeight = header.outerHeight();
75 var footerHeight = footer.outerHeight();
76 var tocHeight = toc.height();
Brian Silverman72890c22015-09-19 14:37:37 -040077 var windowHeight = $(window).height() - headerHeight - footerHeight;
78 content.css({height:windowHeight + "px"});
Austin Schuh189376f2018-12-20 22:11:15 +110079 navtree.css({height:(windowHeight-tocHeight) + "px"});
80 sidenav.css({height:windowHeight + "px"});
Brian Silverman72890c22015-09-19 14:37:37 -040081}
82
83// Overloaded to save the root node into global_navtree_object
84function initNavTree(toroot,relpath)
85{
86 var o = new Object();
87 global_navtree_object = o; // <- we added this line
88 o.toroot = toroot;
89 o.node = new Object();
90 o.node.li = document.getElementById("nav-tree-contents");
91 o.node.childrenData = NAVTREE;
92 o.node.children = new Array();
93 o.node.childrenUL = document.createElement("ul");
94 o.node.getChildrenUL = function() { return o.node.childrenUL; };
95 o.node.li.appendChild(o.node.childrenUL);
96 o.node.depth = 0;
97 o.node.relpath = relpath;
98 o.node.expanded = false;
99 o.node.isLast = true;
100 o.node.plus_img = document.createElement("img");
101 o.node.plus_img.src = relpath+"ftv2pnode.png";
102 o.node.plus_img.width = 16;
103 o.node.plus_img.height = 22;
104
105 if (localStorageSupported()) {
106 var navSync = $('#nav-sync');
107 if (cachedLink()) {
108 showSyncOff(navSync,relpath);
109 navSync.removeClass('sync');
110 } else {
111 showSyncOn(navSync,relpath);
112 }
113 navSync.click(function(){ toggleSyncButton(relpath); });
114 }
115
116 navTo(o,toroot,window.location.hash,relpath);
117
118 $(window).bind('hashchange', function(){
119 if (window.location.hash && window.location.hash.length>1){
120 var a;
121 if ($(location).attr('hash')){
122 var clslink=stripPath($(location).attr('pathname'))+':'+
123 $(location).attr('hash').substring(1);
124 a=$('.item a[class$="'+clslink+'"]');
125 }
126 if (a==null || !$(a).parent().parent().hasClass('selected')){
127 $('.item').removeClass('selected');
128 $('.item').removeAttr('id');
129 }
130 var link=stripPath2($(location).attr('pathname'));
131 navTo(o,link,$(location).attr('hash'),relpath);
132 } else if (!animationInProgress) {
133 $('#doc-content').scrollTop(0);
134 $('.item').removeClass('selected');
135 $('.item').removeAttr('id');
136 navTo(o,toroot,window.location.hash,relpath);
137 }
138 })
139
140 $(window).load(showRoot);
141}
142
143// return false if the the node has no children at all, or has only section/subsection children
144function checkChildrenData(node) {
145 if (!(typeof(node.childrenData)==='string')) {
146 for (var i in node.childrenData) {
147 var url = node.childrenData[i][1];
148 if(url.indexOf("#")==-1)
149 return true;
150 }
151 return false;
152 }
153 return (node.childrenData);
154}
155
156// Modified to:
157// 1 - remove the root node
158// 2 - remove the section/subsection children
159function createIndent(o,domNode,node,level)
160{
161 var level=-2; // <- we replaced level=-1 by level=-2
162 var n = node;
163 while (n.parentNode) { level++; n=n.parentNode; }
Brian Silverman72890c22015-09-19 14:37:37 -0400164 if (checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
Austin Schuh189376f2018-12-20 22:11:15 +1100165 var imgNode = document.createElement("span");
166 imgNode.className = 'arrow';
167 imgNode.style.paddingLeft=(16*level).toString()+'px';
168 imgNode.innerHTML=arrowRight;
Brian Silverman72890c22015-09-19 14:37:37 -0400169 node.plus_img = imgNode;
170 node.expandToggle = document.createElement("a");
171 node.expandToggle.href = "javascript:void(0)";
172 node.expandToggle.onclick = function() {
173 if (node.expanded) {
174 $(node.getChildrenUL()).slideUp("fast");
Austin Schuh189376f2018-12-20 22:11:15 +1100175 node.plus_img.innerHTML=arrowRight;
Brian Silverman72890c22015-09-19 14:37:37 -0400176 node.expanded = false;
177 } else {
178 expandNode(o, node, false, false);
179 }
180 }
181 node.expandToggle.appendChild(imgNode);
182 domNode.appendChild(node.expandToggle);
Brian Silverman72890c22015-09-19 14:37:37 -0400183 } else {
Austin Schuh189376f2018-12-20 22:11:15 +1100184 var span = document.createElement("span");
185 span.className = 'arrow';
186 span.style.width = 16*(level+1)+'px';
187 span.innerHTML = '&#160;';
188 domNode.appendChild(span);
189 }
Brian Silverman72890c22015-09-19 14:37:37 -0400190}
191
192// Overloaded to automatically expand the selected node
193function selectAndHighlight(hash,n)
194{
195 var a;
196 if (hash) {
197 var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);
198 a=$('.item a[class$="'+link+'"]');
199 }
200 if (a && a.length) {
201 a.parent().parent().addClass('selected');
202 a.parent().parent().attr('id','selected');
203 highlightAnchor();
204 } else if (n) {
205 $(n.itemDiv).addClass('selected');
206 $(n.itemDiv).attr('id','selected');
207 }
208 if ($('#nav-tree-contents .item:first').hasClass('selected')) {
209 $('#nav-sync').css('top','30px');
210 } else {
211 $('#nav-sync').css('top','5px');
212 }
213 expandNode(global_navtree_object, n, true, true); // <- we added this line
214 showRoot();
215}
216
217
218$(document).ready(function() {
219
220 generate_autotoc();
221
222 (function (){ // wait until the first "selected" element has been created
223 try {
224
225 // this line will triger an exception if there is no #selected element, i.e., before the tree structure is complete.
226 document.getElementById("selected").className = "item selected";
227
228 // ok, the default tree has been created, we can keep going...
229
230 // expand the "Chapters" node
231 if(window.location.href.indexOf('unsupported')==-1)
232 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[2], true, true);
233 else
234 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[1], true, true);
235
236 // Hide the root node "Eigen"
237 $(document.getElementsByClassName('index.html')[0]).parent().parent().css({display:"none"});
238
239 } catch (err) {
240 setTimeout(arguments.callee, 10);
241 }
242 })();
Austin Schuh189376f2018-12-20 22:11:15 +1100243
244 $(window).load(resizeHeight);
Brian Silverman72890c22015-09-19 14:37:37 -0400245});
246