Heim >php教程 >php手册 >一个很实用和好用的资源管理器的树形目录源码

一个很实用和好用的资源管理器的树形目录源码

WBOY
WBOYOriginal
2016-06-21 09:05:251145Durchsuche

本原码从网上下载,经本人改写,功能更强大,使用更方便,可以有无限级目录,一次性载入,可以分别设置树结点和叶结点的颜色及图标,可以展开和收缩,可以显示当前所处的路径位置,点击树结点时只在展开时显示树结点的超链接,不过,据测试,一次性载入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  totalheight = totalheight + this.children[i].navobj.clip.height;
 subentries = this.subentries();

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

 for(fit = this.id + subentries + 1; 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.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.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 = "";
else
auxev = "
";

if(level > 0) {
if(lastnode) { //the last 'brother' in the children array
 this.renderob(leftside + auxev + "一个很实用和好用的资源管理器的树形目录源码");
 leftside = leftside + "一个很实用和好用的资源管理器的树形目录源码";
 this.islastnode = 1;
}
else {
this.renderob(leftside + auxev + "一个很实用和好用的资源管理器的树形目录源码");
leftside = leftside + "一个很实用和好用的资源管理器的树形目录源码";
this.islastnode = 0;
}
}
else {
this.renderob("");
}

if(nc > 0) {
level = level + 1;
for(i = 0; i if(i == this.nchildren-1)
this.children[i].initialize(level, 1, leftside);
else
this.children[i].initialize(level, 0, leftside);
}
}
}


function drawfolder(leftside) {
if(browserversion == 2) {
if(!doc.ypos)
doc.ypos = 8;

doc.write("");
}
doc.write("

if(browserversion == 1)
doc.write(" id='folder" + this.id + "' style='position:block;' ");

doc.write(" border=0 cellspacing=0 cellpadding=0>");
doc.write("

");
doc.write("
");
doc.write(leftside);

this.outputlink();

doc.write("一个很实用和好用的资源管理器的树形目录源码if(leftside == '') {
doc.write("src='" + this.iconroot+"' border=0>");
}
else {
doc.write("src='" + this.iconsrc+"' border=0>");
}

doc.write("

");

doc.write("

");

if(leftside == '') {
 if(usetextlinks) {
this.outputlink();
doc.write(''+this.desc + "");
 }
 else
 doc.write(this.desc);
}
else {
doc.write("");
doc.write(''+this.desc + "
");
}

doc.write("

");
doc.write("
");

if(browserversion == 2) {
doc.write("");
}

if(browserversion == 1) {
this.navobj = doc.all["folder"+this.id];
this.iconimg = doc.all["foldericon"+this.id]
this.nodeimg = doc.all["nodeicon"+this.id]
}
else if(browserversion == 2) {
this.navobj = doc.layers["folder"+this.id];
this.iconimg = this.navobj.document.images["foldericon"+this.id];
this.nodeimg = this.navobj.document.images["nodeicon"+this.id];
doc.ypos = doc.ypos + this.navobj.clip.height;
}
}




function outputfolderlink() {
if(this.hreference && this.target) {
doc.write("

if(browserversion > 0) {
doc.write("onclick='javascript: clickonfolder("+this.id+")'")
}
doc.write(">")
}
else
doc.write("
")
}


function addchild(childnode) {
 selectfile[fentries]=childnode.desc;
 fentries++;
 this.children[this.nchildren] = childnode;
 this.nchildren++;
 return(childnode);
}


function foldersubentries() {
var i = 0;
var se = this.nchildren;

for(i = 0; i if(this.children[i].children) //is a folder
se = se + this.children[i].subentries();
}

return(se)
}


// definition of class item (a document or link inside a folder)

function item(itemdescription, hreference, itemlink, itemimg,parentid) // constructor
{
// constant data
this.desc = itemdescription
this.link = itemlink
this.hreference = hreference;
this.id =index;
this.navobj = 0; //initialized in render()
this.iconimg = 0; //initialized in render()

// iconsrc俊 瘤沥登绰 捞固瘤 颇老阑 阿 酒捞袍俊 嘎霸 瘤沥且 荐 乐档废 茄促 (格钎)
this.iconsrc = itemimg;

// methods
this.initialize = initializeitem ;
this.createindex = createentryindex;
this.hide = hideitem;
this.display = display;
this.renderob = drawitem;
this.totalheight = totalheight;

this.parentid=parentid;
//alert(this.parent);
}


function hideitem() {
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";
}
}


function initializeitem(level, lastnode, leftside) {
this.createindex();

if(level > 0) {
if(lastnode) { //the last 'brother' in the children array
this.renderob(leftside + "一个很实用和好用的资源管理器的树形目录源码")
leftside = leftside + "一个很实用和好用的资源管理器的树形目录源码"
}
else {
this.renderob(leftside + "一个很实用和好用的资源管理器的树形目录源码")
leftside = leftside + "一个很实用和好用的资源管理器的树形目录源码"
}
}
else
this.renderob("")
}


function drawitem(leftside) {

if(browserversion == 2)
doc.write("");

doc.write("

if(browserversion == 1)
doc.write(" id='item" + this.id + "' style='position:block;' ");
doc.write(" border=0 cellspacing=0 cellpadding=0>");
doc.write(" ");
doc.write(leftside);

if(this.link != "") doc.write("");
doc.write("一个很实用和好用的资源管理器的树形目录源码doc.write("src='"+this.iconsrc+"' border=0>")

if(this.link != "")
doc.write("");

doc.write("

");
doc.write("
");
if(usetextlinks) {
if(this.link != "")
 doc.write("'+ this.desc + "");
else
doc.write(this.desc);
}
else {
doc.write(this.desc);
}

doc.write("

");
doc.write("")

if(browserversion == 2)
doc.write("");

if(browserversion == 1) {
this.navobj = doc.all["item"+this.id]
this.iconimg = doc.all["itemicon"+this.id]
}
else if(browserversion == 2) {
this.navobj = doc.layers["item"+this.id];
this.iconimg = this.navobj.document.images["itemicon"+this.id];
doc.ypos = doc.ypos+this.navobj.clip.height;
}
}

function addposition(id,str1){
if(id>0){
 clickedfolder = indexofentries[id];
 parentid=clickedfolder.parentid;
 parentname=indexofentries[parentid];
 pa=parentname.desc;
 if(parentid==0)str=pa+str1;
 else str='—>'+pa+str1;
 addposition(parentid,str);

}
}
var str="";
function veiwfile (msg) {
var typelogo=typeof top.logo;
if(typelogo=="undefined")return;
var tpyeframe=typeof top.logo.top1;
if(tpyeframe=="undefined")return;
objdocument= top.logo.top1;
var foldertext="";
if(msg==0)foldertext=selectfile[msg];
else {
 str='—>'+selectfile[msg];
 addposition(msg,str);
 foldertext=str;
}
objdocument.document.open();
objdocument.document.write(' 当前位置: '+foldertext+"");
objdocument.document.close();
}

// methods common to both objects (pseudo-inheritance)
function display() {
if(browserversion == 1)
this.navobj.style.display = "block";
else
this.navobj.visibility = "show";
}


function createentryindex() {
indexofentries[nentries] = this;
nentries++;
}


// total height of subentries open
function totalheight() { //used with browserversion == 2
var h = this.navobj.clip.height;
var i = 0;

if(this.isopen) { // is a folder and _is_ open
for(i = 0 ; i h = h + this.children[i].totalheight();
}
return h
}


// events

function clickonfolder(folderid) {
var clicked = indexofentries[folderid];
if(!clicked.isopen)
clickonnode(folderid);
if(clicked.isselected)
return;
}


function clickonnode(folderid) {
var clickedfolder = 0;
var state = 0;
clickedfolder = indexofentries[folderid];
state = clickedfolder.isopen;
if (!state){
 if(clickedfolder.target)clickedfolder.target.location=clickedfolder.hreference; //点击folder时显示相关链接页面
 veiwfile(folderid);
 }
clickedfolder.setstate(!state); //openclose
}


function initializedocument() {
if(doc.all)
browserversion = 1; //ie4
else if(doc.layers)
browserversion = 2; //ns4
else
browserversion = 0; //other

folderstree.initialize(0, 1, "");
//folderstree.display();

if(browserversion > 0) {
doc.write(" ");

// close the whole tree
clickonnode(0);

// open the root folder
clickonnode(0);
}
}


// auxiliary functions for folder-treee backward compatibility
function gfldr(description, hreference,parentid,target) {
var des;
index++;
if(fentries==0){
 selectfile[fentries]=description;
 fentries++;
}
des=description;
folder = new folder(des, hreference,parentid,target);
return(folder);
}


function glnk(target, description, linkdata, itemimg,parentid) {
fulllink = ""

if(target == 0 ||target=="") {
if(linkdata != "")
fulllink = "'"+linkdata+"' target=\"_blank\"";//显示在新开的窗体中
else
fulllink = "";
}
if(target == 1) {
if(linkdata != "" )
fulllink = "'"+linkdata+"' target=\"_slef\"";//显示在表单所在的框架或窗体中
else
fulllink = "";
}
else if(target == 2) {
if(linkdata != "")
fulllink = "'"+linkdata+"' target=\"_parent\""; //显示在包含表单的框架的父框架中
else
fulllink = "";
}
else if(target == 3) {
if(linkdata != "")
fulllink = "'"+linkdata+"' target=\"_top\"";//显示在顶层窗体中
else
fulllink = "";
}

else {//alert(target);
if(linkdata != "")
fulllink = "'"+linkdata+"' target="+target;//显示在target窗体中
else
fulllink = "";
}
index++; //当前节点编号

linkitem = new item(description, linkdata, fulllink, itemimg,parentid)
return linkitem
}


function insfldr(parentfolder, childfolder,target,hreference) {
var child;
var desc;
parentid=parentfolder.id;
child=gfldr(childfolder,hreference,parentid,target);
return(parentfolder.addchild(child));
}


function insdoc(parentfolder,target, description, linkdata, itemimg) {
var document;
var itemimg;
itemimg=imageurl+"bu.gif";
var desc;
parentid=parentfolder.id;
document=glnk(target, description, linkdata, itemimg,parentid);
parentfolder.addchild(document);
}

function setobjdocument(msg){
if (msg!=null){
 objdocument=msg;
}
}

//设置展开、收缩图片路径
function setimageurl(msg){
if (msg==null){
 imageurl="../leftfiles/images/";
}else imageurl=msg;
}

//设置超链接文本颜色
function setlinkcolor(msg){
 linkcolor=msg;
}
function setflodercolor(msg){
 flodercolor=msg;
}
// global variables

usetextlinks = 1;
indexofentries = new array;
nentries = 0;
index=-1;  //节点编号
doc = document;
browserversion = 0;
selectedfolder = 0;
selectfile=new array;
fentries=0;
var objdocument,imageurl;
var linkcolor="#085dde";
var flodercolor="#292c08";
var type1=typeof top.logo;

if (type1=="undefined"){
objdocument=null;
}

if(imageurl==null){
 setimageurl(imageurl);
}

将源代码和接前代码中的代码合并成一个treemenu.js文件,在在页面中引入即可



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn