/*
* Content-seperated javascript tree widget
* Copyright (C) 2005 SilverStripe Limited
* Feel free to use this on your websites, but please leave this message in the fies
* http://www.silverstripe.com/blog
*/
/*
* Initialise all trees identified by
*/
function autoInit_trees() {
var candidates = document.getElementsByTagName('ul');
for(var i=0;i startingPoint) li.insertBefore(spanA, li.childNodes[startingPoint]);
else li.appendChild(spanA);
// Process the children
if(childUL != null) {
if(initTree(childUL)) {
addClass(li, 'children', 'closed');
addClass(spanA, 'children', 'spanClosed');
}
}
}
}
if(li) {
// li and spanA will still be set to the last item
addClass(li, 'last', 'closed');
addClass(spanA, 'last', 'spanClosed');
return true;
} else {
return false;
}
}
/*
* +/- toggle the tree, where el is the node
* force, will force it to "open" or "close"
*/
function treeToggle(el, force) {
el = this;
while(el != null && (!el.tagName || el.tagName.toLowerCase() != "li")) el = el.parentNode;
// Get UL within the LI
var childSet = findChildWithTag(el, 'ul');
var topSpan = findChildWithTag(el, 'span');
if( force != null ){
if( force == "open"){
treeOpen( topSpan, el )
}
else if( force == "close" ){
treeClose( topSpan, el )
}
}
else if( childSet != null) {
// Is open, close it
if(!el.className.match(/(^| )closed($| )/)) {
treeClose( topSpan, el )
// Is closed, open it
} else {
treeOpen( topSpan, el )
}
}
}
function treeOpen( a, b ){
removeClass(a,'spanClosed');
removeClass(b,'closed');
}
function treeClose( a, b ){
addClass(a,'spanClosed');
addClass(b,'closed');
}
/*
* Find the a child of el of type tag
*/
function findChildWithTag(el, tag) {
for(var i=0;i