日期:2013-04-02  浏览次数:20516 次

本原码从网上下载,经本人改写,功能更强大,使用更方便,可以有无限级目录,一次性载入,可以分别设置树结点和叶结点的颜色及图标,可以展开和收缩,可以显示当前所处的路径位置,点击树结点时只在展开时显示树结点的超链接,不过,据测试,一次性载入500个节点时浏览器会显示“该脚本会使浏览器变慢”的提示,不过,选择不取消执行不会影响浏览器的性能。
function folder(folderdescription, hreference,parentid,target) {
 //constant data;

 this.desc = folderdescription;
 this.parentid=parentid;
 this.hreference = hreference;
 this.target=target;
 this.id = index;
 this.navobj = 0;
 this.iconimg = 0;
 this.nodeimg = 0;
 this.islastnode = 0;

 // dynamic data
 this.isroot = true;
 this.isopen = true;
 this.iconsrc=imageurl+"ftv2folderopen.gif";
 this.iconroot =imageurl+"ftv2folderopen.gif";

 this.children = new array;
 this.nchildren = 0;

 // methods
 this.initialize = initializefolder;
 this.setstate = setstatefolder;
 this.addchild = addchild;

 this.createindex = createentryindex;
 this.hide = hidefolder;
 this.display = display;
 this.renderob = drawfolder;
 this.totalheight = totalheight;
 this.subentries = foldersubentries;
 this.outputlink = outputfolderlink;

}


function setstatefolder(isopen) {
 var subentries;
 var totalheight;
 var fit = 0;
 var i = 0;

 if(isopen == this.isopen)
 return;

 if(browserversion == 2) {
 totalheight = 0
 for(i = 0; i < this.nchildren; i++)
 totalheight = totalheight + this.children[i].navobj.clip.height;
 subentries = this.subentries();

 if(this.isopen)
 totalheight = 0 - totalheight;

 for(fit = this.id + subentries + 1; fit < nentries; fit++)
 indexofentries[fit].navobj.moveby(0, totalheight);
 }

 this.isopen = isopen;
 propagatechangesinstate(this);
}


function propagatechangesinstate(folder) {

 var i = 0;
 if(folder.isopen) {
 if(folder.nodeimg) {
 if(folder.islastnode)
 folder.nodeimg.src = imageurl+"ftv2mlastnode.gif";
 else
 folder.nodeimg.src = imageurl+"ftv2mnode.gif";
 }

 if(this.isroot)
 folder.iconimg.src = imageurl+"ftv2_mail.gif";
 else
 folder.iconimg.src = imageurl+"ftv2folderopen.gif";

 for(i = 0; i < folder.nchildren; i++)
 folder.children[i].display();
 }
 else {
 if(folder.nodeimg) {
 if(folder.islastnode)

 folder.nodeimg.src = imageurl+"ftv2plastnode.gif";
 else
 folder.nodeimg.src = imageurl+"ftv2pnode.gif";
 }

 if(this.isroot)
 folder.iconimg.src = imageurl+"ftv2_mail.gif";
 else
 folder.iconimg.src = imageurl+"ftv2folderclosed.gif";

 for(i = 0; i < folder.nchildren; i++)
 folder.children[i].hide();
 }
}

function hidefolder() {
if(browserversion == 1) {
if(this.navobj.style.display == "none")
return;

this.navobj.style.display = "none";
}
else {
if(this.navobj.visibility == "hiden")
return;

this.navobj.visibility = "hiden";
}

this.setstate(0);
}


function initializefolder(level, lastnode, leftside) {
var i = 0;
var j = 0;

var numberoffolders;
var numberofdocs;

nc = this.nchildren;
this.createindex();

var nc;
var auxev = "";

if(browserversion > 0)
auxev = "<a href='javascript: clickonnode("+this.id+")'>";
else
auxev = "<a>";

if(level > 0) {
if(lastnode)