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