navtree.js 15 KB

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