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