blob: 6b021c74904f8559f0823cf2adec00b98480a844 [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
Gael Guennebauddcc17542013-01-09 00:40:48 +010098 if (localStorageSupported()) {
99 var navSync = $('#nav-sync');
100 if (cachedLink()) {
101 showSyncOff(navSync,relpath);
102 navSync.removeClass('sync');
103 } else {
104 showSyncOn(navSync,relpath);
105 }
106 navSync.click(function(){ toggleSyncButton(relpath); });
107 }
108
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100109 navTo(o,toroot,window.location.hash,relpath);
110
111 $(window).bind('hashchange', function(){
112 if (window.location.hash && window.location.hash.length>1){
113 var a;
114 if ($(location).attr('hash')){
115 var clslink=stripPath($(location).attr('pathname'))+':'+
116 $(location).attr('hash').substring(1);
117 a=$('.item a[class$="'+clslink+'"]');
118 }
119 if (a==null || !$(a).parent().parent().hasClass('selected')){
120 $('.item').removeClass('selected');
121 $('.item').removeAttr('id');
122 }
123 var link=stripPath2($(location).attr('pathname'));
124 navTo(o,link,$(location).attr('hash'),relpath);
Gael Guennebauddcc17542013-01-09 00:40:48 +0100125 } else if (!animationInProgress) {
126 $('#doc-content').scrollTop(0);
127 $('.item').removeClass('selected');
128 $('.item').removeAttr('id');
129 navTo(o,toroot,window.location.hash,relpath);
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100130 }
131 })
132
133 $(window).load(showRoot);
134}
135
136// return false if the the node has no children at all, or has only section/subsection children
137function checkChildrenData(node) {
138 if (!(typeof(node.childrenData)==='string')) {
139 for (var i in node.childrenData) {
140 var url = node.childrenData[i][1];
141 if(url.indexOf("#")==-1)
142 return true;
143 }
144 return false;
145 }
146 return (node.childrenData);
147}
148
149// Modified to:
Gael Guennebauddcc17542013-01-09 00:40:48 +0100150// 1 - remove the root node
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100151// 2 - remove the section/subsection children
152function createIndent(o,domNode,node,level)
153{
Gael Guennebauddcc17542013-01-09 00:40:48 +0100154 var level=-2; // <- we replaced level=-1 by level=-2
155 var n = node;
156 while (n.parentNode) { level++; n=n.parentNode; }
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100157 var imgNode = document.createElement("img");
Gael Guennebauddcc17542013-01-09 00:40:48 +0100158 imgNode.style.paddingLeft=(16*(level)).toString()+'px';
159 imgNode.width = 16;
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100160 imgNode.height = 22;
Gael Guennebauddcc17542013-01-09 00:40:48 +0100161 imgNode.border = 0;
162 if (checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100163 node.plus_img = imgNode;
164 node.expandToggle = document.createElement("a");
165 node.expandToggle.href = "javascript:void(0)";
166 node.expandToggle.onclick = function() {
167 if (node.expanded) {
168 $(node.getChildrenUL()).slideUp("fast");
Gael Guennebauddcc17542013-01-09 00:40:48 +0100169 node.plus_img.src = node.relpath+"ftv2pnode.png";
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100170 node.expanded = false;
171 } else {
172 expandNode(o, node, false, false);
173 }
174 }
175 node.expandToggle.appendChild(imgNode);
176 domNode.appendChild(node.expandToggle);
Gael Guennebauddcc17542013-01-09 00:40:48 +0100177 imgNode.src = node.relpath+"ftv2pnode.png";
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100178 } else {
Gael Guennebauddcc17542013-01-09 00:40:48 +0100179 imgNode.src = node.relpath+"ftv2node.png";
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100180 domNode.appendChild(imgNode);
Gael Guennebauddcc17542013-01-09 00:40:48 +0100181 }
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100182}
183
184// Overloaded to automatically expand the selected node
Gael Guennebauddcc17542013-01-09 00:40:48 +0100185function selectAndHighlight(hash,n)
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100186{
187 var a;
Gael Guennebauddcc17542013-01-09 00:40:48 +0100188 if (hash) {
189 var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100190 a=$('.item a[class$="'+link+'"]');
191 }
192 if (a && a.length) {
193 a.parent().parent().addClass('selected');
194 a.parent().parent().attr('id','selected');
195 highlightAnchor();
196 } else if (n) {
197 $(n.itemDiv).addClass('selected');
198 $(n.itemDiv).attr('id','selected');
199 }
Gael Guennebauddcc17542013-01-09 00:40:48 +0100200 if ($('#nav-tree-contents .item:first').hasClass('selected')) {
201 $('#nav-sync').css('top','30px');
202 } else {
203 $('#nav-sync').css('top','5px');
204 }
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100205 expandNode(global_navtree_object, n, true, true); // <- we added this line
206 showRoot();
207}
208
209
210$(document).ready(function() {
211
212 generate_autotoc();
213
214 (function (){ // wait until the first "selected" element has been created
215 try {
216
217 // this line will triger an exception if there is no #selected element, i.e., before the tree structure is complete.
218 document.getElementById("selected").className = "item selected";
219
220 // ok, the default tree has been created, we can keep going...
221
222 // expand the "Chapters" node
Gael Guennebaudcc444bb2013-01-11 10:41:26 +0100223 if(window.location.href.indexOf('unsupported')==-1)
224 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[2], true, true);
225 else
226 expandNode(global_navtree_object, global_navtree_object.node.children[0].children[1], true, true);
Gael Guennebaud93ee82b2013-01-05 16:37:11 +0100227
228 // Hide the root node "Eigen"
229 $(document.getElementsByClassName('index.html')[0]).parent().parent().css({display:"none"});
230
231 } catch (err) {
232 setTimeout(arguments.callee, 10);
233 }
234 })();
235});
Gael Guennebauddcc17542013-01-09 00:40:48 +0100236
237$(window).load(function() {
238 resizeHeight();
239});