You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
7.7 KiB

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