navtree.js 14 KB

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