📄 dhtmlxtree.js
字号:
function dhtmlXTreeObject(htmlObject,width,height,rootId){
if(typeof(htmlObject)!="object")
this.parentObject=document.getElementById(htmlObject);
else
this.parentObject=htmlObject;
this.mytype="tree";
this.width=width;
this.height=height;
this.rootId=rootId;
this.hfMode=0;
this.nodeCut=0;
this.XMLsource=0;
this.XMLloadingWarning=0;
this.a0=new Array();
this.globalNodeStorage=new Array();
this.a0Size=0;
this.treeLinesOn=true;
this.checkFuncHandler=0;
this.openFuncHandler=0;
this.dblclickFuncHandler=0;
this.tscheck=false;
this.imPath="treeGfx/";
this.checkArray=new Array("iconUnCheckAll.gif","iconCheckAll.gif","iconCheckGray.gif");
this.lineArray=new Array("line2.gif","line3.gif","line4.gif","blank.gif","blank.gif");
this.minusArray=new Array("minus2.gif","minus3.gif","minus4.gif","minus.gif","minus5.gif");
this.plusArray=new Array("plus2.gif","plus3.gif","plus4.gif","plus.gif","plus5.gif");
this.imageArray=new Array("leaf.gif","folderOpen.gif","folderClosed.gif");
this.cutImg= new Array(0,0,0);
this.cutImage="but_cut.gif";
this.dragger= new dhtmlDragAndDropObject();
this.htmlNode=new dhtmlXTreeItemObject(this.rootId,"",0,this);
this.htmlNode.htmlNode.childNodes[0].childNodes[0].style.display="none";
this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[0].className="hiddenRow";
this.allTree=this.a2();
this.allTree.appendChild(this.htmlNode.htmlNode);
this.allTree.onselectstart=new Function("return false;");
this.XMLLoader=new dtmlXMLLoaderObject(this.a3,this);
this.dragger.addDragLanding(this.allTree,this);
return this;
};
function dhtmlXTreeItemObject(itemId,itemText,parentObject,treeObject,actionHandler,mode){
this.htmlNode="";
this.acolor="";
this.scolor="";
this.tr=0;
this.childsCount=0;
this.tempDOMM=0;
this.tempDOMU=0;
this.dragSpan=0;
this.dragMove=0;
this.span=0;
this.closeble=1;
this.childNodes=new Array();
this.checkstate=0;
this.treeNod=treeObject;
this.label=itemText;
this.parentObject=parentObject;
this.actionHandler=actionHandler;
this.images=new Array(treeObject.imageArray[0],treeObject.imageArray[1],treeObject.imageArray[2]);
this.id=treeObject.a0Add(itemId,this);
if(this.treeNod.checkBoxOff)this.htmlNode=this.treeNod.a20(1,this,mode);
else this.htmlNode=this.treeNod.a20(0,this,mode);
this.htmlNode.objBelong=this;
return this;
};
dhtmlXTreeObject.prototype.a0Add=function(itemId,itemObject){
if(this.a0Find(itemId)){d=new Date();itemId=d.valueOf()+"_"+itemId;return this.a0Add(itemId,itemObject);}
this.a0[this.a0Size]=itemId;
this.globalNodeStorage[this.a0Size]=itemObject;
this.a0Size++;
return itemId;
};
dhtmlXTreeObject.prototype.a0Sub=function(itemId){
for(var i=0;i<this.a0Size;i++)
if(this.a0[i]==itemId)
{
this.a0[i]=this.a0[this.a0Size-1];
this.globalNodeStorage[i]=this.globalNodeStorage[this.a0Size-1];
this.a0Size--;
this.a0[this.a0Size]=0;
this.globalNodeStorage[this.a0Size]=0;
}
};
dhtmlXTreeObject.prototype.a0Find=function(itemId){
for(var i=0;i<this.a0Size;i++)
if(this.a0[i]==itemId)
return this.globalNodeStorage[i];
return 0;
};
dhtmlXTreeObject.prototype.a7=function(htmlObject)
{
var tr =document.createElement('tr');
var td1=document.createElement('td');
var td2=document.createElement('td');
td1.appendChild(document.createTextNode(" "));
td2.colSpan=3;td2.appendChild(htmlObject);tr.appendChild(td1);tr.appendChild(td2);
return tr;
};
dhtmlXTreeObject.prototype.loadXMLString=function(xmlString){this.XMLLoader.loadXMLString(xmlString);};
dhtmlXTreeObject.prototype.loadXML=function(file){this.XMLLoader.loadXML(file);};
dhtmlXTreeObject.prototype.a8=function(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs,beforeNode){
if(beforeNode)parentObject=beforeNode.parentObject;
if(((parentObject.XMLload==0)&&(this.XMLsource))&&(!this.XMLloadingWarning))
{
parentObject.XMLload=1;this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"itemId="+escape(parentObject.itemId));
}
var Count=parentObject.childsCount;
var Nodes=parentObject.childNodes;
if((!itemActionHandler)&&(this.aFunc))itemActionHandler=this.aFunc;
Nodes[Count]=new dhtmlXTreeItemObject(itemId,itemText,parentObject,this,itemActionHandler,1);
if(image1)Nodes[Count].images[0]=image1;
if(image2)Nodes[Count].images[1]=image2;
if(image3)Nodes[Count].images[2]=image3;
parentObject.childsCount++;
var tr=this.a7(Nodes[Count].htmlNode);
if(this.XMLloadingWarning)
Nodes[Count].htmlNode.parentNode.parentNode.style.display="none";
if(optionStr){
var tempStr=optionStr.split(",");
for(var i=0;i<tempStr.length;i++)
{
switch(tempStr[i])
{
case "TOP": if(parentObject.childsCount>1)beforeNode=parentObject.htmlNode.childNodes[0].childNodes[1].nodem.previousSibling;break;
}
};
};
if((beforeNode)&&(beforeNode.tr.nextSibling))
parentObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr.nextSibling);
else
parentObject.htmlNode.childNodes[0].appendChild(tr);
if(this.XMLsource)if((childs)&&(childs!=0))Nodes[Count].XMLload=0;else Nodes[Count].XMLload=1;
Nodes[Count].tr=tr;
tr.nodem=Nodes[Count];
if(parentObject.itemId==0)
tr.childNodes[0].className="hitemIddenRow";
if(optionStr){
var tempStr=optionStr.split(",");
for(var i=0;i<tempStr.length;i++)
{
switch(tempStr[i])
{
case "SELECT": this.selectItem(itemId,false);break;
case "CALL": this.selectItem(itemId,true);break;
case "CHILD": Nodes[Count].XMLload=0;break;
case "CHECKED": this.setCheck(itemId,1);break;
case "OPEN": Nodes[Count].openMe=1;break;
}
};
};
if(!this.XMLloadingWarning)
{
if(this.a9(parentObject)<0)
this.openItem(parentObject.id);
if(beforeNode)
{
this.a10(beforeNode);
this.a11(beforeNode);
}
this.a10(parentObject);
this.a11(parentObject);
this.a10(Nodes[Count]);
if(parentObject.childsCount>=2)
{
this.a10(Nodes[parentObject.childsCount-2]);
this.a11(Nodes[parentObject.childsCount-2]);
}
if(parentObject.childsCount!=2)this.a10(Nodes[0]);
if(this.tscheck)this.a12(parentObject);
}
};
dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs){
var parentObject=this.a0Find(parentId);
if(!parentObject)return(-1);
this.a8(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs);
};
dhtmlXTreeObject.prototype.a3=function(dhtmlObject,node,parentId,level){
dhtmlObject.XMLloadingWarning=1;
var nodeAskingCall="";
if(!node){
node=dhtmlObject.XMLLoader.getXMLTopNode("tree");
parentId=node.getAttribute("id");
}
for(var i=0;i<node.childNodes.length;i++)
{
if((node.childNodes[i].nodeType==1)&&(node.childNodes[i].tagName == "item"))
{
var name=node.childNodes[i].getAttribute("text");
var cId=node.childNodes[i].getAttribute("id");
var im0=node.childNodes[i].getAttribute("im0");
var im1=node.childNodes[i].getAttribute("im1");
var im2=node.childNodes[i].getAttribute("im2");
var aColor=node.childNodes[i].getAttribute("aCol");
var sColor=node.childNodes[i].getAttribute("sCol");
var chd=node.childNodes[i].getAttribute("child");
var atop=node.childNodes[i].getAttribute("top");
var aopen=node.childNodes[i].getAttribute("open");
var aselect=node.childNodes[i].getAttribute("select");
var acall=node.childNodes[i].getAttribute("call");
var achecked=node.childNodes[i].getAttribute("checked");
var closeable=node.childNodes[i].getAttribute("closeable");
var zST="";
if(aselect)zST+=",SELECT";
if(atop)zST+=",TOP";
if(acall)nodeAskingCall=cId;
if(achecked)zST+=",CHECKED";
if(aopen)zST+=",OPEN";
var temp=dhtmlObject.a0Find(parentId);
temp.XMLload=1;
dhtmlObject.insertNewItem(parentId,cId,name,0,im0,im1,im2,zST,chd);
dhtmlObject.setItemColor(cId,aColor,sColor);
if((closeable=="0")||(closeable=="1"))dhtmlObject.setItemCloseable(cId,closeable);
var zcall=dhtmlObject.a3(dhtmlObject,node.childNodes[i],cId,1);
if(zcall!="")nodeAskingCall=zcall;
}
else
if((node.childNodes[i].nodeType==1)&&(node.childNodes[i].tagName == "userdata"))
{
var name=node.childNodes[i].getAttribute("name");
if((name)&&(node.childNodes[i].childNodes[0])){
dhtmlObject.setUserData(parentId,name,node.childNodes[i].childNodes[0].data);
};
};
};
if(!level){
dhtmlObject.lastLoadedXMLId=parentId;
dhtmlObject.a13(dhtmlObject);
dhtmlObject.XMLloadingWarning=0;
if(nodeAskingCall!="")dhtmlObject.selectItem(nodeAskingCall,true);
}
return nodeAskingCall;
};
dhtmlXTreeObject.prototype.a13=function(dhtmlObject,itemObject){
if(!itemObject){
var tempx=dhtmlObject.a0Find(dhtmlObject.lastLoadedXMLId);
dhtmlObject.lastLoadedXMLId=-1;
if(!tempx)return 0;
}
else tempx=itemObject;
for(var i=0;i<tempx.childsCount;i++)
{
if(!itemObject)tempx.childNodes[i].htmlNode.parentNode.parentNode.style.display="";
if(tempx.childNodes[i].openMe==1)
for(var zy=0;zy<tempx.childNodes[i].childNodes.length;zy++)
tempx.childNodes[i].htmlNode.childNodes[0].childNodes[zy+1].style.display="";
dhtmlObject.a13(dhtmlObject,tempx.childNodes[i]);
dhtmlObject.a11(tempx.childNodes[i]);
dhtmlObject.a10(tempx.childNodes[i]);
};
dhtmlObject.a11(tempx);
dhtmlObject.a10(tempx);
};
dhtmlXTreeObject.prototype.a2=function(){
var div=document.createElement('div');
div.className="containerTableStyle";
div.style.width=this.width;
div.style.height=this.height;
this.parentObject.appendChild(div);
return div;
};
dhtmlXTreeObject.prototype.a14=function(itemObject)
{
this.a15(itemObject,1);
for(var i=0;i<itemObject.childsCount;i++)
this.a14(itemObject.childNodes[i]);
};
dhtmlXTreeObject.prototype.a16=function(itemObject)
{
this.a15(itemObject,2);
for(var i=0;i<itemObject.childsCount;i++)
this.a16(itemObject.childNodes[i]);
};
dhtmlXTreeObject.prototype.a10=function(itemObject){
var workArray=this.lineArray;
if((this.XMLsource)&&(!itemObject.XMLload))
{
var workArray=this.plusArray;
itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[2];
}
else
try{
if(itemObject.childsCount)
{
if(itemObject.htmlNode.childNodes[0].childNodes[1].style.display!="none")
{
var workArray=this.minusArray;
itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[1];
}
else
{
var workArray=this.plusArray;
itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[2];
}
}
else
{
itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[0];
}
}
catch(e){};
var tempNum=2;
if(!itemObject.treeNod.treeLinesOn)itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].src=this.imPath+workArray[3];
else{
if(itemObject.parentObject)tempNum=this.a17(itemObject.id,itemObject.parentObject);
itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].src=this.imPath+workArray[tempNum];
}
};
dhtmlXTreeObject.prototype.a11=function(itemObject){
var sNode=itemObject.parentObject;
try{
if(sNode)
if((this.a18(itemObject.id,sNode)==0)||(!this.treeLinesOn))
{
for(var i=1;i<=itemObject.childsCount;i++)
{
itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="";
itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="";
}
}
else
for(var i=1;i<=itemObject.childsCount;i++)
{
itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="url("+this.imPath+"line1.gif)";
itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="repeat-y";
}
}
catch(e){};
};
dhtmlXTreeObject.prototype.a17=function(itemId,itemObject){
try{
if(itemObject.childsCount<=1){if(itemObject.id==this.rootId)return 4;else return 0;}
if(itemObject.htmlNode.childNodes[0].childNodes[1].nodem.id==itemId)if(!itemObject.id)return 2;else return 1;
if(itemObject.htmlNode.childNodes[0].childNodes[itemObject.childsCount].nodem.id==itemId)return 0;
}
catch(e){};
return 1;
};
dhtmlXTreeObject.prototype.a18 =function(itemId,itemObject){
if(itemObject.htmlNode.childNodes[0].childNodes[itemObject.childsCount].nodem.id==itemId)return 0;
return 1;
}
dhtmlXTreeObject.prototype.a15=function(itemObject,mode){
if(((this.XMLsource)&&(!itemObject.XMLload))&&(!mode)){itemObject.XMLload=1;this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"id="+escape(itemObject.id));return;};
var Nodes=itemObject.htmlNode.childNodes[0].childNodes;var Count=Nodes.length;
if(Count>1){
if(((Nodes[1].style.display!="none")||(mode==1))&&(mode!=2))nodestyle="none";else nodestyle="";
for(var i=1;i<Count;i++)
Nodes[i].style.display=nodestyle;
}
this.a10(itemObject);
}
dhtmlXTreeObject.prototype.a9=function(itemObject){
var z=itemObject.htmlNode.childNodes[0].childNodes;
if(z.length<=1)return 0;
if(z[1].style.display!="none")return 1
else return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -