blob: 1a09e74fc77ddfddf0fa514fc3da9200297921fd [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
29 current.html(prefix + " " + current.html());
30 for(var l = levelTag; l < 2; ++l){
31 indices[l] = 0;
32 }
33
34 if(cur_id == undefined) {
35 current.attr('id', 'title' + i);
36 current.addClass('anchor');
37 toc.append("<li class='level" + levelTag + "'><a id='link" + i + "' href='#title" +
38 i + "' title='" + current.prop("tagName") + "'>" + current.text() + "</a></li>");
39 } else {
40 toc.append("<li class='level" + levelTag + "'><a id='" + cur_id + "' href='#title" +
41 i + "' title='" + current.prop("tagName") + "'>" + current.text() + "</a></li>");
42 }
43 });
44 resizeHeight();
45 }
46}
47
48
49var global_navtree_object;
50
51// Overloaded to remove links to sections/subsections
52function getNode(o, po)
53{
54 po.childrenVisited = true;
55 var l = po.childrenData.length-1;
56 for (var i in po.childrenData) {
57 var nodeData = po.childrenData[i];
58 if((!nodeData[1]) || (nodeData[1].indexOf('#')==-1)) // <- we added this line
59 po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2], i==l);
60 }
61}
62
63// Overloaded to adjust the size of the navtree wrt the toc
64function resizeHeight()
65{
66 var toc = $("#nav-toc");
67 var tocHeight = toc.height(); // <- we added this line
68 var headerHeight = header.height();
69 var footerHeight = footer.height();
70 var windowHeight = $(window).height() - headerHeight - footerHeight;
71 content.css({height:windowHeight + "px"});
72 navtree.css({height:(windowHeight-tocHeight) + "px"}); // <- we modified this line
73 sidenav.css({height:(windowHeight) + "px",top: headerHeight+"px"});
74}
75
76// Overloaded to save the root node into global_navtree_object
77function initNavTree(toroot,relpath)
78{
79 var o = new Object();
80 global_navtree_object = o; // <- we added this line
81 o.toroot = toroot;
82 o.node = new Object();
83 o.node.li = document.getElementById("nav-tree-contents");
84 o.node.childrenData = NAVTREE;
85 o.node.children = new Array();
86 o.node.childrenUL = document.createElement("ul");
87 o.node.getChildrenUL = function() { return o.node.childrenUL; };
88 o.node.li.appendChild(o.node.childrenUL);
89 o.node.depth = 0;
90 o.node.relpath = relpath;
91 o.node.expanded = false;
92 o.node.isLast = true;
93 o.node.plus_img = document.createElement("img");
94 o.node.plus_img.src = relpath+"ftv2pnode.png";
95 o.node.plus_img.width = 16;
96 o.node.plus_img.height = 22;
97
98 navTo(o,toroot,window.location.hash,relpath);
99
100 $(window).bind('hashchange', function(){
101 if (window.location.hash && window.location.hash.length>1){
102 var a;
103 if ($(location).attr('hash')){
104 var clslink=stripPath($(location).attr('pathname'))+':'+
105 $(location).attr('hash').substring(1);
106 a=$('.item a[class$="'+clslink+'"]');
107 }
108 if (a==null || !$(a).parent().parent().hasClass('selected')){
109 $('.item').removeClass('selected');
110 $('.item').removeAttr('id');
111 }
112 var link=stripPath2($(location).attr('pathname'));
113 navTo(o,link,$(location).attr('hash'),relpath);
114 }
115 })
116
117 $(window).load(showRoot);
118}
119
120// return false if the the node has no children at all, or has only section/subsection children
121function checkChildrenData(node) {
122 if (!(typeof(node.childrenData)==='string')) {
123 for (var i in node.childrenData) {
124 var url = node.childrenData[i][1];
125 if(url.indexOf("#")==-1)
126 return true;
127 }
128 return false;
129 }
130 return (node.childrenData);
131}
132
133// Modified to:
134// 1 - remove the root node (added && node.parentNode.parentNode.parentNode)
135// 2 - remove the section/subsection children
136function createIndent(o,domNode,node,level)
137{
138 if (node.parentNode && node.parentNode.parentNode
139 && node.parentNode.parentNode.parentNode // <- we added this line
140 ) {
141 createIndent(o,domNode,node.parentNode,level+1);
142 }
143 var imgNode = document.createElement("img");
144 imgNode.width = 16;
145 imgNode.height = 22;
146
147 if (level==0 && checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
148 node.plus_img = imgNode;
149 node.expandToggle = document.createElement("a");
150 node.expandToggle.href = "javascript:void(0)";
151 node.expandToggle.onclick = function() {
152 if (node.expanded) {
153 $(node.getChildrenUL()).slideUp("fast");
154 if (node.isLast) {
155 node.plus_img.src = node.relpath+"ftv2plastnode.png";
156 } else {
157 node.plus_img.src = node.relpath+"ftv2pnode.png";
158 }
159 node.expanded = false;
160 } else {
161 expandNode(o, node, false, false);
162 }
163 }
164 node.expandToggle.appendChild(imgNode);
165 domNode.appendChild(node.expandToggle);
166 } else {
167 domNode.appendChild(imgNode);
168 }
169 if (level==0) {
170 if (node.isLast) {
171 if (checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
172 imgNode.src = node.relpath+"ftv2plastnode.png";
173 } else {
174 imgNode.src = node.relpath+"ftv2lastnode.png";
175 domNode.appendChild(imgNode);
176 }
177 } else {
178 if (checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
179 imgNode.src = node.relpath+"ftv2pnode.png";
180 } else {
181 imgNode.src = node.relpath+"ftv2node.png";
182 domNode.appendChild(imgNode);
183 }
184 }
185 } else {
186 if (node.isLast) {
187 imgNode.src = node.relpath+"ftv2blank.png";
188 } else {
189 imgNode.src = node.relpath+"ftv2vertline.png";
190 }
191 }
192 imgNode.border = "0";
193}
194
195// Overloaded to automatically expand the selected node
196function selectAndHighlight(n)
197{
198 var a;
199 if ($(location).attr('hash')) {
200 var link=stripPath($(location).attr('pathname'))+':'+
201 $(location).attr('hash').substring(1);
202 a=$('.item a[class$="'+link+'"]');
203 }
204 if (a && a.length) {
205 a.parent().parent().addClass('selected');
206 a.parent().parent().attr('id','selected');
207 highlightAnchor();
208 } else if (n) {
209 $(n.itemDiv).addClass('selected');
210 $(n.itemDiv).attr('id','selected');
211 }
212 expandNode(global_navtree_object, n, true, true); // <- we added this line
213 showRoot();
214}
215
216
217$(document).ready(function() {
218
219 generate_autotoc();
220
221 (function (){ // wait until the first "selected" element has been created
222 try {
223
224 // this line will triger an exception if there is no #selected element, i.e., before the tree structure is complete.
225 document.getElementById("selected").className = "item selected";
226
227 // ok, the default tree has been created, we can keep going...
228
229 // expand the "Chapters" node
230 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[2], true, true);
231
232 // Hide the root node "Eigen"
233 $(document.getElementsByClassName('index.html')[0]).parent().parent().css({display:"none"});
234
235 } catch (err) {
236 setTimeout(arguments.callee, 10);
237 }
238 })();
239});