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

📄 dtree.js

📁 主要是用Dtree.js做的一个树形结构
💻 JS
📖 第 1 页 / 共 2 页
字号:

	if (this.config.useCookies) this.updateCookie();

};



// Opens the tree to a specific node

dTree.prototype.openTo = function(nId, bSelect, bFirst) {

	if (!bFirst) {

		for (var n=0; n<this.aNodes.length; n++) {

			if (this.aNodes[n].id == nId) {

				nId=n;

				break;

			}

		}

	}

	var cn=this.aNodes[nId];

	if (cn.pid==this.root.id || !cn._p) return;

	cn._io = true;

	cn._is = bSelect;

	if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);

	if (this.completed && bSelect) this.s(cn._ai);

	else if (bSelect) this._sn=cn._ai;

	this.openTo(cn._p._ai, false, true);

};



// Closes all nodes on the same level as certain node

dTree.prototype.closeLevel = function(node) {

	for (var n=0; n<this.aNodes.length; n++) {

		if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {

			this.nodeStatus(false, n, this.aNodes[n]._ls);

			this.aNodes[n]._io = false;

			this.closeAllChildren(this.aNodes[n]);

		}

	}

}



// Closes all children of a node

dTree.prototype.closeAllChildren = function(node) {

	for (var n=0; n<this.aNodes.length; n++) {

		if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {

			if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);

			this.aNodes[n]._io = false;

			this.closeAllChildren(this.aNodes[n]);		

		}

	}

}



// Change the status of a node(open or closed)

dTree.prototype.nodeStatus = function(status, id, bottom) {

	eDiv	= document.getElementById('d' + this.obj + id);

	eJoin	= document.getElementById('j' + this.obj + id);

	if (this.config.useIcons) {

		eIcon	= document.getElementById('i' + this.obj + id);

		eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;

	}

	eJoin.src = (this.config.useLines)?

	((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):

	((status)?this.icon.nlMinus:this.icon.nlPlus);

	eDiv.style.display = (status) ? 'block': 'none';

};





// [Cookie] Clears a cookie

dTree.prototype.clearCookie = function() {

	var now = new Date();

	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);

	this.setCookie('co'+this.obj, 'cookieValue', yesterday);

	this.setCookie('cs'+this.obj, 'cookieValue', yesterday);

};



// [Cookie] Sets value in a cookie

dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {

	document.cookie =

		escape(cookieName) + '=' + escape(cookieValue)

		+ (expires ? '; expires=' + expires.toGMTString() : '')

		+ (path ? '; path=' + path : '')

		+ (domain ? '; domain=' + domain : '')

		+ (secure ? '; secure' : '');

};



// [Cookie] Gets a value from a cookie

dTree.prototype.getCookie = function(cookieName) {

	var cookieValue = '';

	var posName = document.cookie.indexOf(escape(cookieName) + '=');

	if (posName != -1) {

		var posValue = posName + (escape(cookieName) + '=').length;

		var endPos = document.cookie.indexOf(';', posValue);

		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));

		else cookieValue = unescape(document.cookie.substring(posValue));

	}

	return (cookieValue);

};



// [Cookie] Returns ids of open nodes as a string

dTree.prototype.updateCookie = function() {

	var str = '';

	for (var n=0; n<this.aNodes.length; n++) {

		if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {

			if (str) str += '.';

			str += this.aNodes[n].id;

		}

	}

	this.setCookie('co' + this.obj, str);

};



// [Cookie] Checks if a node id is in a cookie

dTree.prototype.isOpen = function(id) {

	var aOpen = this.getCookie('co' + this.obj).split('.');

	for (var n=0; n<aOpen.length; n++)

		if (aOpen[n] == id) return true;

	return false;

};



// If Push and pop is not implemented by the browser

if (!Array.prototype.push) {

	Array.prototype.push = function array_push() {

		for(var i=0;i<arguments.length;i++)

			this[this.length]=arguments[i];

		return this.length;

	}

};

if (!Array.prototype.pop) {

	Array.prototype.pop = function array_pop() {

		lastElement = this[this.length-1];

		this.length = Math.max(this.length-1,0);

		return lastElement;

	}

};

 function Onclk(obj)
{  
	 //alert(obj.type);
	if(obj.type=='radio')
		return;
	//��������ӽڵ�͸��ڵ�
    if(obj.isSetChildParent=='false')
    	return; 
	//�����ӽڵ�
	//alert(obj.nodeId);  
	var childs = document.all('d'+ obj.treeName + obj.nodeId); 
	if(childs != null)
	{
	var  items = childs.getElementsByTagName("INPUT");	  
		for(var i=0;items.length>i;i++)
		{	
		   if(!items[i].disabled) 
		   items[i].checked=obj.checked;  
		  
		}
     
	}
		  
	//���ø��ڵ�
	 setParent(obj)	;

}

//���ø��ڵ�
function setParent(obj)
{	//ͬ��ڵ� 
	
   if(obj.nodeId==0)return ; 

	var  items = obj.parentElement.parentElement.getElementsByTagName("INPUT"); 
	 // alert(obj.parentElement.parentElement.outerHTML);
	var status = true;
	var statusDisabled = true;
	
	//checked
	for(var i=0;items.length>i;i++)
	{
	   if(items[i].disabled)continue;
	   if(!items[i].checked)
		{  
		   status=false;
		   break;  
		}  
	}
	
	//disabled
	for(var i=0;items.length>i;i++)
	{ 
	   if(!items[i].disabled)
		{  
		   statusDisabled=false;
		   break;  
		}
	}
	
	var VPID = obj.parentElement.parentElement.id; 
	var pId = VPID.substring(2);   
	 
	//alert(pId);
	var pImg0bj = document.all('id' + pId); 
	var pobj = pImg0bj.parentElement.getElementsByTagName("INPUT")[0];
	if(pobj==null)return ;
	
	//check
	if(status) //˵����ڵ�Ҫѡ��	
	{  		
			//disable
			if(statusDisabled)
			{
			 pobj.disabled=true; 
			}else
			pobj.checked=true;
			setParent(pobj); 	 
	}
	else
	{ 
		//false ˵��ͬ�ڵ㼰���ӽڵ��û��ȫ����ѡ��
		  pobj.disabled = false;
		  pobj.checked = false;
		  setParent(pobj); 
	}
	 
		
}




	 /*
	 *
	 *ȫ���ؼ���������
	 */ 	 
	function disableAll()
	{
		  //var ids = strIds.split(","); 
		  var objs = document.all("div_dtree").getElementsByTagName("INPUT");
		  for(var i=0;i<objs.length;i++)
		  { 
		      objs[i].disabled="true";
	      }
	} 	
	

	 /*
	 *
	 *ȫ����� 
	 */ 	 
	function clearAll()
	{
		  //var ids = strIds.split(","); 
		  var objs = document.all("div_dtree").getElementsByTagName("INPUT");
		  for(var i=0;i<objs.length;i++)
		  { 
		      objs[i].checked=false;
	      }
	} 	

	function setChecked(strIds)
	{
		clearAll();
		  var ids = strIds.split(","); 
		  for(var i=0;i<ids.length;i++)
		  { 
		      if(ids[i]=="") return ;
			  var obj = document.all("id_"+ ids[i] );
		      obj.checked=true;
	      } 
	} 	

	
	/* 
	 *���ÿ��õ����
	 */ 
	function setUsable(strIds)
	{
	      
	      disableAll(); 
	      	
	      var ids = strIds.split(","); 
		  for(var i=0;i<ids.length;i++)
		  { 
		      if(ids[i]=="") return ;
			  var obj = document.all("id_"+ ids[i] );
		      obj.disabled="";
	      } 
	} 
 

⌨️ 快捷键说明

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