navtree.js 15 KB

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