navtree.js 15 KB

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