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