var Tree = {
TREE: "tree"
,
MORE: "plus"
,
LESS: "minus"
,
HERE: "here"
,
TOC: "toc"
,
ARTICLE: "article"
,
ini: function() {
if (Tree.reLessmore) return;
Tree.reLessmore=new RegExp(" *("
+Tree.LESS+"|"
+Tree.MORE+") *"
, "gi"
);
Tree.reHere=new RegExp(" *("
+Tree.HERE+") *"
, "gi"
);
},
create: function(nav, article) {
Tree.ini();
if( nav &&
nav.stopPropagation) {
nav=null;
article=null;
}
if (!nav) nav=document.getElementById(Tree.TOC);
if (!article) article=document.getElementById(Tree.ARTICLE);
if(!nav) return;
if (nav.nodeType !=
1
) nav=document.getElementById(nav);
if(!nav) return;
if (article &&
article.nodeType !=
1
) article=document.getElementById(article);
if(!article) article=document.getElementsByTagName("body"
)[0
];
var hList = Tree.getElementsByTagRE(/\bH[1
-9
]\b/i, article);
if(hList.length < 3
) return;
if (document.createElementNS) var tree = document.createElementNS("http://www.w3.org/1999/xhtml"
, 'div'
);
else var tree = document.createElement('div'
);
tree.className="autotoc "
+Tree.TREE;
var ul=tree;
var li;
var level=1
;
var level_plus=0
;
for(var i=0
; i < hList.length; ++i) {
if (document.createElementNS) var a = document.createElementNS("http://www.w3.org/1999/xhtml"
, 'a'
);
else var a = document.createElement('a'
);
var id=hList[i].id;
if (!id) {
id="h_"
+ i;
hList[i].id=id;
}
a.href="#"
+id;
if (hList[i].textContent) {
a.textContent=hList[i].textContent;
} else if (hList[i].innerText) {
a.innerText=hList[i].innerText;
}
var hn=Number(hList[i].nodeName.substring(1
));
if (hn > level) {
if (document.createElementNS) ul=document.createElementNS("http://www.w3.org/1999/xhtml"
, 'ul'
);
else ul = document.createElement('ul'
);
if (li &&
level > level_plus) li.className+=" "
+ Tree.MORE;
if (li) li.appendChild(ul);
}
else if (hn < level) {
for (var j=level - hn ; j> 0
; j--) {
if (ul &&
ul.parentNode &&
ul.parentNode.parentNode &&
ul.parentNode.parentNode.nodeName.toLowerCase() ==
"ul"
)
ul=ul.parentNode.parentNode;
else break;
}
}
level=hn;
if (ul.nodeName.toLowerCase() ==
'div'
) {
if (document.createElementNS) li=document.createElementNS("http://www.w3.org/1999/xhtml"
, 'header'
);
else li=document.createElement('header'
);
li.appendChild(a);
ul.appendChild(li);
li=ul;
continue;
}
if (document.createElementNS) li=document.createElementNS("http://www.w3.org/1999/xhtml"
, 'li'
);
else li=document.createElement('li'
);
li.onclick = function(e) {return Tree.click(this, e);}
li.className=li.className+" "
+hList[i].nodeName.toLowerCase();
li.appendChild(a);
ul.appendChild(li);
}
nav.appendChild(tree);
},
here:""
,
loaded:false,
load: function(id, href) {
Tree.ini(); if (!href) href=location.protocol + "//"
+location.host+location.pathname;
if( id &&
id.stopPropagation) {
id=null;
}
root=id;
if (id &&
typeof id ==
'string'
) root=document.getElementById(id);
if (!root &&
document) root=document.documentElement;
var reHereDel=new RegExp(' *'
+Tree.HERE+' *'
);
var nodeset = root.getElementsByTagName("li"
);
for(var i=0
; i < nodeset.length; ++i) {
li=nodeset[i];
li.onclick = function(e) {return Tree.click(this, e);}
var links=li.getElementsByTagName("a"
);
for(var j=0
; j < links.length; j++) {
a=links[j];
if (
href.indexOf(a.href.replace(/\/$/, ''
)+'/'
) !==
0
&&
(a.href+'/'
).indexOf(href+'/'
) !==
0
) continue;
Tree.open(li);
if (a.className.indexOf(Tree.HERE) !=
-1
) a.className=a.className.replace(reHereDel, ''
);
a.className += " "
+Tree.HERE;
if (li.getElementsByTagName("li"
).length==
0
) {
if (li.className.indexOf(Tree.HERE) !=
-1
) li.className=li.className.replace(reHereDel, ''
);
li.className += " "
+Tree.HERE;
}
}
}
Tree.loaded=true;
},
click: function (li, e) {
Tree.ini(); if(Tree.className !=
null) li=this;
if (!li) return false;
var ret=false;
var className=""
;
if(li.className.indexOf(Tree.LESS) > -1
) className=" "
+Tree.MORE;
else if(li.className.indexOf(Tree.MORE) > -1
) className=" "
+Tree.LESS;
var ev = e ||
event, src = ev.target ||
ev.srcElement;
while (src &&
src.tagName.toLowerCase() !=
"li"
) {
if (src.tagName.toLowerCase() ==
'a'
) {
className=" "
+Tree.LESS;
ret=true;
if (Tree.a) Tree.a.className=Tree.a.className.replace(Tree.reHere, ' '
);
src.className=src.className.replace(Tree.reHere, ' '
) + " "
+Tree.HERE;
Tree.a=src;
break;
}
src = src.parentNode;
}
if (li.className.search(Tree.reLessmore)>-1
) li.className=li.className.replace(Tree.reLessmore, ' '
) + className;
if (ev &&
document.all ) ev.cancelBubble = true;
if (ev &&
ev.stopPropagation) ev.stopPropagation();
return ret;
},
open: function () {
var li; for (i=arguments.length - 1
; i>=
0
; i--) {
li=arguments[i];
if (li.className ==
null) li=document.getElementById(arguments[i]);
if (!li) continue;
while (li &&
li.tagName.toLowerCase() ==
'li'
) {
if (li.className.match(Tree.reLessmore) ||
li.getElementsByTagName('UL'
).length > 0
)
li.className = li.className.replace(Tree.reLessmore, ' '
) +" "
+Tree.LESS;
li=li.parentNode.parentNode; }
}
},
getElementsByTagRE: function(re, node) {
if(!node) node=document.getElementsByTagName("BODY"
)[0
];
var nodeset = node.getElementsByTagName("*"
);
if(!re ||
re ==
"*"
) return nodeset;
if(!re.test) re = new RegExp(re);
re.ignoreCase = true;
var select = [];
for(i = 0
; i < nodeset.length; ++i)
if( re.test(nodeset[i].nodeName.toLowerCase()) ) select.push( nodeset[i] );
return select;
},
props: function(o) {
tmp=''
;
for (x in o) tmp += x + " "
; alert (tmp);
}
}
if(window.document.body) {
}
else {
if (window.addEventListener) {
if (!Tree.loaded) window.addEventListener('load'
, Tree.load, false);
window.addEventListener('load'
, Tree.create, false);
}
else if (window.attachEvent) {
if (!Tree.loaded) window.attachEvent('onload'
, Tree.load);
window.attachEvent('onload'
, Tree.create);
}
}