navtree.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. var NAVTREE =
  2. [
  3. [ "CMSIS-CORE", "index.html", [
  4. [ "Overview", "index.html", null ],
  5. [ "Using CMSIS in Embedded Applications", "_using_pg.html", "_using_pg" ],
  6. [ "Template Files", "_templates_pg.html", "_templates_pg" ],
  7. [ "MISRA-C:2004 Compliance Exceptions", "_c_o_r_e__m_i_s_r_a__exceptions_pg.html", null ],
  8. [ "Register Mapping", "_reg_map_pg.html", null ],
  9. [ "Todo List", "todo.html", null ],
  10. [ "Reference", "modules.html", "modules" ],
  11. [ "Data Structures", "annotated.html", "annotated" ],
  12. [ "Data Fields", "functions.html", [
  13. [ "All", "functions.html", null ],
  14. [ "Variables", "functions_vars.html", null ]
  15. ] ]
  16. ] ]
  17. ];
  18. var NAVTREEINDEX =
  19. [
  20. "_c_o_r_e__m_i_s_r_a__exceptions_pg.html",
  21. "struct_n_v_i_c___type.html#acf8e38fc2e97316242ddeb7ea959ab90"
  22. ];
  23. var SYNCONMSG = 'click to disable panel synchronisation';
  24. var SYNCOFFMSG = 'click to enable panel synchronisation';
  25. var navTreeSubIndices = new Array();
  26. function getData(varName)
  27. {
  28. var i = varName.lastIndexOf('/');
  29. var n = i>=0 ? varName.substring(i+1) : varName;
  30. return eval(n.replace(/\-/g,'_'));
  31. }
  32. function stripPath(uri)
  33. {
  34. return uri.substring(uri.lastIndexOf('/')+1);
  35. }
  36. function stripPath2(uri)
  37. {
  38. var i = uri.lastIndexOf('/');
  39. var s = uri.substring(i+1);
  40. var m = uri.substring(0,i+1).match(/\/d\w\/d\w\w\/$/);
  41. return m ? uri.substring(i-6) : s;
  42. }
  43. function localStorageSupported()
  44. {
  45. try {
  46. return 'localStorage' in window && window['localStorage'] !== null && window.localStorage.getItem;
  47. }
  48. catch(e) {
  49. return false;
  50. }
  51. }
  52. function storeLink(link)
  53. {
  54. if (!$("#nav-sync").hasClass('sync') && localStorageSupported()) {
  55. window.localStorage.setItem('navpath',link);
  56. }
  57. }
  58. function deleteLink()
  59. {
  60. if (localStorageSupported()) {
  61. window.localStorage.setItem('navpath','');
  62. }
  63. }
  64. function cachedLink()
  65. {
  66. if (localStorageSupported()) {
  67. return window.localStorage.getItem('navpath');
  68. } else {
  69. return '';
  70. }
  71. }
  72. function getScript(scriptName,func,show)
  73. {
  74. var head = document.getElementsByTagName("head")[0];
  75. var script = document.createElement('script');
  76. script.id = scriptName;
  77. script.type = 'text/javascript';
  78. script.onload = func;
  79. script.src = scriptName+'.js';
  80. if ($.browser.msie && $.browser.version<=8) {
  81. // script.onload does work with older versions of IE
  82. script.onreadystatechange = function() {
  83. if (script.readyState=='complete' || script.readyState=='loaded') {
  84. func(); if (show) showRoot();
  85. }
  86. }
  87. }
  88. head.appendChild(script);
  89. }
  90. function createIndent(o,domNode,node,level)
  91. {
  92. if (node.parentNode && node.parentNode.parentNode) {
  93. createIndent(o,domNode,node.parentNode,level+1);
  94. }
  95. var imgNode = document.createElement("img");
  96. imgNode.width = 16;
  97. imgNode.height = 22;
  98. if (level==0 && node.childrenData) {
  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. if (node.isLast) {
  106. node.plus_img.src = node.relpath+"ftv2plastnode.png";
  107. } else {
  108. node.plus_img.src = node.relpath+"ftv2pnode.png";
  109. }
  110. node.expanded = false;
  111. } else {
  112. expandNode(o, node, false, false);
  113. }
  114. }
  115. node.expandToggle.appendChild(imgNode);
  116. domNode.appendChild(node.expandToggle);
  117. } else {
  118. domNode.appendChild(imgNode);
  119. }
  120. if (level==0) {
  121. if (node.isLast) {
  122. if (node.childrenData) {
  123. imgNode.src = node.relpath+"ftv2plastnode.png";
  124. } else {
  125. imgNode.src = node.relpath+"ftv2lastnode.png";
  126. domNode.appendChild(imgNode);
  127. }
  128. } else {
  129. if (node.childrenData) {
  130. imgNode.src = node.relpath+"ftv2pnode.png";
  131. } else {
  132. imgNode.src = node.relpath+"ftv2node.png";
  133. domNode.appendChild(imgNode);
  134. }
  135. }
  136. } else {
  137. if (node.isLast) {
  138. imgNode.src = node.relpath+"ftv2blank.png";
  139. } else {
  140. imgNode.src = node.relpath+"ftv2vertline.png";
  141. }
  142. }
  143. imgNode.border = "0";
  144. }
  145. function newNode(o, po, text, link, childrenData, lastNode)
  146. {
  147. var node = new Object();
  148. node.children = Array();
  149. node.childrenData = childrenData;
  150. node.depth = po.depth + 1;
  151. node.relpath = po.relpath;
  152. node.isLast = lastNode;
  153. node.li = document.createElement("li");
  154. po.getChildrenUL().appendChild(node.li);
  155. node.parentNode = po;
  156. node.itemDiv = document.createElement("div");
  157. node.itemDiv.className = "item";
  158. node.labelSpan = document.createElement("span");
  159. node.labelSpan.className = "label";
  160. createIndent(o,node.itemDiv,node,0);
  161. node.itemDiv.appendChild(node.labelSpan);
  162. node.li.appendChild(node.itemDiv);
  163. var a = document.createElement("a");
  164. node.labelSpan.appendChild(a);
  165. node.label = document.createTextNode(text);
  166. node.expanded = false;
  167. a.appendChild(node.label);
  168. if (link) {
  169. var url;
  170. if (link.substring(0,1)=='^') {
  171. url = link.substring(1);
  172. link = url;
  173. } else {
  174. url = node.relpath+link;
  175. }
  176. a.className = stripPath(link.replace('#',':'));
  177. if (link.indexOf('#')!=-1) {
  178. var aname = '#'+link.split('#')[1];
  179. var srcPage = stripPath($(location).attr('pathname'));
  180. var targetPage = stripPath(link.split('#')[0]);
  181. a.href = srcPage!=targetPage ? url : '#';
  182. a.onclick = function(){
  183. storeLink(link);
  184. if (!$(a).parent().parent().hasClass('selected'))
  185. {
  186. $('.item').removeClass('selected');
  187. $('.item').removeAttr('id');
  188. $(a).parent().parent().addClass('selected');
  189. $(a).parent().parent().attr('id','selected');
  190. }
  191. var pos, anchor = $(aname), docContent = $('#doc-content');
  192. if (anchor.parent().attr('class')=='memItemLeft') {
  193. pos = anchor.parent().position().top;
  194. } else if (anchor.position()) {
  195. pos = anchor.position().top;
  196. }
  197. if (pos) {
  198. var dist = Math.abs(Math.min(
  199. pos-docContent.offset().top,
  200. docContent[0].scrollHeight-
  201. docContent.height()-docContent.scrollTop()));
  202. docContent.animate({
  203. scrollTop: pos + docContent.scrollTop() - docContent.offset().top
  204. },Math.max(50,Math.min(500,dist)),function(){
  205. window.location.replace(aname);
  206. });
  207. }
  208. };
  209. } else {
  210. a.href = url;
  211. a.onclick = function() { storeLink(link); }
  212. }
  213. } else {
  214. if (childrenData != null)
  215. {
  216. a.className = "nolink";
  217. a.href = "javascript:void(0)";
  218. a.onclick = node.expandToggle.onclick;
  219. }
  220. }
  221. node.childrenUL = null;
  222. node.getChildrenUL = function() {
  223. if (!node.childrenUL) {
  224. node.childrenUL = document.createElement("ul");
  225. node.childrenUL.className = "children_ul";
  226. node.childrenUL.style.display = "none";
  227. node.li.appendChild(node.childrenUL);
  228. }
  229. return node.childrenUL;
  230. };
  231. return node;
  232. }
  233. function showRoot()
  234. {
  235. var headerHeight = $("#top").height();
  236. var footerHeight = $("#nav-path").height();
  237. var windowHeight = $(window).height() - headerHeight - footerHeight;
  238. (function (){ // retry until we can scroll to the selected item
  239. try {
  240. var navtree=$('#nav-tree');
  241. navtree.scrollTo('#selected',0,{offset:-windowHeight/2});
  242. } catch (err) {
  243. setTimeout(arguments.callee, 0);
  244. }
  245. })();
  246. }
  247. function expandNode(o, node, imm, showRoot)
  248. {
  249. if (node.childrenData && !node.expanded) {
  250. if (typeof(node.childrenData)==='string') {
  251. var varName = node.childrenData;
  252. getScript(node.relpath+varName,function(){
  253. node.childrenData = getData(varName);
  254. expandNode(o, node, imm, showRoot);
  255. }, showRoot);
  256. } else {
  257. if (!node.childrenVisited) {
  258. getNode(o, node);
  259. } if (imm || ($.browser.msie && $.browser.version>8)) {
  260. // somehow slideDown jumps to the start of tree for IE9 :-(
  261. $(node.getChildrenUL()).show();
  262. } else {
  263. $(node.getChildrenUL()).slideDown("fast");
  264. }
  265. if (node.isLast) {
  266. node.plus_img.src = node.relpath+"ftv2mlastnode.png";
  267. } else {
  268. node.plus_img.src = node.relpath+"ftv2mnode.png";
  269. }
  270. node.expanded = true;
  271. }
  272. }
  273. }
  274. function glowEffect(n,duration)
  275. {
  276. n.addClass('glow').delay(duration).queue(function(next){
  277. $(this).removeClass('glow');next();
  278. });
  279. }
  280. function highlightAnchor()
  281. {
  282. var anchor = $($(location).attr('hash'));
  283. if (anchor.parent().attr('class')=='memItemLeft'){
  284. var rows = $('.memberdecls tr[class$="'+
  285. window.location.hash.substring(1)+'"]');
  286. glowEffect(rows.children(),300); // member without details
  287. } else if (anchor.parents().slice(2).prop('tagName')=='TR') {
  288. glowEffect(anchor.parents('div.memitem'),1000); // enum value
  289. } else if (anchor.parent().attr('class')=='fieldtype'){
  290. glowEffect(anchor.parent().parent(),1000); // struct field
  291. } else if (anchor.parent().is(":header")) {
  292. glowEffect(anchor.parent(),1000); // section header
  293. } else {
  294. glowEffect(anchor.next(),1000); // normal member
  295. }
  296. }
  297. function selectAndHighlight(hash,n)
  298. {
  299. var a;
  300. if (hash) {
  301. var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);
  302. a=$('.item a[class$="'+link+'"]');
  303. }
  304. if (a && a.length) {
  305. a.parent().parent().addClass('selected');
  306. a.parent().parent().attr('id','selected');
  307. highlightAnchor();
  308. } else if (n) {
  309. $(n.itemDiv).addClass('selected');
  310. $(n.itemDiv).attr('id','selected');
  311. }
  312. showRoot();
  313. }
  314. function showNode(o, node, index, hash)
  315. {
  316. if (node && node.childrenData) {
  317. if (typeof(node.childrenData)==='string') {
  318. var varName = node.childrenData;
  319. getScript(node.relpath+varName,function(){
  320. node.childrenData = getData(varName);
  321. showNode(o,node,index,hash);
  322. },true);
  323. } else {
  324. if (!node.childrenVisited) {
  325. getNode(o, node);
  326. }
  327. $(node.getChildrenUL()).show();
  328. if (node.isLast) {
  329. node.plus_img.src = node.relpath+"ftv2mlastnode.png";
  330. } else {
  331. node.plus_img.src = node.relpath+"ftv2mnode.png";
  332. }
  333. node.expanded = true;
  334. var n = node.children[o.breadcrumbs[index]];
  335. if (index+1<o.breadcrumbs.length) {
  336. showNode(o,n,index+1,hash);
  337. } else {
  338. if (typeof(n.childrenData)==='string') {
  339. var varName = n.childrenData;
  340. getScript(n.relpath+varName,function(){
  341. n.childrenData = getData(varName);
  342. node.expanded=false;
  343. showNode(o,node,index,hash); // retry with child node expanded
  344. },true);
  345. } else {
  346. var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
  347. if (rootBase=="index" || rootBase=="pages") {
  348. expandNode(o, n, true, true);
  349. }
  350. selectAndHighlight(hash,n);
  351. }
  352. }
  353. }
  354. } else {
  355. selectAndHighlight(hash);
  356. }
  357. }
  358. function getNode(o, po)
  359. {
  360. po.childrenVisited = true;
  361. var l = po.childrenData.length-1;
  362. for (var i in po.childrenData) {
  363. var nodeData = po.childrenData[i];
  364. po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
  365. i==l);
  366. }
  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 (root==NAVTREE[0][1]) {
  392. $('#nav-sync').css('top','30px');
  393. } else {
  394. $('#nav-sync').css('top','5px');
  395. }
  396. if (hash.match(/^#l\d+$/)) {
  397. var anchor=$('a[name='+hash.substring(1)+']');
  398. glowEffect(anchor.parent(),1000); // line number
  399. hash=''; // strip line number anchors
  400. //root=root.replace(/_source\./,'.'); // source link to doc link
  401. }
  402. var url=root+hash;
  403. var i=-1;
  404. while (NAVTREEINDEX[i+1]<=url) i++;
  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. navTo(o,toroot,window.location.hash,relpath);
  467. $(window).bind('hashchange', function(){
  468. if (window.location.hash && window.location.hash.length>1){
  469. var a;
  470. if ($(location).attr('hash')){
  471. var clslink=stripPath($(location).attr('pathname'))+':'+
  472. $(location).attr('hash').substring(1);
  473. a=$('.item a[class$="'+clslink+'"]');
  474. }
  475. if (a==null || !$(a).parent().parent().hasClass('selected')){
  476. $('.item').removeClass('selected');
  477. $('.item').removeAttr('id');
  478. }
  479. var link=stripPath2($(location).attr('pathname'));
  480. navTo(o,link,$(location).attr('hash'),relpath);
  481. }
  482. })
  483. $(window).load(showRoot);
  484. }