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

📄 dhtmlxtree.js

📁 dhtmlxGrid 是跨浏览器的 JavaScript 表格控制组件(Grid Control)
💻 JS
📖 第 1 页 / 共 5 页
字号:
*/		
	dhtmlXTreeObject.prototype._getOpenState=function(itemObject){
        if (!itemObject) return;
		var z=itemObject.htmlNode.childNodes[0].childNodes;
		if (z.length<=1) return 0;
		if 	(z[1].style.display!="none") return 1;
		else return -1;
	}


	
/**  
*     @desc: ondblclick item  event handler
*     @type: private
*     @topic: 0  
*/		
	dhtmlXTreeObject.prototype.onRowClick2=function(){
	if 	(this.parentObject.treeNod.dblclickFuncHandler) if (!this.parentObject.treeNod.dblclickFuncHandler(this.parentObject.id)) return 0;
		if ((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
			this.parentObject.treeNod._HideShow(this.parentObject);
		else
			this.parentObject.treeNod._HideShow(this.parentObject,2);
	};
/**  
*     @desc: onclick item event handler
*     @type: private
*     @topic: 0  
*/			
	dhtmlXTreeObject.prototype.onRowClick=function(){
	if 	(this.parentObject.treeNod.openFuncHandler) if (!this.parentObject.treeNod.openFuncHandler(this.parentObject.id,this.parentObject.treeNod._getOpenState(this.parentObject))) return 0;
		if ((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
			this.parentObject.treeNod._HideShow(this.parentObject);
		else
			this.parentObject.treeNod._HideShow(this.parentObject,2);
	};


/**  
*     @desc: onclick item image event handler
*     @type: private
*     @topic: 0
*/	
	dhtmlXTreeObject.prototype.onRowClickDown=function(){
			var that=this.parentObject.treeNod;
			that._selectItem(this.parentObject);
		};
/**  
*     @desc: visual select item in tree
*     @type: private
*     @param: node - tree item object
*     @topic: 0
*/
	dhtmlXTreeObject.prototype._selectItem=function(node){
			if (this.lastSelected){
				this._unselectItem(this.lastSelected.parentObject);
				}
			var z=node.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0];
			z.className="selectedTreeRow";
			this.lastSelected=z.parentNode;
			}
/**  
*     @desc: visual unselect item in tree
*     @type: private
*     @param: node - tree item object
*     @topic: 0
*/					
	dhtmlXTreeObject.prototype._unselectItem=function(node){
			node.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].className="standartTreeRow";
			}	
/**  
*     @desc: select node text event handler
*     @type: private
*     @param: e - event object
*     @param: htmlObject - node object	  
*     @param: mode - if false - call onSelect event
*     @topic: 0  
*/				
	dhtmlXTreeObject.prototype.onRowSelect=function(e,htmlObject,mode){
		//if (mode!=false) mode=true;
		if (!htmlObject) htmlObject=this.parentObject.span.parentNode;
    	htmlObject.parentObject.span.className="selectedTreeRow";
//        htmlObject.childNodes[0].className="selectedTreeRow";

		if (htmlObject.parentObject.scolor)  htmlObject.parentObject.span.style.color=htmlObject.parentObject.scolor;
		if ((htmlObject.parentObject.treeNod.lastSelected)&&(htmlObject.parentObject.treeNod.lastSelected!=htmlObject))
			{
				  var lastId=htmlObject.parentObject.treeNod.lastSelected.parentObject.id;
		          htmlObject.parentObject.treeNod.lastSelected.parentObject.span.className="standartTreeRow";
			  	  if (htmlObject.parentObject.treeNod.lastSelected.parentObject.acolor)  htmlObject.parentObject.treeNod.lastSelected.parentObject.span.style.color=htmlObject.parentObject.treeNod.lastSelected.parentObject.acolor;
			}
		else 	var lastId="";
		htmlObject.parentObject.treeNod.lastSelected=htmlObject;
		if (!mode) { 
			if (window.event) e=event;
			//if (e) window.status=e.button;
			if ((e)&&(e.button==2)&&(htmlObject.parentObject.treeNod.arFunc))
				{ htmlObject.parentObject.treeNod.arFunc(htmlObject.parentObject.id);  }
			if (htmlObject.parentObject.actionHandler) htmlObject.parentObject.actionHandler(htmlObject.parentObject.id,lastId); 
			}
	};
	



	
/**  
*     @desc: checbox select action
*     @type: fix checkbox state
*     @topic: 0  
*/
dhtmlXTreeObject.prototype._correctCheckStates=function(dhtmlObject){
	if (!this.tscheck) return;
	if (dhtmlObject.id==this.rootId) return;
	//calculate state
	var act=dhtmlObject.htmlNode.childNodes[0].childNodes;
	var flag1=0; var flag2=0;
	if (act.length<2) return;
	for (var i=1; i<act.length; i++)
		if (act[i].nodem.checkstate==0) flag1=1;
		else if (act[i].nodem.checkstate==1) flag2=1;		
			else { flag1=1; flag2=1; break; }

	if ((flag1)&&(flag2)) this._setCheck(dhtmlObject,"notsure");
	else if (flag1)  this._setCheck(dhtmlObject,false);
		else  this._setCheck(dhtmlObject,true);
		
		this._correctCheckStates(dhtmlObject.parentObject);
}

/**  
*     @desc: checbox select action
*     @type: private
*     @topic: 0  
*/	
	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.treeNod.checkFuncHandler) return (this.treeNod.checkFuncHandler(this.parentObject.id,this.parentObject.checkstate));
		else return true;
	};
/**
*     @desc: create HTML elements for tree node
*     @type: private
*     @param: acheck - enable/disable checkbox
*     @param: itemObject - item object
*     @param: mode - mode
*     @topic: 0  
*/
	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');
//				tr.height="16px"; tr.style.overflow="hidden";
		var td1=document.createElement('td');
			td1.className="standartTreeImage";
			var img0=document.createElement((itemObject.id==this.rootId)?"div":"img");
				img0.border="0"; //img0.src='treeGfx/line1.gif';
				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("input");				inp.type="checkbox"; inp.style.width="12px"; inp.style.height="12px";
			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) ((this._isOpera)?td11:inp).style.display="none";  
			// td11.className="standartTreeImage";
					//if (acheck) 
				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"; }
		

		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;
			td2.style.width="100%";
		itemObject.span.appendChild(document.createTextNode(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.paddinRight="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.arFunc){
			//disable context handler
			tr.oncontextmenu=Function("this.childNodes[0].parentObject.treeNod.arFunc(this.childNodes[0].parentObject.id); return false;");
		}
		return table;	
	};
	

	
/**  
*     @desc: set path to image directory
*     @param: newPath - path to image directory
*     @type: public
*     @topic: 0  
*/
	dhtmlXTreeObject.prototype.setImagePath=function( newPath ){ this.imPath=newPath; };
	


	/**
*     @desc: set function called when tree node selected
*     @param: func - event handling function
*     @type: public
*     @topic: 0
*     @event: onRightClick
*     @eventdesc:  Event occured after right mouse button was clicked.
			Assigning this handler can disable default context menu, and noncompattible with dhtmlXMenu integration.
*     @eventparam: ID of clicked item
*/
	dhtmlXTreeObject.prototype.setOnRightClickHandler=function(func){  if (typeof(func)=="function") this.arFunc=func; else this.arFunc=eval(func);  };

/**
*     @desc: set function called when tree node selected
*     @param: func - event handling function
*     @type: public
*     @topic: 0
*     @event: onClick
*     @eventdesc: Event raised immideatly after text part of item in tree was clicked, but after default onClick functionality was processed.
				  Richt mouse button click can be catched by onRightClick handler.
*     @eventparam:  ID of clicked item
*/
	dhtmlXTreeObject.prototype.setOnClickHandler=function(func){  if (typeof(func)=="function") this.aFunc=func; else this.aFunc=eval(func);  };


/**
*     @desc: enables dynamic loading from XML
*     @type: public
*     @param: filePath - name of script returning XML;
*     @topic: 0
*/
	dhtmlXTreeObject.prototype.setXMLAutoLoading=function(filePath){  this.XMLsource=filePath; };



	
	/**  
*     @desc: set function called before checkbox checked/unchecked
*     @param: func - event handling function
*     @type: public
*     @topic: 0
*     @event: onCheck
*     @eventdesc: Event raised immideatly after item in tree was checked/unchecked.
*     @eventparam: ID of item which will be checked/unchecked
*     @eventparam: Current checkbox state. 1 - item checked, 0 - item unchecked.
*/
	dhtmlXTreeObject.prototype.setOnCheckHandler=function(func){  if (typeof(func)=="function") this.checkFuncHandler=func; else this.checkFuncHandler=eval(func); };


/**  
*     @desc: set function called before tree node opened/closed
*     @param: func - event handling function
*     @type: public
*     @topic: 0
*     @event:  onOpen
*     @eventdesc: Event raised immideatly after item in tree got commant to open/close , and before item was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored.
				Event not raised if node opened by dhtmlXtree API.
*     @eventparam: ID of node which will be opened/closed
*     @eventparam: Current open state of tree item. 0 - item has not childs, -1 - item closed, 1 - item opened.
*     @eventreturn: true - confirm opening/closing; false - deny opening/closing;
*/
	dhtmlXTreeObject.prototype.setOnOpenHandler=function(func){  if (typeof(func)=="function") this.openFuncHandler=func; else this.openFuncHandler=eval(func);  };

	/**
*     @desc: set function called when tree node double clicked
*     @param: func - event handling function
*     @type: public
*     @topic: 0
*     @event: onDblClick
*     @eventdesc: Event raised immideatly after item in tree was doubleclicked, before default onDblClick functionality was processed.
			Beware using both onClick and onDblClick events, because component can  generate onClick event before onDblClick event while doubleclicking item in tree.
			( that behavior depend on used browser )
*     @eventparam:  ID of item which was doubleclicked
*     @eventreturn:  true - confirm opening/closing; false - deny opening/closing;
*/
	dhtmlXTreeObject.prototype.setOnDblClickHandler=function(func){  if (typeof(func)=="function") this.dblclickFuncHandler=func; else this.dblclickFuncHandler=eval(func); };
	
	
	






	/**  
*     @desc: expand target node and all child nodes
*     @type: public
*     @param: itemId - node id
*     @topic: 4  
*/	
	dhtmlXTreeObject.prototype.openAllItems=function(itemId)
	{
		var temp=this._globalIdStorageFind(itemId);
		if (!temp) return 0;
		this._xopenAll(temp); 
	};
	
	/*
*     @desc: return open/close state
*     @type: public
*     @param: itemId - node id
*	  @return: -1 - close, 1 - opened, 0 - node doen't have childs
*     @topic: 4
*/	
	dhtmlXTreeObject.prototype.getOpenState=function(itemId){
		var temp=this._globalIdStorageFind(itemId);
		if (!temp) return "";
		return this._getOpenState(temp);
	};
	
/**  
*     @desc: collapse target node and all child nodes
*     @type: public
*     @param: itemId - node id
*     @topic: 4  
*/		
	dhtmlXTreeObject.prototype.closeAllItems=function(itemId)
	{
		var temp=this._globalIdStorageFind(itemId);
		if (!temp) return 0;
		this._xcloseAll(temp); 		
	};		
	
	
/**  
*     @desc: set user data for target node
*     @type: public
*     @param: itemId - target node identificator
*     @param: name - key for user data
*     @param: value - user data
*     @topic: 5  
*/	
	dhtmlXTreeObject.prototype.setUserData=function(itemId,name,value){
		var sNode=this._globalIdStorageFind(itemId); 
			if (!sNode) return;
			if(name=="hint") sNode.htmlNode.childNodes[0].childNodes[0].title=value;
			sNode.userData["t_"+name]=value;
			if (!sNode._userdatalist) sNode._userdatalist=name;
				else sNode._userdatalist+=","+name;
	};
	
/**  
*     @desc: return user data from target node
*     @type: public
*     @param: itemId - target node identificator
*     @param: name - key for user data
*	  @return: value of user data
*     @topic: 5
*/
	dhtmlXTreeObject.prototype.getUserData=function(itemId,name){
		var sNode=this._globalIdStorageFind(itemId);
		if (!sNode) return;
		return sNode.userData["t_"+name];
	};

/**
*     @desc: retun selected item identificator
*     @type: public
*	  @return: id of selected item

⌨️ 快捷键说明

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