2 @licstart The following is the entire license notice for the
3 JavaScript code in this file.
5 Copyright (C) 1997-2019 by Dimitri van Heesch
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.
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.
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.
20 @licend The above is the entire license notice
21 for the JavaScript code in this file
23 var navTreeSubIndices = new Array();
24 var arrowDown = '▼';
25 var arrowRight = '►';
27 function getData(varName)
29 var i = varName.lastIndexOf('/');
30 var n = i>=0 ? varName.substring(i+1) : varName;
31 return eval(n.replace(/\-/g,'_'));
34 function stripPath(uri)
36 return uri.substring(uri.lastIndexOf('/')+1);
39 function stripPath2(uri)
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;
49 return $(location).attr('hash').substring(1).replace(/[^\w\-]/g,'');
54 return '#'+hashValue();
59 return $(location).attr('pathname').replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/g, '');
62 function localStorageSupported()
65 return 'localStorage' in window && window['localStorage'] !== null && window.localStorage.getItem;
72 function storeLink(link)
74 if (!$("#nav-sync").hasClass('sync') && localStorageSupported()) {
75 window.localStorage.setItem('navpath',link);
81 if (localStorageSupported()) {
82 window.localStorage.setItem('navpath','');
88 if (localStorageSupported()) {
89 return window.localStorage.getItem('navpath');
95 function getScript(scriptName,func,show)
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);
106 function createIndent(o,domNode,node,level)
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() {
121 $(node.getChildrenUL()).slideUp("fast");
122 node.plus_img.innerHTML=arrowRight;
123 node.expanded = false;
125 expandNode(o, node, false, false);
128 node.expandToggle.appendChild(imgNode);
129 domNode.appendChild(node.expandToggle);
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);
139 var animationInProgress = false;
141 function gotoAnchor(anchor,aname,updateLocation)
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'))
151 pos = ancParent.position().top;
152 } else if (anchor.position()) {
153 pos = anchor.position().top;
156 var dist = Math.abs(Math.min(
157 pos-docContent.offset().top,
158 docContent[0].scrollHeight-
159 docContent.height()-docContent.scrollTop()));
160 animationInProgress=true;
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;
170 function newNode(o, po, text, link, childrenData, lastNode)
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;
179 node.li = document.createElement("li");
180 po.getChildrenUL().appendChild(node.li);
181 node.parentNode = po;
183 node.itemDiv = document.createElement("div");
184 node.itemDiv.className = "item";
186 node.labelSpan = document.createElement("span");
187 node.labelSpan.className = "label";
189 createIndent(o,node.itemDiv,node,0);
190 node.itemDiv.appendChild(node.labelSpan);
191 node.li.appendChild(node.itemDiv);
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);
200 if (link.substring(0,1)=='^') {
201 url = link.substring(1);
204 url = node.relpath+link;
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(){
214 if (!$(a).parent().parent().hasClass('selected'))
216 $('.item').removeClass('selected');
217 $('.item').removeAttr('id');
218 $(a).parent().parent().addClass('selected');
219 $(a).parent().parent().attr('id','selected');
221 var anchor = $(aname);
222 gotoAnchor(anchor,aname,true);
226 a.onclick = function() { storeLink(link); }
229 if (childrenData != null)
231 a.className = "nolink";
232 a.href = "javascript:void(0)";
233 a.onclick = node.expandToggle.onclick;
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);
245 return node.childrenUL;
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
258 var navtree=$('#nav-tree');
259 navtree.scrollTo('#selected',100,{offset:-windowHeight/2});
261 setTimeout(arguments.callee, 0);
266 function expandNode(o, node, imm, showRoot)
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);
276 if (!node.childrenVisited) {
279 $(node.getChildrenUL()).slideDown("fast");
280 node.plus_img.innerHTML = arrowDown;
281 node.expanded = true;
286 function glowEffect(n,duration)
288 n.addClass('glow').delay(duration).queue(function(next){
289 $(this).removeClass('glow');next();
293 function highlightAnchor()
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
307 glowEffect(anchor.next(),1000); // normal member
311 function selectAndHighlight(hash,n)
315 var link=stripPath(pathName())+':'+hash.substring(1);
316 a=$('.item a[class$="'+link+'"]');
319 a.parent().parent().addClass('selected');
320 a.parent().parent().attr('id','selected');
323 $(n.itemDiv).addClass('selected');
324 $(n.itemDiv).attr('id','selected');
326 if ($('#nav-tree-contents .item:first').hasClass('selected')) {
327 $('#nav-sync').css('top','30px');
329 $('#nav-sync').css('top','5px');
334 function showNode(o, node, index, hash)
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);
344 if (!node.childrenVisited) {
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);
354 if (typeof(n.childrenData)==='string') {
355 var varName = n.childrenData;
356 getScript(n.relpath+varName,function(){
357 n.childrenData = getData(varName);
359 showNode(o,node,index,hash); // retry with child node expanded
362 var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
363 if (rootBase=="index" || rootBase=="pages" || rootBase=="search") {
364 expandNode(o, n, true, true);
366 selectAndHighlight(hash,n);
371 selectAndHighlight(hash);
375 function removeToInsertLater(element) {
376 var parentNode = element.parentNode;
377 var nextSibling = element.nextSibling;
378 parentNode.removeChild(element);
381 parentNode.insertBefore(element, nextSibling);
383 parentNode.appendChild(element);
388 function getNode(o, po)
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],
401 function gotoNode(o,subIndex,root,hash,relpath)
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');
411 o.breadcrumbs.unshift(0); // add 0 for root node
412 showNode(o, o.node, 0, hash);
416 function navTo(o,root,hash,relpath)
418 var link = cachedLink();
420 var parts = link.split('#');
422 if (parts.length>1) hash = '#'+parts[1].replace(/[^\w\-]/g,'');
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
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)
437 getScript(relpath+'navtreeindex'+i,function(){
438 navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);
439 if (navTreeSubIndices[i]) {
440 gotoNode(o,i,root,hash,relpath);
446 function showSyncOff(n,relpath)
448 n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');
451 function showSyncOn(n,relpath)
453 n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>');
456 function toggleSyncButton(relpath)
458 var navSync = $('#nav-sync');
459 if (navSync.hasClass('sync')) {
460 navSync.removeClass('sync');
461 showSyncOff(navSync,relpath);
462 storeLink(stripPath2(pathName())+hashUrl());
464 navSync.addClass('sync');
465 showSyncOn(navSync,relpath);
470 var loadTriggered = false;
471 var readyTriggered = false;
472 var loadObject,loadToRoot,loadUrl,loadRelPath;
474 $(window).on('load',function(){
475 if (readyTriggered) { // ready first
476 navTo(loadObject,loadToRoot,loadUrl,loadRelPath);
482 function initNavTree(toroot,relpath)
484 var o = new Object();
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);
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;
501 if (localStorageSupported()) {
502 var navSync = $('#nav-sync');
504 showSyncOff(navSync,relpath);
505 navSync.removeClass('sync');
507 showSyncOn(navSync,relpath);
509 navSync.click(function(){ toggleSyncButton(relpath); });
512 if (loadTriggered) { // load before ready
513 navTo(o,toroot,hashUrl(),relpath);
515 } else { // ready before load
519 loadRelPath = relpath;
523 $(window).bind('hashchange', function(){
524 if (window.location.hash && window.location.hash.length>1){
526 if ($(location).attr('hash')){
527 var clslink=stripPath(pathName())+':'+hashValue();
528 a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]');
530 if (a==null || !$(a).parent().parent().hasClass('selected')){
531 $('.item').removeClass('selected');
532 $('.item').removeAttr('id');
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);