navtree.js 15 KB

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