eigen_navtree_hacks.js 7.8 KB

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