navtree.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. var topOffset=5;
  296. if (typeof page_layout!=='undefined' && page_layout==1) {
  297. topOffset+=$('#top').outerHeight();
  298. }
  299. if ($('#nav-tree-contents .item:first').hasClass('selected')) {
  300. topOffset+=25;
  301. }
  302. $('#nav-sync').css('top',topOffset+'px');
  303. showRoot();
  304. }
  305. function showNode(o, node, index, hash)
  306. {
  307. if (node && node.childrenData) {
  308. if (typeof(node.childrenData)==='string') {
  309. var varName = node.childrenData;
  310. getScript(node.relpath+varName,function(){
  311. node.childrenData = getData(varName);
  312. showNode(o,node,index,hash);
  313. },true);
  314. } else {
  315. if (!node.childrenVisited) {
  316. getNode(o, node);
  317. }
  318. $(node.getChildrenUL()).css({'display':'block'});
  319. node.plus_img.innerHTML = arrowDown;
  320. node.expanded = true;
  321. var n = node.children[o.breadcrumbs[index]];
  322. if (index+1<o.breadcrumbs.length) {
  323. showNode(o,n,index+1,hash);
  324. } else {
  325. if (typeof(n.childrenData)==='string') {
  326. var varName = n.childrenData;
  327. getScript(n.relpath+varName,function(){
  328. n.childrenData = getData(varName);
  329. node.expanded=false;
  330. showNode(o,node,index,hash); // retry with child node expanded
  331. },true);
  332. } else {
  333. var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
  334. if (rootBase=="index" || rootBase=="pages" || rootBase=="search") {
  335. expandNode(o, n, true, true);
  336. }
  337. selectAndHighlight(hash,n);
  338. }
  339. }
  340. }
  341. } else {
  342. selectAndHighlight(hash);
  343. }
  344. }
  345. function removeToInsertLater(element) {
  346. var parentNode = element.parentNode;
  347. var nextSibling = element.nextSibling;
  348. parentNode.removeChild(element);
  349. return function() {
  350. if (nextSibling) {
  351. parentNode.insertBefore(element, nextSibling);
  352. } else {
  353. parentNode.appendChild(element);
  354. }
  355. };
  356. }
  357. function getNode(o, po)
  358. {
  359. var insertFunction = removeToInsertLater(po.li);
  360. po.childrenVisited = true;
  361. var l = po.childrenData.length-1;
  362. for (var i in po.childrenData) {
  363. var nodeData = po.childrenData[i];
  364. po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
  365. i==l);
  366. }
  367. insertFunction();
  368. }
  369. function gotoNode(o,subIndex,root,hash,relpath)
  370. {
  371. var nti = navTreeSubIndices[subIndex][root+hash];
  372. o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);
  373. if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index
  374. navTo(o,NAVTREE[0][1],"",relpath);
  375. $('.item').removeClass('selected');
  376. $('.item').removeAttr('id');
  377. }
  378. if (o.breadcrumbs) {
  379. o.breadcrumbs.unshift(0); // add 0 for root node
  380. showNode(o, o.node, 0, hash);
  381. }
  382. }
  383. function navTo(o,root,hash,relpath)
  384. {
  385. var link = cachedLink();
  386. if (link) {
  387. var parts = link.split('#');
  388. root = parts[0];
  389. if (parts.length>1) hash = '#'+parts[1].replace(/[^\w\-]/g,'');
  390. else hash='';
  391. }
  392. if (hash.match(/^#l\d+$/)) {
  393. var anchor=$('a[name='+hash.substring(1)+']');
  394. glowEffect(anchor.parent(),1000); // line number
  395. hash=''; // strip line number anchors
  396. }
  397. var url=root+hash;
  398. var i=-1;
  399. while (NAVTREEINDEX[i+1]<=url) i++;
  400. if (i==-1) { i=0; root=NAVTREE[0][1]; } // fallback: show index
  401. if (navTreeSubIndices[i]) {
  402. gotoNode(o,i,root,hash,relpath)
  403. } else {
  404. getScript(relpath+'navtreeindex'+i,function(){
  405. navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);
  406. if (navTreeSubIndices[i]) {
  407. gotoNode(o,i,root,hash,relpath);
  408. }
  409. },true);
  410. }
  411. }
  412. function showSyncOff(n,relpath)
  413. {
  414. n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');
  415. }
  416. function showSyncOn(n,relpath)
  417. {
  418. n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>');
  419. }
  420. function toggleSyncButton(relpath)
  421. {
  422. var navSync = $('#nav-sync');
  423. if (navSync.hasClass('sync')) {
  424. navSync.removeClass('sync');
  425. showSyncOff(navSync,relpath);
  426. storeLink(stripPath2(pathName())+hashUrl());
  427. } else {
  428. navSync.addClass('sync');
  429. showSyncOn(navSync,relpath);
  430. deleteLink();
  431. }
  432. }
  433. var loadTriggered = false;
  434. var readyTriggered = false;
  435. var loadObject,loadToRoot,loadUrl,loadRelPath;
  436. $(window).on('load',function(){
  437. if (readyTriggered) { // ready first
  438. navTo(loadObject,loadToRoot,loadUrl,loadRelPath);
  439. showRoot();
  440. }
  441. loadTriggered=true;
  442. });
  443. function initNavTree(toroot,relpath)
  444. {
  445. var o = new Object();
  446. o.toroot = toroot;
  447. o.node = new Object();
  448. o.node.li = document.getElementById("nav-tree-contents");
  449. o.node.childrenData = NAVTREE;
  450. o.node.children = new Array();
  451. o.node.childrenUL = document.createElement("ul");
  452. o.node.getChildrenUL = function() { return o.node.childrenUL; };
  453. o.node.li.appendChild(o.node.childrenUL);
  454. o.node.depth = 0;
  455. o.node.relpath = relpath;
  456. o.node.expanded = false;
  457. o.node.isLast = true;
  458. o.node.plus_img = document.createElement("span");
  459. o.node.plus_img.className = 'arrow';
  460. o.node.plus_img.innerHTML = arrowRight;
  461. if (localStorageSupported()) {
  462. var navSync = $('#nav-sync');
  463. if (cachedLink()) {
  464. showSyncOff(navSync,relpath);
  465. navSync.removeClass('sync');
  466. } else {
  467. showSyncOn(navSync,relpath);
  468. }
  469. navSync.click(function(){ toggleSyncButton(relpath); });
  470. }
  471. if (loadTriggered) { // load before ready
  472. navTo(o,toroot,hashUrl(),relpath);
  473. showRoot();
  474. } else { // ready before load
  475. loadObject = o;
  476. loadToRoot = toroot;
  477. loadUrl = hashUrl();
  478. loadRelPath = relpath;
  479. readyTriggered=true;
  480. }
  481. $(window).bind('hashchange', function(){
  482. if (window.location.hash && window.location.hash.length>1){
  483. var a;
  484. if ($(location).attr('hash')){
  485. var clslink=stripPath(pathName())+':'+hashValue();
  486. a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]');
  487. }
  488. if (a==null || !$(a).parent().parent().hasClass('selected')){
  489. $('.item').removeClass('selected');
  490. $('.item').removeAttr('id');
  491. }
  492. var link=stripPath2(pathName());
  493. navTo(o,link,hashUrl(),relpath);
  494. } else if (!animationInProgress) {
  495. $('#doc-content').scrollTop(0);
  496. $('.item').removeClass('selected');
  497. $('.item').removeAttr('id');
  498. navTo(o,toroot,hashUrl(),relpath);
  499. }
  500. })
  501. }
  502. /* @license-end */