📄 dhtmlxtree.js
字号:
/*Copyright DHTMLX LTD http://www.dhtmlx.com
This version of Software is free for using in GPL applications. For commercial use please contact info@dhtmlx.com to obtain license*/
function dhtmlXTreeObject(htmlObject, width, height, rootId){if (_isIE)try {document.execCommand("BackgroundImageCache", false, true);}catch(e){};if (typeof(htmlObject)!="object")
this.parentObject=document.getElementById(htmlObject);else
this.parentObject=htmlObject;this._itim_dg=true;this.dlmtr=",";this.dropLower=false;this.enableIEImageFix();this.xmlstate=0;this.mytype="tree";this.smcheck=true;this.width=width;this.height=height;this.rootId=rootId;this.childCalc=null;this.def_img_x="18px";this.def_img_y="18px";this.def_line_img_x="18px";this.def_line_img_y="18px";this._dragged=new Array();this._selected=new Array();this.style_pointer="pointer";if (_isIE)this.style_pointer="hand";this._aimgs=true;this.htmlcA=" [";this.htmlcB="]";this.lWin=window;this.cMenu=0;this.mlitems=0;this.dadmode=0;this.slowParse=false;this.autoScroll=true;this.hfMode=0;this.nodeCut=new Array();this.XMLsource=0;this.XMLloadingWarning=0;this._idpull={};this._pullSize=0;this.treeLinesOn=true;this.tscheck=false;this.timgen=true;this.dpcpy=false;this._ld_id=null;this.imPath="treeGfx/";this.checkArray=new Array("iconUnCheckAll.gif","iconCheckAll.gif","iconCheckGray.gif","iconUncheckDis.gif","iconCheckDis.gif","iconCheckDis.gif");this.radioArray=new Array("radio_off.gif","radio_on.gif","radio_on.gif","radio_off.gif","radio_on.gif","radio_on.gif");this.lineArray=new Array("line2.gif","line3.gif","line4.gif","blank.gif","blank.gif","line1.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._createSelf();this.allTree.appendChild(this.htmlNode.htmlNode);if(_isFF)this.allTree.childNodes[0].width="100%";this.allTree.onselectstart=new Function("return false;");this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this,true,this.no_cashe);if (_isIE)this.preventIECashing(true);var self=this;if (window.addEventListener)window.addEventListener("unload",function(){try{self.destructor();}catch(e){}},false);if (window.attachEvent)window.attachEvent("onunload",function(){try{self.destructor();}catch(e){}});this.dhx_Event();this._onEventSet={onMouseIn:function(){this.ehlt=true;},onMouseOut:function(){this.ehlt=true;}};return this;};dhtmlXTreeObject.prototype.enableIEImageFix=function(mode){if (!mode){this._getImg=function(id){return document.createElement((id==this.rootId)?"div":"img");};this._setSrc=function(a,b){a.src=b;};this._getSrc=function(a){return a.src;};}else {this._getImg=function(){var z=document.createElement("DIV");z.innerHTML=" ";z.className="dhx_bg_img_fix";return z;};this._setSrc=function(a,b){a.style.backgroundImage="url("+b+")";};this._getSrc=function(a){var z=a.style.backgroundImage;return a.substr(4,a.length-5);};};};dhtmlXTreeObject.prototype.destructor=function(){for (var a in this._idpull){var z=this._idpull[a];if (!z)continue;z.parentObject=null;z.treeNod=null;z.childNodes=null;z.span=null;z.tr.nodem=null;z.tr=null;z.htmlNode.objBelong=null;z.htmlNode=null;this._idpull[a]=null;};this.allTree.innerHTML="";this.XMLLoader.destructor();for(var a in this){this[a]=null;};};function cObject(){return this;};cObject.prototype= new Object;cObject.prototype.clone = function () {function _dummy(){};_dummy.prototype=this;return new _dummy();};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.userData=new cObject();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._globalIdStorageAdd(itemId,this);if (this.treeNod.checkBoxOff )this.htmlNode=this.treeNod._createItem(1,this,mode);else this.htmlNode=this.treeNod._createItem(0,this,mode);this.htmlNode.objBelong=this;return this;};dhtmlXTreeObject.prototype._globalIdStorageAdd=function(itemId,itemObject){if (this._globalIdStorageFind(itemId,1,1)) {itemId=itemId +"_"+(new Date()).valueOf();return this._globalIdStorageAdd(itemId,itemObject);};this._idpull[itemId]=itemObject;this._pullSize++;return itemId;};dhtmlXTreeObject.prototype._globalIdStorageSub=function(itemId){if (this._idpull[itemId]){this._unselectItem(this._idpull[itemId]);this._idpull[itemId]=null;this._pullSize--;};if ((this._locker)&&(this._locker[itemId])) this._locker[itemId]=false;};dhtmlXTreeObject.prototype._globalIdStorageFind=function(itemId,skipXMLSearch,skipParsing,isreparse){var z=this._idpull[itemId]
if (z){return z;};return null;};dhtmlXTreeObject.prototype._escape=function(str){switch(this.utfesc){case "none":
return str;break;case "utf8":
return encodeURI(str);break;default:
return escape(str);break;};};dhtmlXTreeObject.prototype._drawNewTr=function(htmlObject,node)
{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,afterCall){var that=this;if (!this.parsCount)this.callEvent("onXLS",[that,null]);this.xmlstate=1;if (afterCall)this.XMLLoader.waitCall=afterCall;this.XMLLoader.loadXMLString(xmlString);};dhtmlXTreeObject.prototype.loadXML=function(file,afterCall){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);};dhtmlXTreeObject.prototype._attachChildNode=function(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs,beforeNode,afterNode){if (beforeNode)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;};};};Nodes[Count]=new dhtmlXTreeItemObject(itemId,itemText,parentObject,this,null,1);itemId = Nodes[Count].id;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._drawNewTr(Nodes[Count].htmlNode);if ((this.XMLloadingWarning)||(this._hAdI))
Nodes[Count].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)) 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="hiddenRow";if ((parentObject._r_logic)||(this._frbtr))
this._setSrc(Nodes[Count].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": Nodes[Count].XMLload=0;break;case "CHECKED":
if (this.XMLloadingWarning)this.setCheckList+=this.dlmtr+itemId;else
this.setCheck(itemId,1);break;case "HCHECKED":
this._setCheck(Nodes[Count],"unsure");break;case "OPEN": Nodes[Count].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(Nodes[Count]);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 Nodes[Count];};dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs){var parentObject=this._globalIdStorageFind(parentId);if (!parentObject)return (-1);var nodez=this._attachChildNode(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs);return nodez;};dhtmlXTreeObject.prototype.insertNewChild=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs){return this.insertNewItem(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs);};dhtmlXTreeObject.prototype._parseXMLTree=function(dhtmlObject,node,parentId,level,xml_obj,start){if (!xml_obj)xml_obj=dhtmlObject.XMLLoader;dhtmlObject.skipLock=true;if (!dhtmlObject.parsCount)dhtmlObject.parsCount=1;else dhtmlObject.parsCount++;dhtmlObject.XMLloadingWarning=1;var nodeAskingCall="";if (!node){node=xml_obj.getXMLTopNode("tree");parentId=node.getAttribute("id");if (node.getAttribute("radio"))
dhtmlObject.htmlNode._r_logic=true;dhtmlObject.parsingOn=parentId;dhtmlObject.parsedArray=new Array();dhtmlObject.setCheckList="";};var temp=dhtmlObject._globalIdStorageFind(parentId);if ((temp.childsCount)&&(!start)&&(!dhtmlObject._edsbps)&&(!temp._has_top))
var preNode=temp.childNodes[temp.childsCount-1];else
var preNode=0;if (node.getAttribute("order"))
dhtmlObject._reorderXMLBranch(node);var npl=0;for(var i=start||0;i<node.childNodes.length;i++){if ((node.childNodes[i].nodeType==1)&&(node.childNodes[i].tagName == "item"))
{temp.XMLload=1;if ((dhtmlObject._epgps)&&(dhtmlObject._epgpsC==npl)){this._setNextPageSign(temp,npl+1*(start||0),level,node);break;};var nodx=node.childNodes[i];var name=nodx.getAttribute("text");var cId=nodx.getAttribute("id");if ((typeof(dhtmlObject.waitUpdateXML)=="object")&&(!dhtmlObject.waitUpdateXML[cId])){dhtmlObject._parseXMLTree(dhtmlObject,node.childNodes[i],cId,1,xml_obj);continue;};var im0=nodx.getAttribute("im0");var im1=nodx.getAttribute("im1");var im2=nodx.getAttribute("im2");var aColor=nodx.getAttribute("aCol");var sColor=nodx.getAttribute("sCol");var chd=nodx.getAttribute("child");var imw=nodx.getAttribute("imwidth");var imh=nodx.getAttribute("imheight");var atop=nodx.getAttribute("top");var aradio=nodx.getAttribute("radio");var topoffset=nodx.getAttribute("topoffset");var aopen=nodx.getAttribute("open");var aselect=nodx.getAttribute("select");var acall=nodx.getAttribute("call");var achecked=nodx.getAttribute("checked");var closeable=nodx.getAttribute("closeable");var tooltip = nodx.getAttribute("tooltip");var nocheckbox = nodx.getAttribute("nocheckbox");var disheckbox = nodx.getAttribute("disabled");var style = nodx.getAttribute("style");var locked = nodx.getAttribute("locked");var zST="";if (aselect)zST+=",SELECT";if (atop)zST+=",TOP";if (acall)nodeAskingCall=cId;if (achecked==-1)zST+=",HCHECKED";else if (achecked)zST+=",CHECKED";if (aopen)zST+=",OPEN";if (dhtmlObject.waitUpdateXML){if (dhtmlObject._globalIdStorageFind(cId))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -