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