navtree.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. var NAVTREE =
  2. [
  3. [ "CMSIS-RTOS", "index.html", [
  4. [ "Overview", "index.html", null ],
  5. [ "Using a CMSIS RTOS Implementation", "_using_o_s.html", null ],
  6. [ "Function Overview", "_function_overview.html", null ],
  7. [ "Header File Template: cmsis_os.h", "cmsis_os_h.html", null ],
  8. [ "Reference", "modules.html", "modules" ],
  9. [ "Data Structures", "annotated.html", "annotated" ],
  10. [ "Data Structure Index", "classes.html", null ],
  11. [ "Data Fields", "functions.html", [
  12. [ "All", "functions.html", null ],
  13. [ "Variables", "functions_vars.html", null ]
  14. ] ]
  15. ] ]
  16. ];
  17. var NAVTREEINDEX =
  18. [
  19. "_function_overview.html"
  20. ];
  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 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. if (node.parentNode && node.parentNode.parentNode) {
  91. createIndent(o,domNode,node.parentNode,level+1);
  92. }
  93. var imgNode = document.createElement("img");
  94. imgNode.width = 16;
  95. imgNode.height = 22;
  96. if (level==0 && node.childrenData) {
  97. node.plus_img = imgNode;
  98. node.expandToggle = document.createElement("a");
  99. node.expandToggle.href = "javascript:void(0)";
  100. node.expandToggle.onclick = function() {
  101. if (node.expanded) {
  102. $(node.getChildrenUL()).slideUp("fast");
  103. if (node.isLast) {
  104. node.plus_img.src = node.relpath+"ftv2plastnode.png";
  105. } else {
  106. node.plus_img.src = node.relpath+"ftv2pnode.png";
  107. }
  108. node.expanded = false;
  109. } else {
  110. expandNode(o, node, false, false);
  111. }
  112. }
  113. node.expandToggle.appendChild(imgNode);
  114. domNode.appendChild(node.expandToggle);
  115. } else {
  116. domNode.appendChild(imgNode);
  117. }
  118. if (level==0) {
  119. if (node.isLast) {
  120. if (node.childrenData) {
  121. imgNode.src = node.relpath+"ftv2plastnode.png";
  122. } else {
  123. imgNode.src = node.relpath+"ftv2lastnode.png";
  124. domNode.appendChild(imgNode);
  125. }
  126. } else {
  127. if (node.childrenData) {
  128. imgNode.src = node.relpath+"ftv2pnode.png";
  129. } else {
  130. imgNode.src = node.relpath+"ftv2node.png";
  131. domNode.appendChild(imgNode);
  132. }
  133. }
  134. } else {
  135. if (node.isLast) {
  136. imgNode.src = node.relpath+"ftv2blank.png";
  137. } else {
  138. imgNode.src = node.relpath+"ftv2vertline.png";
  139. }
  140. }
  141. imgNode.border = "0";
  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 : '#';
  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 pos, anchor = $(aname), docContent = $('#doc-content');
  190. if (anchor.parent().attr('class')=='memItemLeft') {
  191. pos = anchor.parent().position().top;
  192. } else if (anchor.position()) {
  193. pos = anchor.position().top;
  194. }
  195. if (pos) {
  196. var dist = Math.abs(Math.min(
  197. pos-docContent.offset().top,
  198. docContent[0].scrollHeight-
  199. docContent.height()-docContent.scrollTop()));
  200. docContent.animate({
  201. scrollTop: pos + docContent.scrollTop() - docContent.offset().top
  202. },Math.max(50,Math.min(500,dist)),function(){
  203. window.location.replace(aname);
  204. });
  205. }
  206. };
  207. } else {
  208. a.href = url;
  209. a.onclick = function() { storeLink(link); }
  210. }
  211. } else {
  212. if (childrenData != null)
  213. {
  214. a.className = "nolink";
  215. a.href = "javascript:void(0)";
  216. a.onclick = node.expandToggle.onclick;
  217. }
  218. }
  219. node.childrenUL = null;
  220. node.getChildrenUL = function() {
  221. if (!node.childrenUL) {
  222. node.childrenUL = document.createElement("ul");
  223. node.childrenUL.className = "children_ul";
  224. node.childrenUL.style.display = "none";
  225. node.li.appendChild(node.childrenUL);
  226. }
  227. return node.childrenUL;
  228. };
  229. return node;
  230. }
  231. function showRoot()
  232. {
  233. var headerHeight = $("#top").height();
  234. var footerHeight = $("#nav-path").height();
  235. var windowHeight = $(window).height() - headerHeight - footerHeight;
  236. (function (){ // retry until we can scroll to the selected item
  237. try {
  238. var navtree=$('#nav-tree');
  239. navtree.scrollTo('#selected',0,{offset:-windowHeight/2});
  240. } catch (err) {
  241. setTimeout(arguments.callee, 0);
  242. }
  243. })();
  244. }
  245. function expandNode(o, node, imm, showRoot)
  246. {
  247. if (node.childrenData && !node.expanded) {
  248. if (typeof(node.childrenData)==='string') {
  249. var varName = node.childrenData;
  250. getScript(node.relpath+varName,function(){
  251. node.childrenData = getData(varName);
  252. expandNode(o, node, imm, showRoot);
  253. }, showRoot);
  254. } else {
  255. if (!node.childrenVisited) {
  256. getNode(o, node);
  257. } if (imm || ($.browser.msie && $.browser.version>8)) {
  258. // somehow slideDown jumps to the start of tree for IE9 :-(
  259. $(node.getChildrenUL()).show();
  260. } else {
  261. $(node.getChildrenUL()).slideDown("fast");
  262. }
  263. if (node.isLast) {
  264. node.plus_img.src = node.relpath+"ftv2mlastnode.png";
  265. } else {
  266. node.plus_img.src = node.relpath+"ftv2mnode.png";
  267. }
  268. node.expanded = true;
  269. }
  270. }
  271. }
  272. function glowEffect(n,duration)
  273. {
  274. n.addClass('glow').delay(duration).queue(function(next){
  275. $(this).removeClass('glow');next();
  276. });
  277. }
  278. function highlightAnchor()
  279. {
  280. var anchor = $($(location).attr('hash'));
  281. if (anchor.parent().attr('class')=='memItemLeft'){
  282. var rows = $('.memberdecls tr[class$="'+
  283. window.location.hash.substring(1)+'"]');
  284. glowEffect(rows.children(),300); // member without details
  285. } else if (anchor.parents().slice(2).prop('tagName')=='TR') {
  286. glowEffect(anchor.parents('div.memitem'),1000); // enum value
  287. } else if (anchor.parent().attr('class')=='fieldtype'){
  288. glowEffect(anchor.parent().parent(),1000); // struct field
  289. } else if (anchor.parent().is(":header")) {
  290. glowEffect(anchor.parent(),1000); // section header
  291. } else {
  292. glowEffect(anchor.next(),1000); // normal member
  293. }
  294. }
  295. function selectAndHighlight(hash,n)
  296. {
  297. var a;
  298. if (hash) {
  299. var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);
  300. a=$('.item a[class$="'+link+'"]');
  301. }
  302. if (a && a.length) {
  303. a.parent().parent().addClass('selected');
  304. a.parent().parent().attr('id','selected');
  305. highlightAnchor();
  306. } else if (n) {
  307. $(n.itemDiv).addClass('selected');
  308. $(n.itemDiv).attr('id','selected');
  309. }
  310. showRoot();
  311. }
  312. function showNode(o, node, index, hash)
  313. {
  314. if (node && node.childrenData) {
  315. if (typeof(node.childrenData)==='string') {
  316. var varName = node.childrenData;
  317. getScript(node.relpath+varName,function(){
  318. node.childrenData = getData(varName);
  319. showNode(o,node,index,hash);
  320. },true);
  321. } else {
  322. if (!node.childrenVisited) {
  323. getNode(o, node);
  324. }
  325. $(node.getChildrenUL()).show();
  326. if (node.isLast) {
  327. node.plus_img.src = node.relpath+"ftv2mlastnode.png";
  328. } else {
  329. node.plus_img.src = node.relpath+"ftv2mnode.png";
  330. }
  331. node.expanded = true;
  332. var n = node.children[o.breadcrumbs[index]];
  333. if (index+1<o.breadcrumbs.length) {
  334. showNode(o,n,index+1,hash);
  335. } else {
  336. if (typeof(n.childrenData)==='string') {
  337. var varName = n.childrenData;
  338. getScript(n.relpath+varName,function(){
  339. n.childrenData = getData(varName);
  340. node.expanded=false;
  341. showNode(o,node,index,hash); // retry with child node expanded
  342. },true);
  343. } else {
  344. var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
  345. if (rootBase=="index" || rootBase=="pages") {
  346. expandNode(o, n, true, true);
  347. }
  348. selectAndHighlight(hash,n);
  349. }
  350. }
  351. }
  352. } else {
  353. selectAndHighlight(hash);
  354. }
  355. }
  356. function getNode(o, po)
  357. {
  358. po.childrenVisited = true;
  359. var l = po.childrenData.length-1;
  360. for (var i in po.childrenData) {
  361. var nodeData = po.childrenData[i];
  362. po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
  363. i==l);
  364. }
  365. }
  366. function gotoNode(o,subIndex,root,hash,relpath)
  367. {
  368. var nti = navTreeSubIndices[subIndex][root+hash];
  369. o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);
  370. if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index
  371. navTo(o,NAVTREE[0][1],"",relpath);
  372. $('.item').removeClass('selected');
  373. $('.item').removeAttr('id');
  374. }
  375. if (o.breadcrumbs) {
  376. o.breadcrumbs.unshift(0); // add 0 for root node
  377. showNode(o, o.node, 0, hash);
  378. }
  379. }
  380. function navTo(o,root,hash,relpath)
  381. {
  382. var link = cachedLink();
  383. if (link) {
  384. var parts = link.split('#');
  385. root = parts[0];
  386. if (parts.length>1) hash = '#'+parts[1];
  387. else hash='';
  388. }
  389. if (root==NAVTREE[0][1]) {
  390. $('#nav-sync').css('top','30px');
  391. } else {
  392. $('#nav-sync').css('top','5px');
  393. }
  394. if (hash.match(/^#l\d+$/)) {
  395. var anchor=$('a[name='+hash.substring(1)+']');
  396. glowEffect(anchor.parent(),1000); // line number
  397. hash=''; // strip line number anchors
  398. //root=root.replace(/_source\./,'.'); // source link to doc link
  399. }
  400. var url=root+hash;
  401. var i=-1;
  402. while (NAVTREEINDEX[i+1]<=url) i++;
  403. if (navTreeSubIndices[i]) {
  404. gotoNode(o,i,root,hash,relpath)
  405. } else {
  406. getScript(relpath+'navtreeindex'+i,function(){
  407. navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);
  408. if (navTreeSubIndices[i]) {
  409. gotoNode(o,i,root,hash,relpath);
  410. }
  411. },true);
  412. }
  413. }
  414. function showSyncOff(n,relpath)
  415. {
  416. n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');
  417. }
  418. function showSyncOn(n,relpath)
  419. {
  420. n.html('<img src="'+relpath+'sync_on.png"/ title="'+SYNCONMSG+'">');
  421. }
  422. function toggleSyncButton(relpath)
  423. {
  424. var navSync = $('#nav-sync');
  425. if (navSync.hasClass('sync')) {
  426. navSync.removeClass('sync');
  427. showSyncOff(navSync,relpath);
  428. storeLink(stripPath2($(location).attr('pathname'))+$(location).attr('hash'));
  429. } else {
  430. navSync.addClass('sync');
  431. showSyncOn(navSync,relpath);
  432. deleteLink();
  433. }
  434. }
  435. function initNavTree(toroot,relpath)
  436. {
  437. var o = new Object();
  438. o.toroot = toroot;
  439. o.node = new Object();
  440. o.node.li = document.getElementById("nav-tree-contents");
  441. o.node.childrenData = NAVTREE;
  442. o.node.children = new Array();
  443. o.node.childrenUL = document.createElement("ul");
  444. o.node.getChildrenUL = function() { return o.node.childrenUL; };
  445. o.node.li.appendChild(o.node.childrenUL);
  446. o.node.depth = 0;
  447. o.node.relpath = relpath;
  448. o.node.expanded = false;
  449. o.node.isLast = true;
  450. o.node.plus_img = document.createElement("img");
  451. o.node.plus_img.src = relpath+"ftv2pnode.png";
  452. o.node.plus_img.width = 16;
  453. o.node.plus_img.height = 22;
  454. if (localStorageSupported()) {
  455. var navSync = $('#nav-sync');
  456. if (cachedLink()) {
  457. showSyncOff(navSync,relpath);
  458. navSync.removeClass('sync');
  459. } else {
  460. showSyncOn(navSync,relpath);
  461. }
  462. navSync.click(function(){ toggleSyncButton(relpath); });
  463. }
  464. navTo(o,toroot,window.location.hash,relpath);
  465. $(window).bind('hashchange', function(){
  466. if (window.location.hash && window.location.hash.length>1){
  467. var a;
  468. if ($(location).attr('hash')){
  469. var clslink=stripPath($(location).attr('pathname'))+':'+
  470. $(location).attr('hash').substring(1);
  471. a=$('.item a[class$="'+clslink+'"]');
  472. }
  473. if (a==null || !$(a).parent().parent().hasClass('selected')){
  474. $('.item').removeClass('selected');
  475. $('.item').removeAttr('id');
  476. }
  477. var link=stripPath2($(location).attr('pathname'));
  478. navTo(o,link,$(location).attr('hash'),relpath);
  479. }
  480. })
  481. $(window).load(showRoot);
  482. }