tidy-html5/htmldoc/api/navtree.js

381 lines
11 KiB
JavaScript
Raw Normal View History

2012-03-01 08:54:20 +00:00
var NAVTREE =
[
[ "HTML Tidy", "index.html", [
2012-06-20 07:58:34 +00:00
[ "Deprecated List", "deprecated.html", null ],
[ "Modules", "modules.html", "modules" ],
[ "Data Structures", null, [
[ "Data Structures", "annotated.html", "annotated" ],
[ "Data Fields", "functions.html", [
[ "All", "functions.html", null ],
[ "Functions", "functions_func.html", null ],
[ "Variables", "functions_vars.html", null ]
2012-03-01 08:54:20 +00:00
] ]
] ],
2012-06-20 07:58:34 +00:00
[ "Files", null, [
[ "File List", "files.html", "files" ],
[ "Globals", "globals.html", [
[ "All", "globals.html", null ],
[ "Functions", "globals_func.html", null ],
[ "Typedefs", "globals_type.html", null ],
[ "Defines", "globals_defs.html", null ]
] ]
] ]
2012-03-01 08:54:20 +00:00
] ]
];
2012-06-20 07:58:34 +00:00
function getData(varName)
{
var i = varName.lastIndexOf('/');
var n = i>=0 ? varName.substring(i+1) : varName;
return eval(n);
}
function stripPath(uri)
{
return uri.substring(uri.lastIndexOf('/')+1);
}
function getScript(scriptName,func,show)
{
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();
}
};
head.appendChild(script);
}
2012-03-01 08:54:20 +00:00
function createIndent(o,domNode,node,level)
{
2012-06-20 07:58:34 +00:00
if (node.parentNode && node.parentNode.parentNode) {
2012-03-01 08:54:20 +00:00
createIndent(o,domNode,node.parentNode,level+1);
}
var imgNode = document.createElement("img");
2012-06-20 07:58:34 +00:00
imgNode.width = 16;
imgNode.height = 22;
if (level==0 && node.childrenData) {
2012-03-01 08:54:20 +00:00
node.plus_img = imgNode;
node.expandToggle = document.createElement("a");
node.expandToggle.href = "javascript:void(0)";
2012-06-20 07:58:34 +00:00
node.expandToggle.onclick = function() {
if (node.expanded) {
2012-03-01 08:54:20 +00:00
$(node.getChildrenUL()).slideUp("fast");
2012-06-20 07:58:34 +00:00
if (node.isLast) {
2012-03-01 08:54:20 +00:00
node.plus_img.src = node.relpath+"ftv2plastnode.png";
2012-06-20 07:58:34 +00:00
} else {
2012-03-01 08:54:20 +00:00
node.plus_img.src = node.relpath+"ftv2pnode.png";
}
node.expanded = false;
2012-06-20 07:58:34 +00:00
} else {
expandNode(o, node, false, false);
2012-03-01 08:54:20 +00:00
}
}
node.expandToggle.appendChild(imgNode);
domNode.appendChild(node.expandToggle);
2012-06-20 07:58:34 +00:00
} else {
2012-03-01 08:54:20 +00:00
domNode.appendChild(imgNode);
}
2012-06-20 07:58:34 +00:00
if (level==0) {
if (node.isLast) {
if (node.childrenData) {
2012-03-01 08:54:20 +00:00
imgNode.src = node.relpath+"ftv2plastnode.png";
2012-06-20 07:58:34 +00:00
} else {
2012-03-01 08:54:20 +00:00
imgNode.src = node.relpath+"ftv2lastnode.png";
domNode.appendChild(imgNode);
}
2012-06-20 07:58:34 +00:00
} else {
if (node.childrenData) {
2012-03-01 08:54:20 +00:00
imgNode.src = node.relpath+"ftv2pnode.png";
2012-06-20 07:58:34 +00:00
} else {
2012-03-01 08:54:20 +00:00
imgNode.src = node.relpath+"ftv2node.png";
domNode.appendChild(imgNode);
}
}
2012-06-20 07:58:34 +00:00
} else {
if (node.isLast) {
2012-03-01 08:54:20 +00:00
imgNode.src = node.relpath+"ftv2blank.png";
2012-06-20 07:58:34 +00:00
} else {
2012-03-01 08:54:20 +00:00
imgNode.src = node.relpath+"ftv2vertline.png";
}
}
imgNode.border = "0";
}
function newNode(o, po, text, link, childrenData, lastNode)
{
var node = new Object();
node.children = Array();
node.childrenData = childrenData;
node.depth = po.depth + 1;
node.relpath = po.relpath;
node.isLast = lastNode;
node.li = document.createElement("li");
po.getChildrenUL().appendChild(node.li);
node.parentNode = po;
node.itemDiv = document.createElement("div");
node.itemDiv.className = "item";
node.labelSpan = document.createElement("span");
node.labelSpan.className = "label";
createIndent(o,node.itemDiv,node,0);
node.itemDiv.appendChild(node.labelSpan);
node.li.appendChild(node.itemDiv);
var a = document.createElement("a");
node.labelSpan.appendChild(a);
node.label = document.createTextNode(text);
2012-06-20 07:58:34 +00:00
node.expanded = false;
2012-03-01 08:54:20 +00:00
a.appendChild(node.label);
2012-06-20 07:58:34 +00:00
if (link) {
var url;
if (link.substring(0,1)=='^') {
url = link.substring(1);
link = url;
} else {
url = node.relpath+link;
}
a.className = stripPath(link.replace('#',':'));
if (link.indexOf('#')!=-1) {
var aname = '#'+link.split('#')[1];
var srcPage = stripPath($(location).attr('pathname'));
var targetPage = stripPath(link.split('#')[0]);
a.href = srcPage!=targetPage ? url : '#';
a.onclick = function(){
if (!$(a).parent().parent().hasClass('selected'))
{
$('.item').removeClass('selected');
$('.item').removeAttr('id');
$(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);
});
};
} else {
a.href = url;
}
} else {
2012-03-01 08:54:20 +00:00
if (childrenData != null)
{
a.className = "nolink";
a.href = "javascript:void(0)";
a.onclick = node.expandToggle.onclick;
}
}
node.childrenUL = null;
2012-06-20 07:58:34 +00:00
node.getChildrenUL = function() {
if (!node.childrenUL) {
2012-03-01 08:54:20 +00:00
node.childrenUL = document.createElement("ul");
node.childrenUL.className = "children_ul";
node.childrenUL.style.display = "none";
node.li.appendChild(node.childrenUL);
}
return node.childrenUL;
};
return node;
}
function showRoot()
{
var headerHeight = $("#top").height();
var footerHeight = $("#nav-path").height();
var windowHeight = $(window).height() - headerHeight - footerHeight;
2012-06-20 07:58:34 +00:00
(function (){ // retry until we can scroll to the selected item
try {
navtree.scrollTo('#selected',0,{offset:-windowHeight/2});
} catch (err) {
setTimeout(arguments.callee, 0);
}
})();
2012-03-01 08:54:20 +00:00
}
2012-06-20 07:58:34 +00:00
function expandNode(o, node, imm, showRoot)
2012-03-01 08:54:20 +00:00
{
2012-06-20 07:58:34 +00:00
if (node.childrenData && !node.expanded) {
if (typeof(node.childrenData)==='string') {
var varName = node.childrenData;
getScript(node.relpath+varName,function(){
node.childrenData = getData(varName);
expandNode(o, node, imm, showRoot);
}, showRoot);
} else {
if (!node.childrenVisited) {
getNode(o, node);
} if (imm) {
$(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.expanded = true;
2012-03-01 08:54:20 +00:00
}
2012-06-20 07:58:34 +00:00
}
}
function highlightAnchor()
{
var anchor = $($(location).attr('hash'));
if (anchor.parent().attr('class')=='memItemLeft'){
var rows = $('.memberdecls tr[class$=\""'+
window.location.hash.substring(1)+'"\"]').children();
rows.effect('highlight',{},1500);
} else if (anchor.parent().is(":header")) {
anchor.parent().effect('highlight',{},1500);
} else {
var targetDiv = anchor.next();
$(targetDiv).children('.memproto,.memdoc').effect("highlight",{},1500);
}
}
function showNode(o, node, index)
{
if (node.childrenData /*&& !node.expanded*/) {
if (typeof(node.childrenData)==='string') {
var varName = node.childrenData;
getScript(node.relpath+varName,function(){
node.childrenData = getData(varName);
showNode(o,node,index);
},true);
} else {
if (!node.childrenVisited) {
getNode(o, node);
}
2012-03-01 08:54:20 +00:00
$(node.getChildrenUL()).show();
2012-06-20 07:58:34 +00:00
if (node.isLast) {
node.plus_img.src = node.relpath+"ftv2mlastnode.png";
} else {
node.plus_img.src = node.relpath+"ftv2mnode.png";
}
node.expanded = true;
var n = node.children[o.breadcrumbs[index]];
if (index+1<o.breadcrumbs.length) {
showNode(o,n,index+1);
} 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
},true);
} else {
if (o.toroot=="index.html" || n.childrenData) {
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();
}
}
2012-03-01 08:54:20 +00:00
}
}
}
function getNode(o, po)
{
po.childrenVisited = true;
var l = po.childrenData.length-1;
2012-06-20 07:58:34 +00:00
for (var i in po.childrenData) {
2012-03-01 08:54:20 +00:00
var nodeData = po.childrenData[i];
po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
2012-06-20 07:58:34 +00:00
i==l);
2012-03-01 08:54:20 +00:00
}
}
2012-06-20 07:58:34 +00:00
function navTo(o,root,hash,relpath)
2012-03-01 08:54:20 +00:00
{
2012-06-20 07:58:34 +00:00
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);
2012-03-01 08:54:20 +00:00
}
2012-06-20 07:58:34 +00:00
},true);
2012-03-01 08:54:20 +00:00
}
function initNavTree(toroot,relpath)
{
var o = new Object();
o.toroot = toroot;
o.node = new Object();
o.node.li = document.getElementById("nav-tree-contents");
o.node.childrenData = NAVTREE;
o.node.children = new Array();
o.node.childrenUL = document.createElement("ul");
o.node.getChildrenUL = function() { return o.node.childrenUL; };
o.node.li.appendChild(o.node.childrenUL);
o.node.depth = 0;
o.node.relpath = relpath;
2012-06-20 07:58:34 +00:00
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;
2012-03-01 08:54:20 +00:00
2012-06-20 07:58:34 +00:00
navTo(o,toroot,window.location.hash,relpath);
2012-03-01 08:54:20 +00:00
2012-06-20 07:58:34 +00:00
$(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+'"\"]');
}
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);
}
})
$(window).load(showRoot);
2012-03-01 08:54:20 +00:00
}