📄 dhtmlxtree.js
字号:
if(itemObject.childNodes[itemObject.childsCount-1].id==itemId)return 0;
return 1;
};
dhtmlXTreeObject.prototype._getLineStatus =function(itemId,itemObject){
if(itemObject.childNodes[itemObject.childsCount-1].id==itemId)return 0;
return 1;
}
dhtmlXTreeObject.prototype._HideShow=function(itemObject,mode){
if((this.XMLsource)&&(!itemObject.XMLload)){
if(mode==1)return;
itemObject.XMLload=1;
this._loadDynXML(itemObject.id);
return;};
if(itemObject.unParsed)this.reParse(itemObject);
var Nodes=itemObject.htmlNode.childNodes[0].childNodes;var Count=Nodes.length;
if(Count>1){
if(((Nodes[1].style.display!="none")||(mode==1))&&(mode!=2)){
this.allTree.childNodes[0].border = "1";
this.allTree.childNodes[0].border = "0";
nodestyle="none";
}
else nodestyle="";
for(var i=1;i<Count;i++)
Nodes[i].style.display=nodestyle;
}
this._correctPlus(itemObject);
}
dhtmlXTreeObject.prototype._getOpenState=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;
}
dhtmlXTreeObject.prototype.onRowClick2=function(){
if(this.parentObject.treeNod.dblclickFuncHandler)if(!this.parentObject.treeNod.dblclickFuncHandler(this.parentObject.id,this.parentObject.treeNod))return 0;
if((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
this.parentObject.treeNod._HideShow(this.parentObject);
else
this.parentObject.treeNod._HideShow(this.parentObject,2);
};
dhtmlXTreeObject.prototype.onRowClick=function(){
var that=this.parentObject.treeNod;
if(that._spnFH)if(!that._spnFH(this.parentObject.id,that._getOpenState(this.parentObject)))return 0;
if((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
that._HideShow(this.parentObject);
else
that._HideShow(this.parentObject,2);
if(that._epnFH)
if(!that.xmlstate)
that._epnFH(this.parentObject.id,that._getOpenState(this.parentObject));
else{
that._oie_onXLE=that.onXLE;
that.onXLE=that._epnFHe;
}
};
dhtmlXTreeObject.prototype._epnFHe=function(that,id){
if(that._epnFH)
that._epnFH(id,that.getOpenState(id));
that.onXLE=that._oie_onXLE;
if(that.onXLE)that.onXLE(that,id);
}
dhtmlXTreeObject.prototype.onRowClickDown=function(e){
e=e||window.event;
var that=this.parentObject.treeNod;
that._selectItem(this.parentObject,e);
};
dhtmlXTreeObject.prototype.getSelectedItemId=function()
{
var str=new Array();
for(var i=0;i<this._selected.length;i++)str[i]=this._selected[i].id;
return(str.join(this.dlmtr));
};
dhtmlXTreeObject.prototype._selectItem=function(node,e){
if((!this._amsel)||(!e)||((!e.ctrlKey)&&(!e.shiftKey)))
this._unselectItems();
if((node.i_sel)&&(this._amsel)&&(e)&&(e.ctrlKey))
this._unselectItem(node);
else
if((!node.i_sel)&&((!this._amselS)||(this._selected.length==0)||(this._selected[0].parentObject==node.parentObject)))
if((this._amsel)&&(e)&&(e.shiftKey)&&(this._selected.length!=0)&&(this._selected[this._selected.length-1].parentObject==node.parentObject)){
var a=this._getIndex(this._selected[this._selected.length-1]);
var b=this._getIndex(node);
if(b<a){var c=a;a=b;b=c;}
for(var i=a;i<=b;i++)
if(!node.parentObject.childNodes[i].i_sel)
this._markItem(node.parentObject.childNodes[i]);
}
else this._markItem(node);
}
dhtmlXTreeObject.prototype._markItem=function(node){
if(node.scolor)node.span.style.color=node.scolor;
node.span.className="selectedTreeRow";
node.i_sel=true;
this._selected[this._selected.length]=node;
}
dhtmlXTreeObject.prototype.getIndexById=function(itemId){
var z=this._globalIdStorageFind(itemId);
if(!z)return null;
return this._getIndex(z);
};
dhtmlXTreeObject.prototype._getIndex=function(w){
var z=w.parentObject;
for(var i=0;i<z.childsCount;i++)
if(z.childNodes[i]==w)return i;
};
dhtmlXTreeObject.prototype.clearSelection=function(itemId){
if(itemId)
this._unselectItem(this._globalIdStorageFind(itemId));
else
this._unselectItems();
}
dhtmlXTreeObject.prototype._unselectItem=function(node){
if((node)&&(node.i_sel))
{
node.span.className="standartTreeRow";
if(node.acolor)node.span.style.color=node.acolor;
node.i_sel=false;
for(var i=0;i<this._selected.length;i++)
if(!this._selected[i].i_sel){
this._selected.splice(i,1);
break;
}
}
}
dhtmlXTreeObject.prototype._unselectItems=function(){
for(var i=0;i<this._selected.length;i++){
var node=this._selected[i];
node.span.className="standartTreeRow";
if(node.acolor)node.span.style.color=node.acolor;
node.i_sel=false;
}
this._selected=new Array();
}
dhtmlXTreeObject.prototype.onRowSelect=function(e,htmlObject,mode){
e=e||window.event;
var obj=this.parentObject;
if(htmlObject)obj=htmlObject.parentObject;
var that=obj.treeNod;
var lastId=that.getSelectedItemId();
that._selectItem(obj,e);
if(!mode){
if((e)&&(e.button==2)&&(that.arFunc))that.arFunc(obj.id);
if(obj.actionHandler)obj.actionHandler(obj.id,lastId);
}
};
dhtmlXTreeObject.prototype._correctCheckStates=function(dhtmlObject){
if(!this.tscheck)return;
if(dhtmlObject.id==this.rootId)return;
var act=dhtmlObject.childNodes;
var flag1=0;var flag2=0;
if(dhtmlObject.childsCount==0)return;
for(var i=0;i<dhtmlObject.childsCount;i++)
if(act[i].checkstate==0)flag1=1;
else if(act[i].checkstate==1)flag2=1;
else{flag1=1;flag2=1;break;}
if((flag1)&&(flag2))this._setCheck(dhtmlObject,"unsure");
else if(flag1)this._setCheck(dhtmlObject,false);
else this._setCheck(dhtmlObject,true);
this._correctCheckStates(dhtmlObject.parentObject);
}
dhtmlXTreeObject.prototype.onCheckBoxClick=function(e){
if(this.treeNod.tscheck)
if(this.parentObject.checkstate==1)this.treeNod._setSubChecked(false,this.parentObject);
else this.treeNod._setSubChecked(true,this.parentObject);
else
if(this.parentObject.checkstate==1)this.treeNod._setCheck(this.parentObject,false);
else this.treeNod._setCheck(this.parentObject,true);
this.treeNod._correctCheckStates(this.parentObject.parentObject);
if((!this.parentObject.dscheck)&&(this.treeNod.checkFuncHandler))return(this.treeNod.checkFuncHandler(this.parentObject.id,this.parentObject.checkstate));
else return true;
};
dhtmlXTreeObject.prototype._createItem=function(acheck,itemObject,mode){
var table=document.createElement('table');
table.cellSpacing=0;table.cellPadding=0;
table.border=0;
if(this.hfMode)table.style.tableLayout="fixed";
table.style.margin=0;table.style.padding=0;
var tbody=document.createElement('tbody');
var tr=document.createElement('tr');
var td1=document.createElement('td');
td1.className="standartTreeImage";
if(this._txtimg){
var img0=document.createElement("div");
td1.appendChild(img0);
img0.className="dhx_tree_textSign";
}
else
{
var img0=document.createElement((itemObject.id==this.rootId)?"div":"img");
img0.border="0";
if(itemObject.id!=this.rootId)img0.align="absmiddle";
td1.appendChild(img0);img0.style.padding=0;img0.style.margin=0;
}
var td11=document.createElement('td');
var inp=document.createElement((itemObject.id==this.rootId)?"div":"img");
inp.checked=0;inp.src=this.imPath+this.checkArray[0];inp.style.width="16px";inp.style.height="16px";
if(!acheck)(((_isOpera)||(_isKHTML))?td11:inp).style.display="none";
td11.appendChild(inp);
if(itemObject.id!=this.rootId)inp.align="absmiddle";
inp.onclick=this.onCheckBoxClick;
inp.treeNod=this;
inp.parentObject=itemObject;
td11.width="20px";
var td12=document.createElement('td');
td12.className="standartTreeImage";
var img=document.createElement((itemObject.id==this.rootId)?"div":"img");img.onmousedown=this._preventNsDrag;img.ondragstart=this._preventNsDrag;
img.border="0";
if(this._aimgs){
img.parentObject=itemObject;
if(itemObject.id!=this.rootId)img.align="absmiddle";
img.onclick=this.onRowSelect;}
if(!mode)img.src=this.imPath+this.imageArray[0];
td12.appendChild(img);img.style.padding=0;img.style.margin=0;
if(this.timgen)
{img.style.width=this.def_img_x;img.style.height=this.def_img_y;}
else
{
img.style.width="0px";img.style.height="0px";
if(_isOpera)td12.style.display="none";
}
var td2=document.createElement('td');
td2.className="standartTreeRow";
itemObject.span=document.createElement('span');
itemObject.span.className="standartTreeRow";
if(this.mlitems)itemObject.span.style.width=this.mlitems;
else td2.noWrap=true;
if(!_isKHTML)td2.style.width="100%";
itemObject.span.innerHTML=itemObject.label;
td2.appendChild(itemObject.span);
td2.parentObject=itemObject;td1.parentObject=itemObject;
td2.onclick=this.onRowSelect;td1.onclick=this.onRowClick;td2.ondblclick=this.onRowClick2;
if(this.ettip)td2.title=itemObject.label;
if(this.dragAndDropOff){
if(this._aimgs){this.dragger.addDraggableItem(td12,this);td12.parentObject=itemObject;}
this.dragger.addDraggableItem(td2,this);
}
itemObject.span.style.paddingLeft="5px";itemObject.span.style.paddingRight="5px";td2.style.verticalAlign="";
td2.style.fontSize="10pt";td2.style.cursor=this.style_pointer;
tr.appendChild(td1);tr.appendChild(td11);tr.appendChild(td12);
tr.appendChild(td2);
tbody.appendChild(tr);
table.appendChild(tbody);
if(this.ehlt){
itemObject.span.onmouseout=this._itemMouseOut;
itemObject.span.onmousemove=this._itemMouseIn;
}
if(this.arFunc){
tr.oncontextmenu=Function("this.childNodes[0].parentObject.treeNod.arFunc(this.childNodes[0].parentObject.id);return false;");
}
return table;
};
dhtmlXTreeObject.prototype._itemMouseOut=function(){
var z=this.className.split("_");
if(z[1]=="lor"){
this.className=z[0];
}
}
dhtmlXTreeObject.prototype._itemMouseIn=function(){
var z=this.className.split("_");
if(z[1]!="lor"){
this.className=z[0]+"_lor";
}
}
dhtmlXTreeObject.prototype.setImagePath=function(newPath){this.imPath=newPath;};
dhtmlXTreeObject.prototype.setChildCalcMode=function(mode){
switch(mode){
case "child": this.childCalc=1;break;
case "leafs": this.childCalc=2;break;
case "childrec": this.childCalc=3;break;
case "leafsrec": this.childCalc=4;break;
case "disabled": this.childCalc=null;break;
default: this.childCalc=4;
}
}
dhtmlXTreeObject.prototype.setChildCalcHTML=function(htmlA,htmlB){
this.htmlcA=htmlA;this.htmlcB=htmlB;
}
dhtmlXTreeObject.prototype.setOnRightClickHandler=function(func){if(typeof(func)=="function")this.arFunc=func;else this.arFunc=eval(func);};
dhtmlXTreeObject.prototype.setOnClickHandler=function(func){if(typeof(func)=="function")this.aFunc=func;else this.aFunc=eval(func);};
dhtmlXTreeObject.prototype.enableContextMenu=function(menu){if(menu)this.cMenu=menu;};
dhtmlXTreeObject.prototype.setXMLAutoLoading=function(filePath){this.XMLsource=filePath;};
dhtmlXTreeObject.prototype.setDragBehavior=function(mode){
switch(mode){
case "child": this.dadmode=0;break;
case "sibling": this.dadmode=1;break;
case "complex": this.dadmode=2;break;
}};
dhtmlXTreeObject.prototype.setOnCheckHandler=function(func){if(typeof(func)=="function")this.checkFuncHandler=func;else this.checkFuncHandler=eval(func);};
dhtmlXTreeObject.prototype.setOnOpenHandler=function(func){if(typeof(func)=="function")this._spnFH=func;else this._spnFH=eval(func);};
dhtmlXTreeObject.prototype.setOnOpenStartHandler=function(func){if(typeof(func)=="function")this._spnFH=func;else this._spnFH=eval(func);};
dhtmlXTreeObject.prototype.setOnOpenEndHandler=function(func){if(typeof(func)=="function")this._epnFH=func;else this._epnFH=eval(func);};
dhtmlXTreeObject.prototype.setOnDblClickHandler=function(func){if(typeof(func)=="function")this.dblclickFuncHandler=func;else this.dblclickFuncHandler=eval(func);};
dhtmlXTreeObject.prototype.openAllItems=function(itemId)
{
var temp=this._globalIdStorageFind(itemId);
if(!temp)return 0;
this._xopenAll(temp);
};
dhtmlXTreeObject.prototype.getOpenState=function(itemId){
var temp=this._globalIdStorageFind(itemId);
if(!temp)return "";
return this._getOpenState(temp);
};
dhtmlXTreeObject.prototype.closeAllItems=function(itemId)
{
if(itemId===window.undefined)itemId=this.rootId;
var temp=this._globalIdStorageFind(itemId);
if(!temp)return 0;
this._xcloseAll(temp);
this.allTree.childNodes[0].border = "1";
this.allTree.childNodes[0].border = "0";
};
dhtmlXTreeObject.prototype.setUserData=function(itemId,name,value){
var sNode=this._globalIdStorageFind(itemId,0,true);
if(!sNode)return;
if(name=="hint")sNode.htmlNode.childNodes[0].childNodes[0].title=value;
if(sNode.userData["t_"+name]===undefined){
if(!sNode._userdatalist)sNode._userdatalist=name;
else sNode._userdatalist+=","+name;
}
sNode.userData["t_"+name]=value;
};
dhtmlXTreeObject.prototype.getUserData=function(itemId,name){
var sNode=this._globalIdStorageFind(itemId,0,true);
if(!sNode)return;
return sNode.userData["t_"+name];
};
dhtmlXTreeObject.prototype.getItemColor=function(itemId)
{
var temp=this._globalIdStorageFind(itemId);
if(!temp)return 0;
var res= new Object();
if(temp.acolor)res.acolor=temp.acolor;
if(temp.acolor)res.scolor=temp.scolor;
return res;
};
dhtmlXTreeObject.prototype.setItemColor=function(itemId,defaultColor,selectedColor)
{
if((itemId)&&(itemId.span))
var temp=itemId;
else
var temp=this._globalIdStorageFind(itemId);
if(!temp)return 0;
else{
if(temp.i_sel)
{if(selectedColor)temp.span.style.color=selectedColor;}
else
{if(defaultColor)temp.span.style.color=defaultColor;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -