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