Mercurial > hg > vamp-docs
diff code-docs/navtree.js @ 6:27319718b1f8 vamp-plugin-sdk-v2.7
Update code docs to v2.7 SDK
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2017 16:44:47 +0000 |
parents | 5c2683745b33 |
children |
line wrap: on
line diff
--- a/code-docs/navtree.js Tue Dec 03 16:43:33 2013 +0000 +++ b/code-docs/navtree.js Fri Feb 24 16:44:47 2017 +0000 @@ -1,47 +1,12 @@ -var NAVTREE = -[ - [ "VampPluginSDK", "index.html", [ - [ "Vamp Plugin SDK", "index.html", null ], - [ "Namespaces", null, [ - [ "Namespace List", "namespaces.html", "namespaces" ], - [ "Namespace Members", "namespacemembers.html", [ - [ "All", "namespacemembers.html", null ], - [ "Functions", "namespacemembers_func.html", null ] - ] ] - ] ], - [ "Classes", null, [ - [ "Class List", "annotated.html", "annotated" ], - [ "Class Hierarchy", "hierarchy.html", "hierarchy" ], - [ "Class Members", "functions.html", [ - [ "All", "functions.html", "functions_dup" ], - [ "Functions", "functions_func.html", "functions_func" ], - [ "Variables", "functions_vars.html", null ], - [ "Typedefs", "functions_type.html", null ], - [ "Enumerations", "functions_enum.html", null ], - [ "Enumerator", "functions_eval.html", null ] - ] ] - ] ], - [ "Files", null, [ - [ "File List", "files.html", "files" ], - [ "File Members", "globals.html", [ - [ "All", "globals.html", null ], - [ "Functions", "globals_func.html", null ], - [ "Variables", "globals_vars.html", null ], - [ "Typedefs", "globals_type.html", null ], - [ "Enumerations", "globals_enum.html", null ], - [ "Enumerator", "globals_eval.html", null ], - [ "Defines", "globals_defs.html", null ] - ] ] - ] ], - [ "Directories", "dirs.html", "dirs" ] - ] ] -]; +var navTreeSubIndices = new Array(); +var arrowDown = '▼'; +var arrowRight = '►'; function getData(varName) { var i = varName.lastIndexOf('/'); var n = i>=0 ? varName.substring(i+1) : varName; - return eval(n); + return eval(n.replace(/\-/g,'_')); } function stripPath(uri) @@ -49,42 +14,99 @@ return uri.substring(uri.lastIndexOf('/')+1); } +function stripPath2(uri) +{ + var i = uri.lastIndexOf('/'); + var s = uri.substring(i+1); + var m = uri.substring(0,i+1).match(/\/d\w\/d\w\w\/$/); + return m ? uri.substring(i-6) : s; +} + +function hashValue() +{ + return $(location).attr('hash').substring(1).replace(/[^\w\-]/g,''); +} + +function hashUrl() +{ + return '#'+hashValue(); +} + +function pathName() +{ + return $(location).attr('pathname').replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/g, ''); +} + +function localStorageSupported() +{ + try { + return 'localStorage' in window && window['localStorage'] !== null && window.localStorage.getItem; + } + catch(e) { + return false; + } +} + + +function storeLink(link) +{ + if (!$("#nav-sync").hasClass('sync') && localStorageSupported()) { + window.localStorage.setItem('navpath',link); + } +} + +function deleteLink() +{ + if (localStorageSupported()) { + window.localStorage.setItem('navpath',''); + } +} + +function cachedLink() +{ + if (localStorageSupported()) { + return window.localStorage.getItem('navpath'); + } else { + return ''; + } +} + function getScript(scriptName,func,show) { - var head = document.getElementsByTagName("head")[0]; + var head = document.getElementsByTagName("head")[0]; var script = document.createElement('script'); script.id = scriptName; script.type = 'text/javascript'; - script.onload = func; - script.src = scriptName+'.js'; - script.onreadystatechange = function() { - if (script.readyState=='complete' || script.readyState=='loaded') { - func(); if (show) showRoot(); + script.onload = func; + script.src = scriptName+'.js'; + if ($.browser.msie && $.browser.version<=8) { + // script.onload does not work with older versions of IE + script.onreadystatechange = function() { + if (script.readyState=='complete' || script.readyState=='loaded') { + func(); if (show) showRoot(); + } } - }; + } head.appendChild(script); } function createIndent(o,domNode,node,level) { - if (node.parentNode && node.parentNode.parentNode) { - createIndent(o,domNode,node.parentNode,level+1); - } - var imgNode = document.createElement("img"); - imgNode.width = 16; - imgNode.height = 22; - if (level==0 && node.childrenData) { + var level=-1; + var n = node; + while (n.parentNode) { level++; n=n.parentNode; } + if (node.childrenData) { + var imgNode = document.createElement("span"); + imgNode.className = 'arrow'; + imgNode.style.paddingLeft=(16*level).toString()+'px'; + imgNode.innerHTML=arrowRight; node.plus_img = imgNode; node.expandToggle = document.createElement("a"); node.expandToggle.href = "javascript:void(0)"; node.expandToggle.onclick = function() { if (node.expanded) { $(node.getChildrenUL()).slideUp("fast"); - if (node.isLast) { - node.plus_img.src = node.relpath+"ftv2plastnode.png"; - } else { - node.plus_img.src = node.relpath+"ftv2pnode.png"; - } + node.plus_img.innerHTML=arrowRight; node.expanded = false; } else { expandNode(o, node, false, false); @@ -93,32 +115,42 @@ node.expandToggle.appendChild(imgNode); domNode.appendChild(node.expandToggle); } else { - domNode.appendChild(imgNode); + var span = document.createElement("span"); + span.className = 'arrow'; + span.style.width = 16*(level+1)+'px'; + span.innerHTML = ' '; + domNode.appendChild(span); } - if (level==0) { - if (node.isLast) { - if (node.childrenData) { - imgNode.src = node.relpath+"ftv2plastnode.png"; - } else { - imgNode.src = node.relpath+"ftv2lastnode.png"; - domNode.appendChild(imgNode); - } - } else { - if (node.childrenData) { - imgNode.src = node.relpath+"ftv2pnode.png"; - } else { - imgNode.src = node.relpath+"ftv2node.png"; - domNode.appendChild(imgNode); - } - } - } else { - if (node.isLast) { - imgNode.src = node.relpath+"ftv2blank.png"; - } else { - imgNode.src = node.relpath+"ftv2vertline.png"; - } +} + +var animationInProgress = false; + +function gotoAnchor(anchor,aname,updateLocation) +{ + var pos, docContent = $('#doc-content'); + var ancParent = $(anchor.parent()); + if (ancParent.hasClass('memItemLeft') || + ancParent.hasClass('fieldname') || + ancParent.hasClass('fieldtype') || + ancParent.is(':header')) + { + pos = ancParent.position().top; + } else if (anchor.position()) { + pos = anchor.position().top; } - imgNode.border = "0"; + if (pos) { + var dist = Math.abs(Math.min( + pos-docContent.offset().top, + docContent[0].scrollHeight- + docContent.height()-docContent.scrollTop())); + animationInProgress=true; + docContent.animate({ + scrollTop: pos + docContent.scrollTop() - docContent.offset().top + },Math.max(50,Math.min(500,dist)),function(){ + if (updateLocation) window.location.href=aname; + animationInProgress=false; + }); + } } function newNode(o, po, text, link, childrenData, lastNode) @@ -160,10 +192,11 @@ a.className = stripPath(link.replace('#',':')); if (link.indexOf('#')!=-1) { var aname = '#'+link.split('#')[1]; - var srcPage = stripPath($(location).attr('pathname')); + var srcPage = stripPath(pathName()); var targetPage = stripPath(link.split('#')[0]); - a.href = srcPage!=targetPage ? url : '#'; + a.href = srcPage!=targetPage ? url : "javascript:void(0)"; a.onclick = function(){ + storeLink(link); if (!$(a).parent().parent().hasClass('selected')) { $('.item').removeClass('selected'); @@ -171,27 +204,15 @@ $(a).parent().parent().addClass('selected'); $(a).parent().parent().attr('id','selected'); } - var pos, anchor = $(aname), docContent = $('#doc-content'); - if (anchor.parent().attr('class')=='memItemLeft') { - pos = anchor.parent().position().top; - } else { - pos = anchor.position().top; - } - var dist = Math.abs(Math.min( - pos-docContent.offset().top, - docContent[0].scrollHeight- - docContent.height()-docContent.scrollTop())); - docContent.animate({ - scrollTop: pos + docContent.scrollTop() - docContent.offset().top - },Math.max(50,Math.min(500,dist)),function(){ - window.location.replace(aname); - }); + var anchor = $(aname); + gotoAnchor(anchor,aname,true); }; } else { a.href = url; + a.onclick = function() { storeLink(link); } } } else { - if (childrenData != null) + if (childrenData != null) { a.className = "nolink"; a.href = "javascript:void(0)"; @@ -220,6 +241,7 @@ var windowHeight = $(window).height() - headerHeight - footerHeight; (function (){ // retry until we can scroll to the selected item try { + var navtree=$('#nav-tree'); navtree.scrollTo('#selected',0,{offset:-windowHeight/2}); } catch (err) { setTimeout(arguments.callee, 0); @@ -239,94 +261,124 @@ } else { if (!node.childrenVisited) { getNode(o, node); - } if (imm) { + } if (imm || ($.browser.msie && $.browser.version>8)) { + // somehow slideDown jumps to the start of tree for IE9 :-( $(node.getChildrenUL()).show(); } else { $(node.getChildrenUL()).slideDown("fast"); } - if (node.isLast) { - node.plus_img.src = node.relpath+"ftv2mlastnode.png"; - } else { - node.plus_img.src = node.relpath+"ftv2mnode.png"; - } + node.plus_img.innerHTML = arrowDown; node.expanded = true; } } } +function glowEffect(n,duration) +{ + n.addClass('glow').delay(duration).queue(function(next){ + $(this).removeClass('glow');next(); + }); +} + function highlightAnchor() { - var anchor = $($(location).attr('hash')); + var aname = hashUrl(); + var anchor = $(aname); if (anchor.parent().attr('class')=='memItemLeft'){ - var rows = $('.memberdecls tr[class$=\""'+ - window.location.hash.substring(1)+'"\"]').children(); - rows.effect('highlight',{},1500); + var rows = $('.memberdecls tr[class$="'+hashValue()+'"]'); + glowEffect(rows.children(),300); // member without details + } else if (anchor.parent().attr('class')=='fieldname'){ + glowEffect(anchor.parent().parent(),1000); // enum value + } else if (anchor.parent().attr('class')=='fieldtype'){ + glowEffect(anchor.parent().parent(),1000); // struct field } else if (anchor.parent().is(":header")) { - anchor.parent().effect('highlight',{},1500); + glowEffect(anchor.parent(),1000); // section header } else { - var targetDiv = anchor.next(); - $(targetDiv).children('.memproto,.memdoc').effect("highlight",{},1500); + glowEffect(anchor.next(),1000); // normal member } + gotoAnchor(anchor,aname,false); } -function showNode(o, node, index) +function selectAndHighlight(hash,n) { - if (node.childrenData /*&& !node.expanded*/) { + var a; + if (hash) { + var link=stripPath(pathName())+':'+hash.substring(1); + a=$('.item a[class$="'+link+'"]'); + } + if (a && a.length) { + a.parent().parent().addClass('selected'); + a.parent().parent().attr('id','selected'); + highlightAnchor(); + } else if (n) { + $(n.itemDiv).addClass('selected'); + $(n.itemDiv).attr('id','selected'); + } + if ($('#nav-tree-contents .item:first').hasClass('selected')) { + $('#nav-sync').css('top','30px'); + } else { + $('#nav-sync').css('top','5px'); + } + showRoot(); +} + +function showNode(o, node, index, hash) +{ + if (node && node.childrenData) { if (typeof(node.childrenData)==='string') { var varName = node.childrenData; getScript(node.relpath+varName,function(){ node.childrenData = getData(varName); - showNode(o,node,index); + showNode(o,node,index,hash); },true); } else { if (!node.childrenVisited) { getNode(o, node); } - $(node.getChildrenUL()).show(); - if (node.isLast) { - node.plus_img.src = node.relpath+"ftv2mlastnode.png"; - } else { - node.plus_img.src = node.relpath+"ftv2mnode.png"; - } + $(node.getChildrenUL()).css({'display':'block'}); + node.plus_img.innerHTML = arrowDown; node.expanded = true; var n = node.children[o.breadcrumbs[index]]; if (index+1<o.breadcrumbs.length) { - showNode(o,n,index+1); + showNode(o,n,index+1,hash); } else { if (typeof(n.childrenData)==='string') { var varName = n.childrenData; getScript(n.relpath+varName,function(){ n.childrenData = getData(varName); node.expanded=false; - showNode(o,node,index); // retry with child node expanded + showNode(o,node,index,hash); // retry with child node expanded },true); } else { - if (o.toroot=="index.html" || n.childrenData) { + var rootBase = stripPath(o.toroot.replace(/\..+$/, '')); + if (rootBase=="index" || rootBase=="pages" || rootBase=="search") { expandNode(o, n, true, true); } - var a; - if ($(location).attr('hash')) { - var link=stripPath($(location).attr('pathname'))+':'+ - $(location).attr('hash').substring(1); - a=$('.item a[class$=\""'+link+'"\"]'); - } - if (a && a.length) { - a.parent().parent().addClass('selected'); - a.parent().parent().attr('id','selected'); - highlightAnchor(); - } else { - $(n.itemDiv).addClass('selected'); - $(n.itemDiv).attr('id','selected'); - } - showRoot(); + selectAndHighlight(hash,n); } } } + } else { + selectAndHighlight(hash); } } +function removeToInsertLater(element) { + var parentNode = element.parentNode; + var nextSibling = element.nextSibling; + parentNode.removeChild(element); + return function() { + if (nextSibling) { + parentNode.insertBefore(element, nextSibling); + } else { + parentNode.appendChild(element); + } + }; +} + function getNode(o, po) { + var insertFunction = removeToInsertLater(po.li); po.childrenVisited = true; var l = po.childrenData.length-1; for (var i in po.childrenData) { @@ -334,20 +386,76 @@ po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2], i==l); } + insertFunction(); +} + +function gotoNode(o,subIndex,root,hash,relpath) +{ + var nti = navTreeSubIndices[subIndex][root+hash]; + o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]); + if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index + navTo(o,NAVTREE[0][1],"",relpath); + $('.item').removeClass('selected'); + $('.item').removeAttr('id'); + } + if (o.breadcrumbs) { + o.breadcrumbs.unshift(0); // add 0 for root node + showNode(o, o.node, 0, hash); + } } function navTo(o,root,hash,relpath) { - getScript(relpath+"navtreeindex",function(){ - var navTreeIndex = eval('NAVTREEINDEX'); - if (navTreeIndex) { - var nti = navTreeIndex[root+hash]; - o.breadcrumbs = nti ? nti : navTreeIndex[root]; - if (o.breadcrumbs==null) o.breadcrumbs = navTreeIndex["index.html"]; - o.breadcrumbs.unshift(0); - showNode(o, o.node, 0); - } - },true); + var link = cachedLink(); + if (link) { + var parts = link.split('#'); + root = parts[0]; + if (parts.length>1) hash = '#'+parts[1].replace(/[^\w\-]/g,''); + else hash=''; + } + if (hash.match(/^#l\d+$/)) { + var anchor=$('a[name='+hash.substring(1)+']'); + glowEffect(anchor.parent(),1000); // line number + hash=''; // strip line number anchors + } + var url=root+hash; + var i=-1; + while (NAVTREEINDEX[i+1]<=url) i++; + if (i==-1) { i=0; root=NAVTREE[0][1]; } // fallback: show index + if (navTreeSubIndices[i]) { + gotoNode(o,i,root,hash,relpath) + } else { + getScript(relpath+'navtreeindex'+i,function(){ + navTreeSubIndices[i] = eval('NAVTREEINDEX'+i); + if (navTreeSubIndices[i]) { + gotoNode(o,i,root,hash,relpath); + } + },true); + } +} + +function showSyncOff(n,relpath) +{ + n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>'); +} + +function showSyncOn(n,relpath) +{ + n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>'); +} + +function toggleSyncButton(relpath) +{ + var navSync = $('#nav-sync'); + if (navSync.hasClass('sync')) { + navSync.removeClass('sync'); + showSyncOff(navSync,relpath); + storeLink(stripPath2(pathName())+hashUrl()); + } else { + navSync.addClass('sync'); + showSyncOn(navSync,relpath); + deleteLink(); + } } function initNavTree(toroot,relpath) @@ -365,30 +473,45 @@ o.node.relpath = relpath; o.node.expanded = false; o.node.isLast = true; - o.node.plus_img = document.createElement("img"); - o.node.plus_img.src = relpath+"ftv2pnode.png"; - o.node.plus_img.width = 16; - o.node.plus_img.height = 22; + o.node.plus_img = document.createElement("span"); + o.node.plus_img.className = 'arrow'; + o.node.plus_img.innerHTML = arrowRight; - navTo(o,toroot,window.location.hash,relpath); + if (localStorageSupported()) { + var navSync = $('#nav-sync'); + if (cachedLink()) { + showSyncOff(navSync,relpath); + navSync.removeClass('sync'); + } else { + showSyncOn(navSync,relpath); + } + navSync.click(function(){ toggleSyncButton(relpath); }); + } + + $(window).load(function(){ + navTo(o,toroot,hashUrl(),relpath); + showRoot(); + }); $(window).bind('hashchange', function(){ if (window.location.hash && window.location.hash.length>1){ var a; if ($(location).attr('hash')){ - var clslink=stripPath($(location).attr('pathname'))+':'+ - $(location).attr('hash').substring(1); - a=$('.item a[class$=\""'+clslink+'"\"]'); + var clslink=stripPath(pathName())+':'+hashValue(); + a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]'); } if (a==null || !$(a).parent().parent().hasClass('selected')){ $('.item').removeClass('selected'); $('.item').removeAttr('id'); } - var link=stripPath($(location).attr('pathname')); - navTo(o,link,$(location).attr('hash'),relpath); + var link=stripPath2(pathName()); + navTo(o,link,hashUrl(),relpath); + } else if (!animationInProgress) { + $('#doc-content').scrollTop(0); + $('.item').removeClass('selected'); + $('.item').removeAttr('id'); + navTo(o,toroot,hashUrl(),relpath); } }) - - $(window).load(showRoot); }