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