eigen_navtree_hacks.js
Go to the documentation of this file.
1 
2 // generate a table of contents in the side-nav based on the h1/h2 tags of the current page.
3 function 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 
51 var global_navtree_object;
52 
53 // Overloaded to remove links to sections/subsections
54 function 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 /*
66  @licstart The following is the entire license notice for the JavaScript code in this file.
67 
68  The MIT License (MIT)
69 
70  Copyright (C) 1997-2020 by Dimitri van Heesch
71 
72  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
73  and associated documentation files (the "Software"), to deal in the Software without restriction,
74  including without limitation the rights to use, copy, modify, merge, publish, distribute,
75  sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
76  furnished to do so, subject to the following conditions:
77 
78  The above copyright notice and this permission notice shall be included in all copies or
79  substantial portions of the Software.
80 
81  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
82  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
83  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
84  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
85  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
86 
87  @licend The above is the entire license notice for the JavaScript code in this file
88  */
89 // We need to override entire resizable just so we can change the height to account for the TOC.
90 function initResizable()
91 {
92  var cookie_namespace = 'doxygen';
93  var sidenav,navtree,content,header,collapsed,collapsedWidth=0,barWidth=6,desktop_vp=768,titleHeight;
94 
95  function readCookie(cookie)
96  {
97  var myCookie = cookie_namespace+"_"+cookie+"=";
98  if (document.cookie) {
99  var index = document.cookie.indexOf(myCookie);
100  if (index != -1) {
101  var valStart = index + myCookie.length;
102  var valEnd = document.cookie.indexOf(";", valStart);
103  if (valEnd == -1) {
104  valEnd = document.cookie.length;
105  }
106  var val = document.cookie.substring(valStart, valEnd);
107  return val;
108  }
109  }
110  return 0;
111  }
112 
113  function writeCookie(cookie, val, expiration)
114  {
115  if (val==undefined) return;
116  if (expiration == null) {
117  var date = new Date();
118  date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week
119  expiration = date.toGMTString();
120  }
121  document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/";
122  }
123 
124  function resizeWidth()
125  {
126  var windowWidth = $(window).width() + "px";
127  var sidenavWidth = $(sidenav).outerWidth();
128  content.css({marginLeft:parseInt(sidenavWidth)+"px"});
129  writeCookie('width',sidenavWidth-barWidth, null);
130  }
131 
132  function restoreWidth(navWidth)
133  {
134  var windowWidth = $(window).width() + "px";
135  content.css({marginLeft:parseInt(navWidth)+barWidth+"px"});
136  sidenav.css({width:navWidth + "px"});
137  }
138 
139  function resizeHeight()
140  {
141  var headerHeight = header.outerHeight();
142  var footerHeight = footer.outerHeight();
143  var windowHeight = $(window).height() - headerHeight - footerHeight;
144  //==========================================================================
145  // MODIFICATION:
146  // This small section is the only portion modified within initResizable().
147  // The rest is copy-pasted from the doxygen-generated resize.js.
148  //
149  // Adjust nav height to make room for TOC.
150  var toc = $("#nav-toc");
151  var tocHeight = toc.height();
152  var navHeight = windowHeight;
153  // tocHeight is not always defined (e.g. if empty)
154  if (tocHeight) {
155  navHeight = windowHeight - tocHeight;
156  }
157  //==========================================================================
158 
159  content.css({height:windowHeight + "px"});
160  navtree.css({height:navHeight + "px"});
161  sidenav.css({height:windowHeight + "px"});
162 
163  var width=$(window).width();
164  if (width!=collapsedWidth) {
165  if (width<desktop_vp && collapsedWidth>=desktop_vp) {
166  if (!collapsed) {
167  collapseExpand();
168  }
169  } else if (width>desktop_vp && collapsedWidth<desktop_vp) {
170  if (collapsed) {
171  collapseExpand();
172  }
173  }
174  collapsedWidth=width;
175  }
176  if (location.hash.slice(1)) {
177  (document.getElementById(location.hash.slice(1))||document.body).scrollIntoView();
178  }
179  }
180 
181  function collapseExpand()
182  {
183  if (sidenav.width()>0) {
184  restoreWidth(0);
185  collapsed=true;
186  }
187  else {
188  var width = readCookie('width');
189  if (width>200 && width<$(window).width()) { restoreWidth(width); } else { restoreWidth(200); }
190  collapsed=false;
191  }
192  }
193  header = $("#top");
194  sidenav = $("#side-nav");
195  content = $("#doc-content");
196  navtree = $("#nav-tree");
197  footer = $("#nav-path");
198 
199  $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } });
200  $(sidenav).resizable({ minWidth: 0 });
201  $(window).resize(function() { resizeHeight(); });
202  var device = navigator.userAgent.toLowerCase();
203  var touch_device = device.match(/(iphone|ipod|ipad|android)/);
204  if (touch_device) { /* wider split bar for touch only devices */
205  $(sidenav).css({ paddingRight:'20px' });
206  $('.ui-resizable-e').css({ width:'20px' });
207  $('#nav-sync').css({ right:'34px' });
208  barWidth=20;
209  }
210  var width = readCookie('width');
211  if (width) { restoreWidth(width); } else { resizeWidth(); }
212  resizeHeight();
213  var url = location.href;
214  var i=url.indexOf("#");
215  if (i>=0) window.location.hash=url.substr(i);
216  var _preventDefault = function(evt) { evt.preventDefault(); };
217  $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault);
218  $(".ui-resizable-handle").dblclick(collapseExpand);
219  $(window).on('load',resizeHeight);
220 }
221 
222 // Overloaded to save the root node into global_navtree_object
223 function initNavTree(toroot,relpath)
224 {
225  var o = new Object();
226  global_navtree_object = o; // <- we added this line
227  o.toroot = toroot;
228  o.node = new Object();
229  o.node.li = document.getElementById("nav-tree-contents");
230  o.node.childrenData = NAVTREE;
231  o.node.children = new Array();
232  o.node.childrenUL = document.createElement("ul");
233  o.node.getChildrenUL = function() { return o.node.childrenUL; };
234  o.node.li.appendChild(o.node.childrenUL);
235  o.node.depth = 0;
236  o.node.relpath = relpath;
237  o.node.expanded = false;
238  o.node.isLast = true;
239  o.node.plus_img = document.createElement("img");
240  o.node.plus_img.src = relpath+"ftv2pnode.png";
241  o.node.plus_img.width = 16;
242  o.node.plus_img.height = 22;
243 
244  if (localStorageSupported()) {
245  var navSync = $('#nav-sync');
246  if (cachedLink()) {
247  showSyncOff(navSync,relpath);
248  navSync.removeClass('sync');
249  } else {
250  showSyncOn(navSync,relpath);
251  }
252  navSync.click(function(){ toggleSyncButton(relpath); });
253  }
254 
255  navTo(o,toroot,window.location.hash,relpath);
256 
257  $(window).bind('hashchange', function(){
258  if (window.location.hash && window.location.hash.length>1){
259  var a;
260  if ($(location).attr('hash')){
261  var clslink=stripPath($(location).attr('pathname'))+':'+
262  $(location).attr('hash').substring(1);
263  a=$('.item a[class$="'+clslink+'"]');
264  }
265  if (a==null || !$(a).parent().parent().hasClass('selected')){
266  $('.item').removeClass('selected');
267  $('.item').removeAttr('id');
268  }
269  var link=stripPath2($(location).attr('pathname'));
270  navTo(o,link,$(location).attr('hash'),relpath);
271  } else if (!animationInProgress) {
272  $('#doc-content').scrollTop(0);
273  $('.item').removeClass('selected');
274  $('.item').removeAttr('id');
275  navTo(o,toroot,window.location.hash,relpath);
276  }
277  })
278 
279  $(window).on("load", showRoot);
280 }
281 
282 // return false if the the node has no children at all, or has only section/subsection children
283 function checkChildrenData(node) {
284  if (!(typeof(node.childrenData)==='string')) {
285  for (var i in node.childrenData) {
286  var url = node.childrenData[i][1];
287  if(url.indexOf("#")==-1)
288  return true;
289  }
290  return false;
291  }
292  return (node.childrenData);
293 }
294 
295 // Modified to:
296 // 1 - remove the root node
297 // 2 - remove the section/subsection children
298 function createIndent(o,domNode,node,level)
299 {
300  var level=-2; // <- we replaced level=-1 by level=-2
301  var n = node;
302  while (n.parentNode) { level++; n=n.parentNode; }
303  if (checkChildrenData(node)) { // <- we modified this line to use checkChildrenData(node) instead of node.childrenData
304  var imgNode = document.createElement("span");
305  imgNode.className = 'arrow';
306  imgNode.style.paddingLeft=(16*level).toString()+'px';
307  imgNode.innerHTML=arrowRight;
308  node.plus_img = imgNode;
309  node.expandToggle = document.createElement("a");
310  node.expandToggle.href = "javascript:void(0)";
311  node.expandToggle.onclick = function() {
312  if (node.expanded) {
313  $(node.getChildrenUL()).slideUp("fast");
314  node.plus_img.innerHTML=arrowRight;
315  node.expanded = false;
316  } else {
317  expandNode(o, node, false, false);
318  }
319  }
320  node.expandToggle.appendChild(imgNode);
321  domNode.appendChild(node.expandToggle);
322  } else {
323  var span = document.createElement("span");
324  span.className = 'arrow';
325  span.style.width = 16*(level+1)+'px';
326  span.innerHTML = '&#160;';
327  domNode.appendChild(span);
328  }
329 }
330 
331 // Overloaded to automatically expand the selected node
332 function selectAndHighlight(hash,n)
333 {
334  var a;
335  if (hash) {
336  var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);
337  a=$('.item a[class$="'+link+'"]');
338  }
339  if (a && a.length) {
340  a.parent().parent().addClass('selected');
341  a.parent().parent().attr('id','selected');
342  highlightAnchor();
343  } else if (n) {
344  $(n.itemDiv).addClass('selected');
345  $(n.itemDiv).attr('id','selected');
346  }
347  if ($('#nav-tree-contents .item:first').hasClass('selected')) {
348  $('#nav-sync').css('top','30px');
349  } else {
350  $('#nav-sync').css('top','5px');
351  }
352  expandNode(global_navtree_object, n, true, true); // <- we added this line
353  showRoot();
354 }
355 
356 
357 $(document).ready(function() {
358 
359  generate_autotoc();
360 
361  (function (){ // wait until the first "selected" element has been created
362  try {
363 
364  // this line will triger an exception if there is no #selected element, i.e., before the tree structure is complete.
365  document.getElementById("selected").className = "item selected";
366 
367  // ok, the default tree has been created, we can keep going...
368 
369  // expand the "Chapters" node
370  if(window.location.href.indexOf('unsupported')==-1)
371  expandNode(global_navtree_object, global_navtree_object.node.children[0].children[2], true, true);
372  else
373  expandNode(global_navtree_object, global_navtree_object.node.children[0].children[1], true, true);
374 
375  // Hide the root node "Eigen"
376  $(document.getElementsByClassName('index.html')[0]).parent().parent().css({display:"none"});
377 
378  } catch (err) {
379  setTimeout(arguments.callee, 10);
380  }
381  })();
382 });