1 var navTreeSubIndices = new Array();
2 var arrowDown = '▼';
3 var arrowRight = '►';
5 function getData(varName)
7 var i = varName.lastIndexOf('/');
8 var n = i>=0 ? varName.substring(i+1) : varName;
9 return eval(n.replace(/\-/g,'_'));
12 function stripPath(uri)
14 return uri.substring(uri.lastIndexOf('/')+1);
17 function stripPath2(uri)
19 var i = uri.lastIndexOf('/');
20 var s = uri.substring(i+1);
21 var m = uri.substring(0,i+1).match(/\/d\w\/d\w\w\/$/);
22 return m ? uri.substring(i-6) : s;
27 return $(location).attr('hash').substring(1).replace(/[^\w\-]/g,'');
32 return '#'+hashValue();
37 return $(location).attr('pathname').replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/g, '');
40 function localStorageSupported()
43 return 'localStorage' in window && window['localStorage'] !== null && window.localStorage.getItem;
51 function storeLink(link)
53 if (!$("#nav-sync").hasClass('sync') && localStorageSupported()) {
54 window.localStorage.setItem('navpath',link);
60 if (localStorageSupported()) {
61 window.localStorage.setItem('navpath','');
67 if (localStorageSupported()) {
68 return window.localStorage.getItem('navpath');
74 function getScript(scriptName,func,show)
76 var head = document.getElementsByTagName("head")[0];
77 var script = document.createElement('script');
78 script.id = scriptName;
79 script.type = 'text/javascript';
81 script.src = scriptName+'.js';
82 if ($.browser.msie && $.browser.version<=8) {
83 // script.onload does not work with older versions of IE
84 script.onreadystatechange = function() {
85 if (script.readyState=='complete' || script.readyState=='loaded') {
86 func(); if (show) showRoot();
90 head.appendChild(script);
93 function createIndent(o,domNode,node,level)
97 while (n.parentNode) { level++; n=n.parentNode; }
98 if (node.childrenData) {
99 var imgNode = document.createElement("span");
100 imgNode.className = 'arrow';
101 imgNode.style.paddingLeft=(16*level).toString()+'px';
102 imgNode.innerHTML=arrowRight;
103 node.plus_img = imgNode;
104 node.expandToggle = document.createElement("a");
105 node.expandToggle.href = "javascript:void(0)";
106 node.expandToggle.onclick = function() {
108 $(node.getChildrenUL()).slideUp("fast");
109 node.plus_img.innerHTML=arrowRight;
110 node.expanded = false;
112 expandNode(o, node, false, false);
115 node.expandToggle.appendChild(imgNode);
116 domNode.appendChild(node.expandToggle);
118 var span = document.createElement("span");
119 span.className = 'arrow';
120 span.style.width = 16*(level+1)+'px';
121 span.innerHTML = ' ';
122 domNode.appendChild(span);
126 var animationInProgress = false;
128 function gotoAnchor(anchor,aname,updateLocation)
130 var pos, docContent = $('#doc-content');
131 var ancParent = $(anchor.parent());
132 if (ancParent.hasClass('memItemLeft') ||
133 ancParent.hasClass('fieldname') ||
134 ancParent.hasClass('fieldtype') ||
135 ancParent.is(':header'))
137 pos = ancParent.position().top;
138 } else if (anchor.position()) {
139 pos = anchor.position().top;
142 var dist = Math.abs(Math.min(
143 pos-docContent.offset().top,
144 docContent[0].scrollHeight-
145 docContent.height()-docContent.scrollTop()));
146 animationInProgress=true;
148 scrollTop: pos + docContent.scrollTop() - docContent.offset().top
149 },Math.max(50,Math.min(500,dist)),function(){
150 if (updateLocation) window.location.href=aname;
151 animationInProgress=false;
156 function newNode(o, po, text, link, childrenData, lastNode)
158 var node = new Object();
159 node.children = Array();
160 node.childrenData = childrenData;
161 node.depth = po.depth + 1;
162 node.relpath = po.relpath;
163 node.isLast = lastNode;
165 node.li = document.createElement("li");
166 po.getChildrenUL().appendChild(node.li);
167 node.parentNode = po;
169 node.itemDiv = document.createElement("div");
170 node.itemDiv.className = "item";
172 node.labelSpan = document.createElement("span");
173 node.labelSpan.className = "label";
175 createIndent(o,node.itemDiv,node,0);
176 node.itemDiv.appendChild(node.labelSpan);
177 node.li.appendChild(node.itemDiv);
179 var a = document.createElement("a");
180 node.labelSpan.appendChild(a);
181 node.label = document.createTextNode(text);
182 node.expanded = false;
183 a.appendChild(node.label);
186 if (link.substring(0,1)=='^') {
187 url = link.substring(1);
190 url = node.relpath+link;
192 a.className = stripPath(link.replace('#',':'));
193 if (link.indexOf('#')!=-1) {
194 var aname = '#'+link.split('#')[1];
195 var srcPage = stripPath(pathName());
196 var targetPage = stripPath(link.split('#')[0]);
197 a.href = srcPage!=targetPage ? url : "javascript:void(0)";
198 a.onclick = function(){
200 if (!$(a).parent().parent().hasClass('selected'))
202 $('.item').removeClass('selected');
203 $('.item').removeAttr('id');
204 $(a).parent().parent().addClass('selected');
205 $(a).parent().parent().attr('id','selected');
207 var anchor = $(aname);
208 gotoAnchor(anchor,aname,true);
212 a.onclick = function() { storeLink(link); }
215 if (childrenData != null)
217 a.className = "nolink";
218 a.href = "javascript:void(0)";
219 a.onclick = node.expandToggle.onclick;
223 node.childrenUL = null;
224 node.getChildrenUL = function() {
225 if (!node.childrenUL) {
226 node.childrenUL = document.createElement("ul");
227 node.childrenUL.className = "children_ul";
228 node.childrenUL.style.display = "none";
229 node.li.appendChild(node.childrenUL);
231 return node.childrenUL;
239 var headerHeight = $("#top").height();
240 var footerHeight = $("#nav-path").height();
241 var windowHeight = $(window).height() - headerHeight - footerHeight;
242 (function (){ // retry until we can scroll to the selected item
244 var navtree=$('#nav-tree');
245 navtree.scrollTo('#selected',0,{offset:-windowHeight/2});
247 setTimeout(arguments.callee, 0);
252 function expandNode(o, node, imm, showRoot)
254 if (node.childrenData && !node.expanded) {
255 if (typeof(node.childrenData)==='string') {
256 var varName = node.childrenData;
257 getScript(node.relpath+varName,function(){
258 node.childrenData = getData(varName);
259 expandNode(o, node, imm, showRoot);
262 if (!node.childrenVisited) {
264 } if (imm || ($.browser.msie && $.browser.version>8)) {
265 // somehow slideDown jumps to the start of tree for IE9 :-(
266 $(node.getChildrenUL()).show();
268 $(node.getChildrenUL()).slideDown("fast");
270 node.plus_img.innerHTML = arrowDown;
271 node.expanded = true;
276 function glowEffect(n,duration)
278 n.addClass('glow').delay(duration).queue(function(next){
279 $(this).removeClass('glow');next();
283 function highlightAnchor()
285 var aname = hashUrl();
286 var anchor = $(aname);
287 if (anchor.parent().attr('class')=='memItemLeft'){
288 var rows = $('.memberdecls tr[class$="'+hashValue()+'"]');
289 glowEffect(rows.children(),300); // member without details
290 } else if (anchor.parent().attr('class')=='fieldname'){
291 glowEffect(anchor.parent().parent(),1000); // enum value
292 } else if (anchor.parent().attr('class')=='fieldtype'){
293 glowEffect(anchor.parent().parent(),1000); // struct field
294 } else if (anchor.parent().is(":header")) {
295 glowEffect(anchor.parent(),1000); // section header
297 glowEffect(anchor.next(),1000); // normal member
299 gotoAnchor(anchor,aname,false);
302 function selectAndHighlight(hash,n)
306 var link=stripPath(pathName())+':'+hash.substring(1);
307 a=$('.item a[class$="'+link+'"]');
310 a.parent().parent().addClass('selected');
311 a.parent().parent().attr('id','selected');
314 $(n.itemDiv).addClass('selected');
315 $(n.itemDiv).attr('id','selected');
317 if ($('#nav-tree-contents .item:first').hasClass('selected')) {
318 $('#nav-sync').css('top','30px');
320 $('#nav-sync').css('top','5px');
325 function showNode(o, node, index, hash)
327 if (node && node.childrenData) {
328 if (typeof(node.childrenData)==='string') {
329 var varName = node.childrenData;
330 getScript(node.relpath+varName,function(){
331 node.childrenData = getData(varName);
332 showNode(o,node,index,hash);
335 if (!node.childrenVisited) {
338 $(node.getChildrenUL()).css({'display':'block'});
339 node.plus_img.innerHTML = arrowDown;
340 node.expanded = true;
341 var n = node.children[o.breadcrumbs[index]];
342 if (index+1<o.breadcrumbs.length) {
343 showNode(o,n,index+1,hash);
345 if (typeof(n.childrenData)==='string') {
346 var varName = n.childrenData;
347 getScript(n.relpath+varName,function(){
348 n.childrenData = getData(varName);
350 showNode(o,node,index,hash); // retry with child node expanded
353 var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
354 if (rootBase=="index" || rootBase=="pages" || rootBase=="search") {
355 expandNode(o, n, true, true);
357 selectAndHighlight(hash,n);
362 selectAndHighlight(hash);
366 function removeToInsertLater(element) {
367 var parentNode = element.parentNode;
368 var nextSibling = element.nextSibling;
369 parentNode.removeChild(element);
372 parentNode.insertBefore(element, nextSibling);
374 parentNode.appendChild(element);
379 function getNode(o, po)
381 var insertFunction = removeToInsertLater(po.li);
382 po.childrenVisited = true;
383 var l = po.childrenData.length-1;
384 for (var i in po.childrenData) {
385 var nodeData = po.childrenData[i];
386 po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
392 function gotoNode(o,subIndex,root,hash,relpath)
394 var nti = navTreeSubIndices[subIndex][root+hash];
395 o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);
396 if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index
397 navTo(o,NAVTREE[0][1],"",relpath);
398 $('.item').removeClass('selected');
399 $('.item').removeAttr('id');
402 o.breadcrumbs.unshift(0); // add 0 for root node
403 showNode(o, o.node, 0, hash);
407 function navTo(o,root,hash,relpath)
409 var link = cachedLink();
411 var parts = link.split('#');
413 if (parts.length>1) hash = '#'+parts[1].replace(/[^\w\-]/g,'');
416 if (hash.match(/^#l\d+$/)) {
417 var anchor=$('a[name='+hash.substring(1)+']');
418 glowEffect(anchor.parent(),1000); // line number
419 hash=''; // strip line number anchors
423 while (NAVTREEINDEX[i+1]<=url) i++;
424 if (i==-1) { i=0; root=NAVTREE[0][1]; } // fallback: show index
425 if (navTreeSubIndices[i]) {
426 gotoNode(o,i,root,hash,relpath)
428 getScript(relpath+'navtreeindex'+i,function(){
429 navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);
430 if (navTreeSubIndices[i]) {
431 gotoNode(o,i,root,hash,relpath);
437 function showSyncOff(n,relpath)
439 n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');
442 function showSyncOn(n,relpath)
444 n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>');
447 function toggleSyncButton(relpath)
449 var navSync = $('#nav-sync');
450 if (navSync.hasClass('sync')) {
451 navSync.removeClass('sync');
452 showSyncOff(navSync,relpath);
453 storeLink(stripPath2(pathName())+hashUrl());
455 navSync.addClass('sync');
456 showSyncOn(navSync,relpath);
461 function initNavTree(toroot,relpath)
463 var o = new Object();
465 o.node = new Object();
466 o.node.li = document.getElementById("nav-tree-contents");
467 o.node.childrenData = NAVTREE;
468 o.node.children = new Array();
469 o.node.childrenUL = document.createElement("ul");
470 o.node.getChildrenUL = function() { return o.node.childrenUL; };
471 o.node.li.appendChild(o.node.childrenUL);
473 o.node.relpath = relpath;
474 o.node.expanded = false;
475 o.node.isLast = true;
476 o.node.plus_img = document.createElement("span");
477 o.node.plus_img.className = 'arrow';
478 o.node.plus_img.innerHTML = arrowRight;
480 if (localStorageSupported()) {
481 var navSync = $('#nav-sync');
483 showSyncOff(navSync,relpath);
484 navSync.removeClass('sync');
486 showSyncOn(navSync,relpath);
488 navSync.click(function(){ toggleSyncButton(relpath); });
491 $(window).load(function(){
492 navTo(o,toroot,hashUrl(),relpath);
496 $(window).bind('hashchange', function(){
497 if (window.location.hash && window.location.hash.length>1){
499 if ($(location).attr('hash')){
500 var clslink=stripPath(pathName())+':'+hashValue();
501 a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]');
503 if (a==null || !$(a).parent().parent().hasClass('selected')){
504 $('.item').removeClass('selected');
505 $('.item').removeAttr('id');
507 var link=stripPath2(pathName());
508 navTo(o,link,hashUrl(),relpath);
509 } else if (!animationInProgress) {
510 $('#doc-content').scrollTop(0);
511 $('.item').removeClass('selected');
512 $('.item').removeAttr('id');
513 navTo(o,toroot,hashUrl(),relpath);