⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhtmlxtree.js

📁 dhtmlxGrid 是跨浏览器的 JavaScript 表格控制组件(Grid Control)
💻 JS
📖 第 1 页 / 共 5 页
字号:
*     @topic: 1
*/
	dhtmlXTreeObject.prototype.getSelectedItemId=function()
	{
		if (this.lastSelected)
			if(this._globalIdStorageFind(this.lastSelected.parentObject.id))
				return this.lastSelected.parentObject.id;
		return ("");
	};
	
/**  
*     @desc: get node color
*     @param: itemId - identificator of node
*     @type: public
*	  @return: color of node (empty string for default color);
*     @topic: 6  
*/	
	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;
	};
/**  
*     @desc: set node color
*     @param: itemId - identificator of node
*     @param: defaultColor - node color
*     @param: selectedColor - selected node color
*     @type: public
*     @topic: 6
*/
	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 ((this.lastSelected) && (temp.tr==this.lastSelected.parentObject.tr))
				{  if (selectedColor) temp.span.style.color=selectedColor; }
			else
				{  if (defaultColor) temp.span.style.color=defaultColor;  }

			if (selectedColor) temp.scolor=selectedColor;
			if (defaultColor) temp.acolor=defaultColor;
			}
	};

/**
*     @desc: return item text
*     @param: itemId - identificator of node
*     @type: public
*	  @return: text of item (with HTML formatting, if any)
*     @topic: 6
*/
	dhtmlXTreeObject.prototype.getItemText=function(itemId)
	{
		var temp=this._globalIdStorageFind(itemId);
		if (!temp) return 0;
		return(temp.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].innerHTML);
	};
/**  
*     @desc: return parent item identificator
*     @param: itemId - identificator of node
*     @type: public
*	  @return: id of parent item
*     @topic: 4
*/			
	dhtmlXTreeObject.prototype.getParentId=function(itemId)
	{
		var temp=this._globalIdStorageFind(itemId);
		if ((!temp)||(!temp.parentObject)) return "";
		return temp.parentObject.id;
	};



/**  
*     @desc: change item id
*     @type: public
*     @param: itemId - old node id
*     @param: newItemId - new node id		  
*     @topic: 4
*/ 	
	dhtmlXTreeObject.prototype.changeItemId=function(itemId,newItemId)
	{
		var temp=this._globalIdStorageFind(itemId);
		if (!temp) return 0;
		temp.id=newItemId;
        temp.span.contextMenuId=newItemId;
		for (var i=0; i<this._globalIdStorageSize; i++)
			if (this._globalIdStorage[i]==itemId) 
				{
				this._globalIdStorage[i]=newItemId;
				}
	};

	
/**  
*     @desc: mark selected item as cutted
*     @type: public
*     @topic: 2  
*/ 	
	dhtmlXTreeObject.prototype.doCut=function(){
		if (this.nodeCut) this.clearCut();
		this.nodeCut=this.lastSelected;
		if (this.nodeCut) 
			{
		var tempa=this.nodeCut.parentObject;
		this.cutImg[0]=tempa.images[0];
		this.cutImg[1]=tempa.images[1];
		this.cutImg[2]=tempa.images[2];	
		tempa.images[0]=tempa.images[1]=tempa.images[2]=this.cutImage;
		this._correctPlus(tempa);			
			}
	};
	
/**
*     @desc: insert previously cutted branch
*     @param: itemId - id of new parent node
*     @type: public
*     @topic: 2  
*/ 	
	dhtmlXTreeObject.prototype.doPaste=function(itemId){
		var temp=this._globalIdStorageFind(itemId);
		if (!temp) return 0;
		if  (this.nodeCut) {
	    if ((!this._checkParenNodes(this.nodeCut.parentObject.id,temp))&&(id!=this.nodeCut.parentObject.parentObject.id))		
		        this._moveNode(temp,this.nodeCut.parentObject);
		this.clearCut();
							}
	};
	
/**  
*     @desc: clear cut
*     @type: public
*     @topic: 2  
*/ 		
	dhtmlXTreeObject.prototype.clearCut=function(){
		if (this.nodeCut) 
			{
		var tempa=this.nodeCut.parentObject;			
		tempa.images[0]=this.cutImg[0];
		tempa.images[1]=this.cutImg[1];
		tempa.images[2]=this.cutImg[2];	
		if (tempa.parentObject) this._correctPlus(tempa);		
		if (tempa.parentObject) this._correctLine(tempa);				
		this.nodeCut=0;
			}
	};
	


	/**  
*     @desc: move node with subnodes
*     @type: private
*     @param: itemObject - moved node object
*     @param: targetObject - new parent node
*     @topic: 2  
*/	
	dhtmlXTreeObject.prototype._moveNode=function(itemObject,targetObject){
                //debugger;
		var mode=this.dadmodec;
		if (mode==1)
        {
            var z=targetObject;
			if (this.dadmodefix<0)
			{

                while (true){
				z=this._getPrevNode(z);
				if ((z==-1)) { z=this.htmlNode; break; }
                if ((z.tr.style.display=="")||(!z.parentObject)) break;
        		//var Nodes=itemObject.htmlNode.childNodes[0].childNodes;
       			//if (Nodes[1].style.display!="none") break;
                }

                var nodeA=z;
                var nodeB=targetObject;

            }
            else
            {
                while (true){
				z=this._getNextNode(z);
				if ((z==-1)) { z=this.htmlNode; break; }
                if ((z.tr.style.display=="")||(!z.parentObject)) break;
        		//var Nodes=itemObject.htmlNode.childNodes[0].childNodes;
       			//if (Nodes[1].style.display!="none") break;
                }

                var nodeB=z;
                var nodeA=targetObject;
            }


            if (this._getNodeLevel(nodeA,0)>this._getNodeLevel(nodeB,0))
                {
                return this._moveNodeTo(itemObject,nodeA.parentObject);
                }
            else
                {
//  				if (this._checkParenNodes(itemObject.id,d)) return;
                return this._moveNodeTo(itemObject,nodeB.parentObject,nodeB);
                }


/*
			if ((!targetObject.tr.nextSibling)||(!targetObject.tr.nextSibling.nodem))
				return this._moveNodeTo(itemObject,targetObject.parentObject);
			//move in middle of group
			else return this._moveNodeTo(itemObject,targetObject.parentObject,targetObject.tr.nextSibling.nodem);
            */
//            debugger;

		}
		else return this._moveNodeTo(itemObject,targetObject);
			
	}

	/**
*     @desc: fix order of nodes in collection
*     @type: private
*     @param: target - parent item node
*     @param: zParent - before node
*     @topic: 2
*/

dhtmlXTreeObject.prototype._fixNodesCollection=function(target,zParent){
		var flag=0; var icount=0;
		var Nodes=target.childNodes;
		var Count=target.childsCount-1;
		
		if (zParent==Nodes[Count]) return;
		for (var i=0; i<Count; i++)
			if (Nodes[i]==Nodes[Count]) {  Nodes[i]=Nodes[i+1]; Nodes[i+1]=Nodes[Count]; }

//			Count=target.childsCount;
		for (var i=0; i<Count+1; i++)		
			{
			if (flag) { 
				var temp=Nodes[i];
				Nodes[i]=flag; 
				flag=temp; 
					}
			else 
			if (Nodes[i]==zParent) {   flag=Nodes[i]; Nodes[i]=Nodes[Count];  }
			}
	};
	

/**  
*     @desc: move single node
*     @type: private
*     @param: itemObject - moved node object
*     @param: targetObject - new parent node
*     @mode: mode - DragAndDrop mode (0 - as child, 1 as sibling)
*     @topic: 2  
*/
	dhtmlXTreeObject.prototype._moveNodeTo=function(itemObject,targetObject,beforeNode){
	//if (beforeNode) alert(targetObject.id+"-"+beforeNode.id);
    if    (targetObject.mytype)
    	var framesMove=(itemObject.treeNod.lWin!=targetObject.lWin);
    else
       	var framesMove=(itemObject.treeNod.lWin!=targetObject.treeNod.lWin);

	if (this.dragFunc) if (!this.dragFunc(itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod)) return false;
		if ((targetObject.XMLload==0)&&(this.XMLsource)) 		
			{
			targetObject.XMLload=1; this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"id="+escape(targetObject.id));
			}	
		this.openItem(targetObject.id);
		
	var oldTree=itemObject.treeNod;
	var c=itemObject.parentObject.childsCount; 
	var z=itemObject.parentObject;

	if ((framesMove)||(oldTree.dpcpy)) //interframe drag flag
		itemObject=this._recreateBranch(itemObject,targetObject,beforeNode);
	else
		{	

		var Count=targetObject.childsCount; var Nodes=targetObject.childNodes;
				Nodes[Count]=itemObject; 			
				itemObject.treeNod=targetObject.treeNod;
				targetObject.childsCount++;			
				
				var tr=this._drawNewTr(Nodes[Count].htmlNode);
				
				if (!beforeNode)
					{
					targetObject.htmlNode.childNodes[0].appendChild(tr);
					if (this.dadmode==1) this._fixNodesCollection(targetObject,beforeNode);
					}
				else 
					{
					targetObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr);
					this._fixNodesCollection(targetObject,beforeNode);
					Nodes=targetObject.childNodes;
					}
				
		
			} 
				if (!oldTree.dpcpy)	{
				itemObject.parentObject.htmlNode.childNodes[0].removeChild(itemObject.tr);		
				if ((!beforeNode)||(targetObject!=itemObject.parentObject)){
					for (var i=0; i<z.childsCount; i++){
						if (z.childNodes[i].id==itemObject.id) { 
						z.childNodes[i]=0;
						break;				}}}
					else z.childNodes[z.childsCount-1]=0;
			
				oldTree._compressChildList(z.childsCount,z.childNodes); 
				z.childsCount--;
				}

				
		if ((!framesMove)&&(!oldTree.dpcpy)) {
		itemObject.tr=tr;	
		tr.nodem=itemObject;	
		itemObject.parentObject=targetObject;
		
		if (oldTree!=targetObject.treeNod) {	if(itemObject.treeNod._registerBranch(itemObject,oldTree)) return;  	 this._clearStyles(itemObject);  this._redrawFrom(this,itemObject.parentObject);	};
		
		this._correctPlus(targetObject);
		this._correctLine(targetObject); 
		this._correctLine(itemObject);	
		this._correctPlus(itemObject);

			//fix target siblings
		if (beforeNode)
		{
		
			this._correctPlus(beforeNode);
			//this._correctLine(beforeNode);	
		}
		else 
		if (targetObject.childsCount>=2) 
		{
//			alert(Nodes[targetObject.childsCount-2].id)
			this._correctPlus(Nodes[targetObject.childsCount-2]);
			this._correctLine(Nodes[targetObject.childsCount-2]);				
		}
		
		this._correctPlus(Nodes[targetObject.childsCount-1]);
		//this._correctLine(Nodes[targetObject.childsCount-1]);				
	
		
		if (this.tscheck) this._correctCheckStates(targetObject);
		if (oldTree.tscheck) oldTree._correctCheckStates(z);
		
		}				
	
		//fix source parent
		
		if (c>1) { oldTree._correctPlus(z.childNodes[c-2]);
				   oldTree._correctLine(z.childNodes[c-2]);
				   }	
		//if (z.childsCount>0)
			oldTree._correctPlus(z);
			
		//fix target parent		   
		 
		
		if (this.dropFunc) this.dropFunc(itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod);
		return itemObject.id;
	};
	
/**  
*     @desc: check possibility of drag-and-drop
*     @type: private
*     @param: itemId - draged node id
*     @param: htmlObject - droped node object
*     @param: shtmlObject - sourse node object
*     @topic: 6  
*/	
dhtmlXTreeObject.prototype._checkParenNodes=function(itemId,htmlObject,shtmlObject){
		if (shtmlObject) { if (shtmlObject.parentObject.id==htmlObject.id)  return 1; }
		if (htmlObject.id==itemId) return 1;
		if (htmlObject.parentObject) return this._checkParenNodes(itemId,htmlObject.parentObject); else return 0;
	};
	
	
	
/**  
*     @desc: recursive set default styles for node
*     @type: private
*     @param: itemObject - target node object
*     @topic: 6  
*/	
	dhtmlXTreeObject.prototype._clearStyles=function(itemObject){ 
			var td1=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[1];
			var td3=td1.nextSibling.nextSibling;
			
			itemObject.span.innerHTML=itemObject.label;
			
			if (this.checkBoxOff) { td1.childNodes[0].style.display=""; td1.childNodes[0].onclick=this.onCheckBoxClick;  }
			else td1.childNodes[0].style.display="none";
			td1.childNodes[0].treeNod=this;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -