2
0

navtree.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. @licstart The following is the entire license notice for the JavaScript code in this file.
  3. The MIT License (MIT)
  4. Copyright (C) 1997-2020 by Dimitri van Heesch
  5. Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  6. and associated documentation files (the "Software"), to deal in the Software without restriction,
  7. including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all copies or
  11. substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  13. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. @licend The above is the entire license notice for the JavaScript code in this file
  18. */
  19. var navTreeSubIndices = new Array();
  20. var arrowDown = '▼';
  21. var arrowRight = '►';
  22. function getData(varName)
  23. {
  24. var i = varName.lastIndexOf('/');
  25. var n = i>=0 ? varName.substring(i+1) : varName;
  26. return eval(n.replace(/\-/g,'_'));
  27. }
  28. function stripPath(uri)
  29. {
  30. return uri.substring(uri.lastIndexOf('/')+1);
  31. }
  32. function stripPath2(uri)
  33. {
  34. var i = uri.lastIndexOf('/');
  35. var s = uri.substring(i+1);
  36. var m = uri.substring(0,i+1).match(/\/d\w\/d\w\w\/$/);
  37. return m ? uri.substring(i-6) : s;
  38. }
  39. function hashValue()
  40. {
  41. return $(location).attr('hash').substring(1).replace(/[^\w\-]/g,'');
  42. }
  43. function hashUrl()
  44. {
  45. return '#'+hashValue();
  46. }
  47. function pathName()
  48. {
  49. return $(location).attr('pathname').replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/g, '');
  50. }
  51. function localStorageSupported()
  52. {
  53. try {
  54. return 'localStorage' in window && window['localStorage'] !== null && window.localStorage.getItem;
  55. }
  56. catch(e) {
  57. return false;
  58. }
  59. }
  60. function storeLink(link)
  61. {
  62. if (!$("#nav-sync").hasClass('sync') && localStorageSupported()) {
  63. window.localStorage.setItem('navpath',link);
  64. }
  65. }
  66. function deleteLink()
  67. {
  68. if (localStorageSupported()) {
  69. window.localStorage.setItem('navpath','');
  70. }
  71. }
  72. function cachedLink()
  73. {
  74. if (localStorageSupported()) {
  75. return window.localStorage.getItem('navpath');
  76. } else {
  77. return '';
  78. }
  79. }
  80. function getScript(scriptName,func,show)
  81. {
  82. var head = document.getElementsByTagName("head")[0];
  83. var script = document.createElement('script');
  84. script.id = scriptName;
  85. script.type = 'text/javascript';
  86. script.onload = func;
  87. script.src = scriptName+'.js';
  88. head.appendChild(script);
  89. }
  90. function createIndent(o,domNode,node,level)
  91. {
  92. var level=-1;
  93. var n = node;
  94. while (n.parentNode) { level++; n=n.parentNode; }
  95. if (node.childrenData) {
  96. var imgNode = document.createElement("span");
  97. imgNode.className = 'arrow';
  98. imgNode.style.paddingLeft=(16*level).toString()+'px';
  99. imgNode.innerHTML=arrowRight;
  100. node.plus_img = imgNode;
  101. node.expandToggle = document.createElement("a");
  102. node.expandToggle.href = "javascript:void(0)";
  103. node.expandToggle.onclick = function() {
  104. if (node.expanded) {
  105. $(node.getChildrenUL()).slideUp("fast");
  106. node.plus_img.innerHTML=arrowRight;
  107. node.expanded = false;
  108. } else {
  109. expandNode(o, node, false, false);
  110. }
  111. }
  112. node.expandToggle.appendChild(imgNode);
  113. domNode.appendChild(node.expandToggle);
  114. } else {
  115. var span = document.createElement("span");
  116. span.className = 'arrow';
  117. span.style.width = 16*(level+1)+'px';
  118. span.innerHTML = ' ';
  119. domNode.appendChild(span);
  120. }
  121. }
  122. var animationInProgress = false;
  123. function gotoAnchor(anchor,aname,updateLocation)
  124. {
  125. var pos, docContent = $('#doc-content');
  126. var ancParent = $(anchor.parent());
  127. if (ancParent.hasClass('memItemLeft') ||
  128. ancParent.hasClass('memtitle') ||
  129. ancParent.hasClass('fieldname') ||
  130. ancParent.hasClass('fieldtype') ||
  131. ancParent.is(':header'))
  132. {
  133. pos = ancParent.position().top;
  134. } else if (anchor.position()) {
  135. pos = anchor.position().top;
  136. }
  137. if (pos) {
  138. var dist = Math.abs(Math.min(
  139. pos-docContent.offset().top,
  140. docContent[0].scrollHeight-
  141. docContent.height()-docContent.scrollTop()));
  142. animationInProgress=true;
  143. docContent.animate({
  144. scrollTop: pos + docContent.scrollTop() - docContent.offset().top
  145. },Math.max(50,Math.min(500,dist)),function(){
  146. if (updateLocation) window.location.href=aname;
  147. animationInProgress=false;
  148. });
  149. }
  150. }
  151. function newNode(o, po, text, link, childrenData, lastNode)
  152. {
  153. var node = new Object();
  154. node.children = Array();
  155. node.childrenData = childrenData;
  156. node.depth = po.depth + 1;
  157. node.relpath = po.relpath;
  158. node.isLast = lastNode;
  159. node.li = document.createElement("li");
  160. po.getChildrenUL().appendChild(node.li);
  161. node.parentNode = po;
  162. node.itemDiv = document.createElement("div");
  163. node.itemDiv.className = "item";
  164. node.labelSpan = document.createElement("span");
  165. node.labelSpan.className = "label";
  166. createIndent(o,node.itemDiv,node,0);
  167. node.itemDiv.appendChild(node.labelSpan);
  168. node.li.appendChild(node.itemDiv);
  169. var a = document.createElement("a");
  170. node.labelSpan.appendChild(a);
  171. node.label = document.createTextNode(text);
  172. node.expanded = false;
  173. a.appendChild(node.label);
  174. if (link) {
  175. var url;
  176. if (link.substring(0,1)=='^') {
  177. url = link.substring(1);
  178. link = url;
  179. } else {
  180. url = node.relpath+link;
  181. }
  182. a.className = stripPath(link.replace('#',':'));
  183. if (link.indexOf('#')!=-1) {
  184. var aname = '#'+link.split('#')[1];
  185. var srcPage = stripPath(pathName());
  186. var targetPage = stripPath(link.split('#')[0]);
  187. a.href = srcPage!=targetPage ? url : "javascript:void(0)";
  188. a.onclick = function(){
  189. storeLink(link);
  190. if (!$(a).parent().parent().hasClass('selected'))
  191. {
  192. $('.item').removeClass('selected');
  193. $('.item').removeAttr('id');
  194. $(a).parent().parent().addClass('selected');
  195. $(a).parent().parent().attr('id','selected');
  196. }
  197. var anchor = $(aname);
  198. gotoAnchor(anchor,aname,true);
  199. };
  200. } else {
  201. a.href = url;
  202. a.onclick = function() { storeLink(link); }
  203. }
  204. } else {
  205. if (childrenData != null)
  206. {
  207. a.className = "nolink";
  208. a.href = "javascript:void(0)";
  209. a.onclick = node.expandToggle.onclick;
  210. }
  211. }
  212. node.childrenUL = null;
  213. node.getChildrenUL = function() {
  214. if (!node.childrenUL) {
  215. node.childrenUL = document.createElement("ul");
  216. node.childrenUL.className = "children_ul";
  217. node.childrenUL.style.display = "none";
  218. node.li.appendChild(node.childrenUL);
  219. }
  220. return node.childrenUL;
  221. };
  222. return node;
  223. }
  224. function showRoot()
  225. {
  226. var headerHeight = $("#top").height();
  227. var footerHeight = $("#nav-path").height();
  228. var windowHeight = $(window).height() - headerHeight - footerHeight;
  229. (function (){ // retry until we can scroll to the selected item
  230. try {
  231. var navtree=$('#nav-tree');
  232. navtree.scrollTo('#selected',100,{offset:-windowHeight/2});
  233. } catch (err) {
  234. setTimeout(arguments.callee, 0);
  235. }
  236. })();
  237. }
  238. function expandNode(o, node, imm, showRoot)
  239. {
  240. if (node.childrenData && !node.expanded) {
  241. if (typeof(node.childrenData)==='string') {
  242. var varName = node.childrenData;
  243. getScript(node.relpath+varName,function(){
  244. node.childrenData = getData(varName);
  245. expandNode(o, node, imm, showRoot);
  246. }, showRoot);
  247. } else {
  248. if (!node.childrenVisited) {
  249. getNode(o, node);
  250. }
  251. $(node.getChildrenUL()).slideDown("fast");
  252. node.plus_img.innerHTML = arrowDown;
  253. node.expanded = true;
  254. }
  255. }
  256. }
  257. function glowEffect(n,duration)
  258. {
  259. n.addClass('glow').delay(duration).queue(function(next){
  260. $(this).removeClass('glow');next();
  261. });
  262. }
  263. function highlightAnchor()
  264. {
  265. var aname = hashUrl();
  266. var anchor = $(aname);
  267. if (anchor.parent().attr('class')=='memItemLeft'){
  268. var rows = $('.memberdecls tr[class$="'+hashValue()+'"]');
  269. glowEffect(rows.children(),300); // member without details
  270. } else if (anchor.parent().attr('class')=='fieldname'){
  271. glowEffect(anchor.parent().parent(),1000); // enum value
  272. } else if (anchor.parent().attr('class')=='fieldtype'){
  273. glowEffect(anchor.parent().parent(),1000); // struct field
  274. } else if (anchor.parent().is(":header")) {
  275. glowEffect(anchor.parent(),1000); // section header
  276. } else {
  277. glowEffect(anchor.next(),1000); // normal member
  278. }
  279. }
  280. function selectAndHighlight(hash,n)
  281. {
  282. var a;
  283. if (hash) {
  284. var link=stripPath(pathName())+':'+hash.substring(1);
  285. a=$('.item a[class$="'+link+'"]');
  286. }
  287. if (a && a.length) {
  288. a.parent().parent().addClass('selected');
  289. a.parent().parent().attr('id','selected');
  290. highlightAnchor();
  291. } else if (n) {
  292. $(n.itemDiv).addClass('selected');
  293. $(n.itemDiv).attr('id','selected');
  294. }
  295. if ($('#nav-tree-contents .item:first').hasClass('selected')) {
  296. $('#nav-sync').css('top','30px');
  297. } else {
  298. $('#nav-sync').css('top','5px');
  299. }
  300. showRoot();
  301. }
  302. function showNode(o, node, index, hash)
  303. {
  304. if (node && node.childrenData) {
  305. if (typeof(node.childrenData)==='string') {
  306. var varName = node.childrenData;
  307. getScript(node.relpath+varName,function(){
  308. node.childrenData = getData(varName);
  309. showNode(o,node,index,hash);
  310. },true);
  311. } else {
  312. if (!node.childrenVisited) {
  313. getNode(o, node);
  314. }
  315. $(node.getChildrenUL()).css({'display':'block'});
  316. node.plus_img.innerHTML = arrowDown;
  317. node.expanded = true;
  318. var n = node.children[o.breadcrumbs[index]];
  319. if (index+1<o.breadcrumbs.length) {
  320. showNode(o,n,index+1,hash);
  321. } else {
  322. if (typeof(n.childrenData)==='string') {
  323. var varName = n.childrenData;
  324. getScript(n.relpath+varName,function(){
  325. n.childrenData = getData(varName);
  326. node.expanded=false;
  327. showNode(o,node,index,hash); // retry with child node expanded
  328. },true);
  329. } else {
  330. var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
  331. if (rootBase=="index" || rootBase=="pages" || rootBase=="search") {
  332. expandNode(o, n, true, true);
  333. }
  334. selectAndHighlight(hash,n);
  335. }
  336. }
  337. }
  338. } else {
  339. selectAndHighlight(hash);
  340. }
  341. }
  342. function removeToInsertLater(element) {
  343. var parentNode = element.parentNode;
  344. var nextSibling = element.nextSibling;
  345. parentNode.removeChild(element);
  346. return function() {
  347. if (nextSibling) {
  348. parentNode.insertBefore(element, nextSibling);
  349. } else {
  350. parentNode.appendChild(element);
  351. }
  352. };
  353. }
  354. function getNode(o, po)
  355. {
  356. var insertFunction = removeToInsertLater(po.li);
  357. po.childrenVisited = true;
  358. var l = po.childrenData.length-1;
  359. for (var i in po.childrenData) {
  360. var nodeData = po.childrenData[i];
  361. po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
  362. i==l);
  363. }
  364. insertFunction();
  365. }
  366. function gotoNode(o,subIndex,root,hash,relpath)
  367. {
  368. var nti = navTreeSubIndices[subIndex][root+hash];
  369. o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);
  370. if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index
  371. navTo(o,NAVTREE[0][1],"",relpath);
  372. $('.item').removeClass('selected');
  373. $('.item').removeAttr('id');
  374. }
  375. if (o.breadcrumbs) {
  376. o.breadcrumbs.unshift(0); // add 0 for root node
  377. showNode(o, o.node, 0, hash);
  378. }
  379. }
  380. function navTo(o,root,hash,relpath)
  381. {
  382. var link = cachedLink();
  383. if (link) {
  384. var parts = link.split('#');
  385. root = parts[0];
  386. if (parts.length>1) hash = '#'+parts[1].replace(/[^\w\-]/g,'');
  387. else hash='';
  388. }
  389. if (hash.match(/^#l\d+$/)) {
  390. var anchor=$('a[name='+hash.substring(1)+']');
  391. glowEffect(anchor.parent(),1000); // line number
  392. hash=''; // strip line number anchors
  393. }
  394. var url=root+hash;
  395. var i=-1;
  396. while (NAVTREEINDEX[i+1]<=url) i++;
  397. if (i==-1) { i=0; root=NAVTREE[0][1]; } // fallback: show index
  398. if (navTreeSubIndices[i]) {
  399. gotoNode(o,i,root,hash,relpath)
  400. } else {
  401. getScript(relpath+'navtreeindex'+i,function(){
  402. navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);
  403. if (navTreeSubIndices[i]) {
  404. gotoNode(o,i,root,hash,relpath);
  405. }
  406. },true);
  407. }
  408. }
  409. function showSyncOff(n,relpath)
  410. {
  411. n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');
  412. }
  413. function showSyncOn(n,relpath)
  414. {
  415. n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>');
  416. }
  417. function toggleSyncButton(relpath)
  418. {
  419. var navSync = $('#nav-sync');
  420. if (navSync.hasClass('sync')) {
  421. navSync.removeClass('sync');
  422. showSyncOff(navSync,relpath);
  423. storeLink(stripPath2(pathName())+hashUrl());
  424. } else {
  425. navSync.addClass('sync');
  426. showSyncOn(navSync,relpath);
  427. deleteLink();
  428. }
  429. }
  430. var loadTriggered = false;
  431. var readyTriggered = false;
  432. var loadObject,loadToRoot,loadUrl,loadRelPath;
  433. $(window).on('load',function(){
  434. if (readyTriggered) { // ready first
  435. navTo(loadObject,loadToRoot,loadUrl,loadRelPath);
  436. showRoot();
  437. }
  438. loadTriggered=true;
  439. });
  440. function initNavTree(toroot,relpath)
  441. {
  442. var o = new Object();
  443. o.toroot = toroot;
  444. o.node = new Object();
  445. o.node.li = document.getElementById("nav-tree-contents");
  446. o.node.childrenData = NAVTREE;
  447. o.node.children = new Array();
  448. o.node.childrenUL = document.createElement("ul");
  449. o.node.getChildrenUL = function() { return o.node.childrenUL; };
  450. o.node.li.appendChild(o.node.childrenUL);
  451. o.node.depth = 0;
  452. o.node.relpath = relpath;
  453. o.node.expanded = false;
  454. o.node.isLast = true;
  455. o.node.plus_img = document.createElement("span");
  456. o.node.plus_img.className = 'arrow';
  457. o.node.plus_img.innerHTML = arrowRight;
  458. if (localStorageSupported()) {
  459. var navSync = $('#nav-sync');
  460. if (cachedLink()) {
  461. showSyncOff(navSync,relpath);
  462. navSync.removeClass('sync');
  463. } else {
  464. showSyncOn(navSync,relpath);
  465. }
  466. navSync.click(function(){ toggleSyncButton(relpath); });
  467. }
  468. if (loadTriggered) { // load before ready
  469. navTo(o,toroot,hashUrl(),relpath);
  470. showRoot();
  471. } else { // ready before load
  472. loadObject = o;
  473. loadToRoot = toroot;
  474. loadUrl = hashUrl();
  475. loadRelPath = relpath;
  476. readyTriggered=true;
  477. }
  478. $(window).bind('hashchange', function(){
  479. if (window.location.hash && window.location.hash.length>1){
  480. var a;
  481. if ($(location).attr('hash')){
  482. var clslink=stripPath(pathName())+':'+hashValue();
  483. a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]');
  484. }
  485. if (a==null || !$(a).parent().parent().hasClass('selected')){
  486. $('.item').removeClass('selected');
  487. $('.item').removeAttr('id');
  488. }
  489. var link=stripPath2(pathName());
  490. navTo(o,link,hashUrl(),relpath);
  491. } else if (!animationInProgress) {
  492. $('#doc-content').scrollTop(0);
  493. $('.item').removeClass('selected');
  494. $('.item').removeAttr('id');
  495. navTo(o,toroot,hashUrl(),relpath);
  496. }
  497. })
  498. }
  499. /* @license-end */