diff options
Diffstat (limited to 'src/navtree_js.h')
-rw-r--r-- | src/navtree_js.h | 95 |
1 files changed, 82 insertions, 13 deletions
diff --git a/src/navtree_js.h b/src/navtree_js.h index e243466..fee88b3 100644 --- a/src/navtree_js.h +++ b/src/navtree_js.h @@ -20,6 +20,34 @@ " return m ? uri.substring(i-6) : s;\n" "}\n" "\n" +"function localStorageSupported()\n" +"{\n" +" return 'localStorage' in window && window['localStorage'] !== null;\n" +"}\n" +"\n" +"function storeLink(link)\n" +"{\n" +" if (!$(\"#nav-sync\").hasClass('sync') && localStorageSupported()) {\n" +" window.localStorage.setItem('navpath',link);\n" +" }\n" +"}\n" +"\n" +"function deleteLink()\n" +"{\n" +" if (localStorageSupported()) {\n" +" window.localStorage.setItem('navpath','');\n" +" } \n" +"}\n" +"\n" +"function cachedLink()\n" +"{\n" +" if (localStorageSupported()) {\n" +" return window.localStorage.getItem('navpath');\n" +" } else {\n" +" return '';\n" +" }\n" +"}\n" +"\n" "function getScript(scriptName,func,show)\n" "{\n" " var head = document.getElementsByTagName(\"head\")[0]; \n" @@ -138,6 +166,7 @@ " var targetPage = stripPath(link.split('#')[0]);\n" " a.href = srcPage!=targetPage ? url : '#';\n" " a.onclick = function(){\n" +" storeLink(link);\n" " if (!$(a).parent().parent().hasClass('selected'))\n" " {\n" " $('.item').removeClass('selected');\n" @@ -165,6 +194,7 @@ " };\n" " } else {\n" " a.href = url;\n" +" a.onclick = function() { storeLink(link); }\n" " }\n" " } else {\n" " if (childrenData != null) \n" @@ -248,6 +278,8 @@ " glowEffect(rows.children(),300); // member without details\n" " } else if (anchor.parents().slice(2).prop('tagName')=='TR') {\n" " glowEffect(anchor.parents('div.memitem'),1000); // enum value\n" +" } else if (anchor.parent().attr('class')=='fieldtype'){\n" +" glowEffect(anchor.parent().parent(),1000); // struct field\n" " } else if (anchor.parent().is(\":header\")) {\n" " glowEffect(anchor.parent(),1000); // section header\n" " } else {\n" @@ -255,12 +287,11 @@ " }\n" "}\n" "\n" -"function selectAndHighlight(n)\n" +"function selectAndHighlight(hash,n)\n" "{\n" " var a;\n" -" if ($(location).attr('hash')) {\n" -" var link=stripPath($(location).attr('pathname'))+':'+\n" -" $(location).attr('hash').substring(1);\n" +" if (hash) {\n" +" var link=stripPath($(location).attr('pathname'))+':'+hash.substring(1);\n" " a=$('.item a[class$=\"'+link+'\"]');\n" " }\n" " if (a && a.length) {\n" @@ -274,14 +305,14 @@ " showRoot();\n" "}\n" "\n" -"function showNode(o, node, index)\n" +"function showNode(o, node, index, hash)\n" "{\n" " if (node && node.childrenData) {\n" " if (typeof(node.childrenData)==='string') {\n" " var varName = node.childrenData;\n" " getScript(node.relpath+varName,function(){\n" " node.childrenData = getData(varName);\n" -" showNode(o,node,index);\n" +" showNode(o,node,index,hash);\n" " },true);\n" " } else {\n" " if (!node.childrenVisited) {\n" @@ -296,26 +327,26 @@ " node.expanded = true;\n" " var n = node.children[o.breadcrumbs[index]];\n" " if (index+1<o.breadcrumbs.length) {\n" -" showNode(o,n,index+1);\n" +" showNode(o,n,index+1,hash);\n" " } else {\n" " if (typeof(n.childrenData)==='string') {\n" " var varName = n.childrenData;\n" " getScript(n.relpath+varName,function(){\n" " n.childrenData = getData(varName);\n" " node.expanded=false;\n" -" showNode(o,node,index); // retry with child node expanded\n" +" showNode(o,node,index,hash); // retry with child node expanded\n" " },true);\n" " } else {\n" -" var rootBase = o.toroot.replace(/\\..+$/, '');\n" +" var rootBase = stripPath(o.toroot.replace(/\\..+$/, ''));\n" " if (rootBase==\"index\" || rootBase==\"pages\") {\n" " expandNode(o, n, true, true);\n" " }\n" -" selectAndHighlight(n);\n" +" selectAndHighlight(hash,n);\n" " }\n" " }\n" " }\n" " } else {\n" -" selectAndHighlight();\n" +" selectAndHighlight(hash);\n" " }\n" "}\n" "\n" @@ -333,7 +364,7 @@ "function gotoNode(o,subIndex,root,hash,relpath)\n" "{\n" " var nti = navTreeSubIndices[subIndex][root+hash];\n" -" o.breadcrumbs = nti ? nti : navTreeSubIndices[subIndex][root];\n" +" o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);\n" " if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index\n" " navTo(o,NAVTREE[0][1],\"\",relpath);\n" " $('.item').removeClass('selected');\n" @@ -341,16 +372,29 @@ " }\n" " if (o.breadcrumbs) {\n" " o.breadcrumbs.unshift(0); // add 0 for root node\n" -" showNode(o, o.node, 0);\n" +" showNode(o, o.node, 0, hash);\n" " }\n" "}\n" "\n" "function navTo(o,root,hash,relpath)\n" "{\n" +" var link = cachedLink();\n" +" if (link) {\n" +" var parts = link.split('#');\n" +" root = parts[0];\n" +" if (parts.length>1) hash = '#'+parts[1];\n" +" else hash='';\n" +" }\n" +" if (root==NAVTREE[0][1]) {\n" +" $('#nav-sync').css('top','30px');\n" +" } else {\n" +" $('#nav-sync').css('top','5px');\n" +" }\n" " if (hash.match(/^#l\\d+$/)) {\n" " var anchor=$('a[name='+hash.substring(1)+']');\n" " glowEffect(anchor.parent(),1000); // line number\n" " hash=''; // strip line number anchors\n" +" //root=root.replace(/_source\\./,'.'); // source link to doc link\n" " }\n" " var url=root+hash;\n" " var i=-1;\n" @@ -367,6 +411,20 @@ " }\n" "}\n" "\n" +"function toggleSyncButton(relpath)\n" +"{\n" +" var navSync = $('#nav-sync');\n" +" if (navSync.hasClass('sync')) {\n" +" navSync.removeClass('sync');\n" +" navSync.html('<img src=\"'+relpath+'sync_off.png\"/>');\n" +" storeLink(stripPath2($(location).attr('pathname'))+$(location).attr('hash'));\n" +" } else {\n" +" navSync.addClass('sync');\n" +" navSync.html('<img src=\"'+relpath+'sync_on.png\"/>');\n" +" deleteLink();\n" +" }\n" +"}\n" +"\n" "function initNavTree(toroot,relpath)\n" "{\n" " var o = new Object();\n" @@ -387,6 +445,17 @@ " o.node.plus_img.width = 16;\n" " o.node.plus_img.height = 22;\n" "\n" +" if (localStorageSupported()) {\n" +" var navSync = $('#nav-sync');\n" +" if (cachedLink()) {\n" +" navSync.html('<img src=\"'+relpath+'sync_off.png\"/>');\n" +" navSync.removeClass('sync');\n" +" } else {\n" +" navSync.html('<img src=\"'+relpath+'sync_on.png\"/>');\n" +" }\n" +" navSync.click(function(){ toggleSyncButton(relpath); });\n" +" }\n" +"\n" " navTo(o,toroot,window.location.hash,relpath);\n" "\n" " $(window).bind('hashchange', function(){\n" |