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