📄 dhtmlxtree.js
字号:
var that=this;
if (!this.parsCount) this.callEvent("onXLS",[that,this._ld_id]);
this._ld_id=null;
this.xmlstate=1;
this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this,true,this.no_cashe);
if (afterCall) this.XMLLoader.waitCall=afterCall;
this.XMLLoader.loadXML(file);
};
/**
* @desc: create new child node
* @type: private
* @param: parentObject - parent node object
* @param: itemId - new node id
* @param: itemText - new node text
* @param: itemActionHandler - function fired on node select event
* @param: image1 - image for node without children;
* @param: image2 - image for closed node;
* @param: image3 - image for opened node
* @param: optionStr - string of otions
* @param: childs - node childs flag (for dynamical trees) (optional)
* @param: beforeNode - node, after which new node will be inserted (optional)
* @topic: 2
*/
dhtmlXTreeObject.prototype._attachChildNode=function(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs,beforeNode,afterNode){
if (beforeNode && beforeNode.parentObject) parentObject=beforeNode.parentObject;
if (((parentObject.XMLload==0)&&(this.XMLsource))&&(!this.XMLloadingWarning))
{
parentObject.XMLload=1;
this._loadDynXML(parentObject.id);
}
var Count=parentObject.childsCount;
var Nodes=parentObject.childNodes;
if (afterNode){
if (afterNode.tr.previousSibling.previousSibling){
beforeNode=afterNode.tr.previousSibling.nodem;
}
else
optionStr=optionStr.replace("TOP","")+",TOP";
}
if (beforeNode)
{
var ik,jk;
for (ik=0; ik<Count; ik++)
if (Nodes[ik]==beforeNode)
{
for (jk=Count; jk!=ik; jk--)
Nodes[1+jk]=Nodes[jk];
break;
}
ik++;
Count=ik;
}
if (optionStr) {
var tempStr=optionStr.split(",");
for (var i=0; i<tempStr.length; i++)
{
switch(tempStr[i])
{
case "TOP": if (parentObject.childsCount>0) { beforeNode=new Object; beforeNode.tr=parentObject.childNodes[0].tr.previousSibling; }
parentObject._has_top=true;
for (ik=Count; ik>0; ik--)
Nodes[ik]=Nodes[ik-1];
Count=0;
break;
}
};
};
var n;
if (!(n=this._idpull[itemId]) || n.span!=-1){
n=Nodes[Count]=new dhtmlXTreeItemObject(itemId,itemText,parentObject,this,null,1);
itemId = Nodes[Count].id;
parentObject.childsCount++;
}
if(!n.htmlNode) {
n.label=itemText;
n.htmlNode=this._createItem((this.checkBoxOff?1:0),n);
n.htmlNode.objBelong=n;
}
if(image1) n.images[0]=image1;
if(image2) n.images[1]=image2;
if(image3) n.images[2]=image3;
var tr=this._drawNewTr(n.htmlNode);
if ((this.XMLloadingWarning)||(this._hAdI))
n.htmlNode.parentNode.parentNode.style.display="none";
if ((beforeNode)&&(beforeNode.tr.nextSibling))
parentObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr.nextSibling);
else
if (this.parsingOn==parentObject.id){
this.parsedArray[this.parsedArray.length]=tr;
}
else
parentObject.htmlNode.childNodes[0].appendChild(tr);
if ((beforeNode)&&(!beforeNode.span)) beforeNode=null;
if (this.XMLsource) if ((childs)&&(childs!=0)) n.XMLload=0; else n.XMLload=1;
n.tr=tr;
tr.nodem=n;
if (parentObject.itemId==0)
tr.childNodes[0].className="hiddenRow";
if ((parentObject._r_logic)||(this._frbtr))
this._setSrc(n.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0],this.imPath+this.radioArray[0]);
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": n.XMLload=0; break;
case "CHECKED":
if (this.XMLloadingWarning)
this.setCheckList+=this.dlmtr+itemId;
else
this.setCheck(itemId,1);
break;
case "HCHECKED":
this._setCheck(n,"unsure");
break;
case "OPEN": n.openMe=1; break;
}
};
};
if (!this.XMLloadingWarning)
{
if ((this._getOpenState(parentObject)<0)&&(!this._hAdI)) this.openItem(parentObject.id);
if (beforeNode)
{
this._correctPlus(beforeNode);
this._correctLine(beforeNode);
}
this._correctPlus(parentObject);
this._correctLine(parentObject);
this._correctPlus(n);
if (parentObject.childsCount>=2)
{
this._correctPlus(Nodes[parentObject.childsCount-2]);
this._correctLine(Nodes[parentObject.childsCount-2]);
}
if (parentObject.childsCount!=2) this._correctPlus(Nodes[0]);
if (this.tscheck) this._correctCheckStates(parentObject);
if (this._onradh) {
if (this.xmlstate==1){
var old=this.onXLE;
this.onXLE=function(id){ this._onradh(itemId); if (old) old(id); }
}
else
this._onradh(itemId);
}
}
return n;
};
/**
* @desc: create new node as a child to specified with parentId
* @type: deprecated
* @param: parentId - parent node id
* @param: itemId - new node id
* @param: itemText - new node text
* @param: itemActionHandler - function fired on node select event (optional)
* @param: image1 - image for node without children; (optional)
* @param: image2 - image for closed node; (optional)
* @param: image3 - image for opened node (optional)
* @param: optionStr - options string (optional)
* @param: children - node children flag (for dynamical trees) (optional)
* @topic: 2
*/
dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){
var parentObject=this._globalIdStorageFind(parentId);
if (!parentObject) return (-1);
var nodez=this._attachChildNode(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children);
return nodez;
};
/**
* @desc: create new node as a child to specified with parentId
* @type: public
* @param: parentId - parent node id
* @param: itemId - new node id
* @param: itemText - new node label
* @param: itemActionHandler - function fired on node select event (optional)
* @param: image1 - image for node without children; (optional)
* @param: image2 - image for closed node; (optional)
* @param: image3 - image for opened node (optional)
* @param: optionStr - options string (optional)
* @param: children - node children flag (for dynamical trees) (optional)
* @topic: 2
*/
dhtmlXTreeObject.prototype.insertNewChild=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){
return this.insertNewItem(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children);
}
/**
* @desc: parse xml
* @type: private
* @param: dhtmlObject - jsTree object
* @param: node - top XML node
* @param: parentId - parent node id
* @param: level - level of tree
* @topic: 2
*/
dhtmlXTreeObject.prototype._parseXMLTree=function(a,b,c,d,xml){
var p=new xmlPointer(xml.getXMLTopNode("tree"));
a._parse(p);
a._p=p;
}
dhtmlXTreeObject.prototype._parseItem=function(c,temp,preNode,befNode){
var id;
if (this._srnd && (!this._idpull[id=c.get("id")] || !this._idpull[id].span))
{
this._addItemSRND(temp.id,id,c);
return;
}
var a=c.get_all();
if ((typeof(this.waitUpdateXML)=="object")&&(!this.waitUpdateXML[a.id])){
this._parse(c,a.id,1);
return;
}
var zST=[];
if (a.select) zST.push("SELECT");
if (a.top) zST.push("TOP");
if (a.call) nodeAskingCall=a.id;
if (a.checked==-1) zST.push("HCHECKED");
else if (a.checked) zST.push("CHECKED");
if (a.open) zST.push("OPEN");
if (this.waitUpdateXML){
if (this._globalIdStorageFind(a.id))
var newNode=this.updateItem(a.id,a.text,a.im0,a.im1,a.im2,a.checked);
else{
if (this.npl==0) zST.push("TOP");
else preNode=temp.childNodes[this.npl];
var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,0,preNode);
preNode=null;
}
}
else
var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,(befNode||0),preNode);
if (a.tooltip)
newNode.span.parentNode.parentNode.title=a.tooltip;
if (a.style)
if (newNode.span.style.cssText)
newNode.span.style.cssText+=(";"+a.style);
else
newNode.span.setAttribute("style",newNode.span.getAttribute("style")+"; "+a.style);
if (a.radio) newNode._r_logic=true;
if (a.nocheckbox){
newNode.span.parentNode.previousSibling.previousSibling.childNodes[0].style.display='none';
newNode.nocheckbox=true;
}
if (a.disabled){
if (a.checked!=null) this._setCheck(newNode,convertStringToBoolean(a.checked));
this.disableCheckbox(newNode,1);
}
newNode._acc=a.child||0;
if (this.parserExtension) this.parserExtension._parseExtension(node.childNodes[i],this.parserExtension,a.id,parentId);
this.setItemColor(newNode,a.aCol,a.sCol);
if (a.locked=="1") this._lockItem(newNode,true,true);
if ((a.imwidth)||(a.imheight)) this.setIconSize(a.imwidth,a.imheight,newNode);
if ((a.closeable=="0")||(a.closeable=="1")) this.setItemCloseable(newNode,a.closeable);
var zcall="";
if (a.topoffset) this.setItemTopOffset(newNode,a.topoffset);
if ((!this.slowParse)||(typeof(this.waitUpdateXML)=="object")){
if (c.sub_exists("item"))
zcall=this._parse(c,a.id,1);
}
if (zcall!="") this.nodeAskingCall=zcall;
c.each("userdata",function(u){
this.setUserData(c.get("id"),u.get("name"),u.content());
},this)
}
dhtmlXTreeObject.prototype._parse=function(p,parentId,level,start){
if (this._srnd && !this.parentObject.offsetHeight) {
var self=this;
return window.setTimeout(function(){
self._parse(p,parentId,level,start);
},100);
}
if (!p.exists()) return;
this.skipLock=true; //disable item locking
//loading flags
this.parsCount=this.parsCount?(this.parsCount+1):1;
this.XMLloadingWarning=1;
this.nodeAskingCall="";
if (!parentId) { //top level
parentId=p.get("id");
if (p.get("radio"))
this.htmlNode._r_logic=true;
this.parsingOn=parentId;
this.parsedArray=new Array();
this.setCheckList="";
}
var temp=this._globalIdStorageFind(parentId);
if (!temp) return dhtmlxError.throwError("DataStructure","XML reffers to not existing parent");
if ((temp.childsCount)&&(!start)&&(!this._edsbps)&&(!temp._has_top))
var preNode=temp.childNodes[temp.childsCount-1];
else
var preNode=0;
this.npl=0;
p.each("item",function(c,i){
temp.XMLload=1;
if ((this._epgps)&&(this._epgpsC==this.npl)){
this._setNextPageSign(temp,this.npl+1*(start||0),level,node);
return -1;
}
this._parseItem(c,temp,preNode);
this.npl++;
},this,start);
if (!level) {
p.each("userdata",function(u){
this.setUserData(p.get("id"),u.get("name"),u.content());
},this);
temp.XMLload=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -