blob: 39c59f73c944d43e205b485338413790a8621f9c [file] [log] [blame]
Gael Guennebaud93ee82b2013-01-05 16:37:11 +01001
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
Gael Guennebauda3b94d22013-01-12 20:34:52 +010029 // Uncomment to add number prefixes
30 // current.html(prefix + " " + current.html());
Gael Guennebaud93ee82b2013-01-05 16:37:11 +010031 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{
67 var toc = $("#nav-toc");
Gael Guennebaud9c8decf2018-04-11 11:30:14 +020068 var header = $("#header");
69 var content = $("#doc-content");
70 var navtree = $("#nav-path");
71 var sidenav = $("#side-nav");
Gael Guennebaud93ee82b2013-01-05 16:37:11 +010072 var tocHeight = toc.height(); // <- we added this line
73 var headerHeight = header.height();
74 var footerHeight = footer.height();
75 var windowHeight = $(window).height() - headerHeight - footerHeight;
76 content.css({height:windowHeight + "px"});
77 navtree.css({height:(windowHeight-tocHeight) + "px"}); // <- we modified this line
78 sidenav.css({height:(windowHeight) + "px",top: headerHeight+"px"});
79}
80
81// Overloaded to save the root node into global_navtree_object
82function initNavTree(toroot,relpath)
83{
84 var o = new Object();
85 global_navtree_object = o; // <- we added this line
86 o.toroot = toroot;
87 o.node = new Object();
88 o.node.li = document.getElementById("nav-tree-contents");
89 o.node.childrenData = NAVTREE;
90 o.node.children = new Array();
91 o.node.childrenUL = document.createElement("ul");
92 o.node.getChildrenUL = function() { return o.node.childrenUL; };
93 o.node.li.appendChild(o.node.childrenUL);
94 o.node.depth = 0;
95 o.node.relpath = relpath;
96 o.node.expanded = false;
97 o.node.isLast = true;
98 o.node.plus_img = document.createElement("img");
99 o.node.plus_img.src = relpath+"ftv2pnode.png";
100 o.node.plus_img.width = 16;
101 o.node.plus_img.height = 22;
102
Gael Guennebauddcc17542013-01-09 00:40:48 +0100103 if (localStorageSupported()) {
104 var navSync = $('#nav-sync');
105 if (cachedLink()) {
106 showSyncOff(navSync,relpath);
107 navSync.removeClass('sync');
108 } else {
109 showSyncOn(navSync,relpath);
110 }
111 navSync.click(function(){ toggleSyncButton(relpath); });
112 }
113
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100114 navTo(o,toroot,window.location.hash,relpath);
115
116 $(window).bind('hashchange', function(){
117 if (window.location.hash && window.location.hash.length>1){
118 var a;
119 if ($(location).attr('hash')){
120 var clslink=stripPath($(location).attr('pathname'))+':'+
121 $(location).attr('hash').substring(1);
122 a=$('.item a[class$="'+clslink+'"]');
123 }
124 if (a==null || !$(a).parent().parent().hasClass('selected')){
125 $('.item').removeClass('selected');
126 $('.item').removeAttr('id');
127 }
128 var link=stripPath2($(location).attr('pathname'));
129 navTo(o,link,$(location).attr('hash'),relpath);
Gael Guennebauddcc17542013-01-09 00:40:48 +0100130 } else if (!animationInProgress) {
131 $('#doc-content').scrollTop(0);
132 $('.item').removeClass('selected');
133 $('.item').removeAttr('id');
134 navTo(o,toroot,window.location.hash,relpath);
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100135 }
136 })
137
138 $(window).load(showRoot);
139}
140
141// return false if the the node has no children at all, or has only section/subsection children
142function checkChildrenData(node) {
143 if (!(typeof(node.childrenData)==='string')) {
144 for (var i in node.childrenData) {
145 var url = node.childrenData[i][1];
146 if(url.indexOf("#")==-1)
147 return true;
148 }
149 return false;
150 }
151 return (node.childrenData);
152}
153
154// Modified to:
Gael Guennebauddcc17542013-01-09 00:40:48 +0100155// 1 - remove the root node
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100156// 2 - remove the section/subsection children
157function createIndent(o,domNode,node,level)
158{
Gael Guennebauddcc17542013-01-09 00:40:48 +0100159 var level=-2; // <- we replaced level=-1 by level=-2
160 var n = node;
161 while (n.parentNode) { level++; n=n.parentNode; }
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100162 var imgNode = document.createElement("img");
Gael Guennebauddcc17542013-01-09 00:40:48 +0100163 imgNode.style.paddingLeft=(16*(level)).toString()+'px';
164 imgNode.width = 16;
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100165 imgNode.height = 22;
Gael Guennebauddcc17542013-01-09 00:40:48 +0100166 imgNode.border = 0;
167 if (checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100168 node.plus_img = imgNode;
169 node.expandToggle = document.createElement("a");
170 node.expandToggle.href = "javascript:void(0)";
171 node.expandToggle.onclick = function() {
172 if (node.expanded) {
173 $(node.getChildrenUL()).slideUp("fast");
Gael Guennebauddcc17542013-01-09 00:40:48 +0100174 node.plus_img.src = node.relpath+"ftv2pnode.png";
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100175 node.expanded = false;
176 } else {
177 expandNode(o, node, false, false);
178 }
179 }
180 node.expandToggle.appendChild(imgNode);
181 domNode.appendChild(node.expandToggle);
Gael Guennebauddcc17542013-01-09 00:40:48 +0100182 imgNode.src = node.relpath+"ftv2pnode.png";
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100183 } else {
Gael Guennebauddcc17542013-01-09 00:40:48 +0100184 imgNode.src = node.relpath+"ftv2node.png";
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100185 domNode.appendChild(imgNode);
Gael Guennebauddcc17542013-01-09 00:40:48 +0100186 }
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100187}
188
189// Overloaded to automatically expand the selected node
Gael Guennebauddcc17542013-01-09 00:40:48 +0100190function selectAndHighlight(hash,n)
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100191{
192 var a;
Gael Guennebauddcc17542013-01-09 00:40:48 +0100193 if (hash) {
194 var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100195 a=$('.item a[class$="'+link+'"]');
196 }
197 if (a && a.length) {
198 a.parent().parent().addClass('selected');
199 a.parent().parent().attr('id','selected');
200 highlightAnchor();
201 } else if (n) {
202 $(n.itemDiv).addClass('selected');
203 $(n.itemDiv).attr('id','selected');
204 }
Gael Guennebauddcc17542013-01-09 00:40:48 +0100205 if ($('#nav-tree-contents .item:first').hasClass('selected')) {
206 $('#nav-sync').css('top','30px');
207 } else {
208 $('#nav-sync').css('top','5px');
209 }
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100210 expandNode(global_navtree_object, n, true, true); // <- we added this line
211 showRoot();
212}
213
214
215$(document).ready(function() {
216
217 generate_autotoc();
218
219 (function (){ // wait until the first "selected" element has been created
220 try {
221
222 // this line will triger an exception if there is no #selected element, i.e., before the tree structure is complete.
223 document.getElementById("selected").className = "item selected";
224
225 // ok, the default tree has been created, we can keep going...
226
227 // expand the "Chapters" node
Gael Guennebaudcc444bb2013-01-11 10:41:26 +0100228 if(window.location.href.indexOf('unsupported')==-1)
229 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[2], true, true);
230 else
231 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[1], true, true);
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100232
233 // Hide the root node "Eigen"
234 $(document.getElementsByClassName('index.html')[0]).parent().parent().css({display:"none"});
235
236 } catch (err) {
237 setTimeout(arguments.callee, 10);
238 }
239 })();
240});
Gael Guennebauddcc17542013-01-09 00:40:48 +0100241
242$(window).load(function() {
243 resizeHeight();
244});