navtree.js 15 KB

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