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

📄 tree_maker.js

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JS
📖 第 1 页 / 共 2 页
字号:
/************************************************************************************
*Title   :   treeMaker 脚本文件 (Ver 3.0)
*program :   区钊贤
*website :   http://www.ouzx.com
*e-mail  :   ouzhaoxian@21cn.com
*Date    :   2003-03-03  (all right reserved)
************************************************************************************/
var Tree_CHILD=-1;
var Tree_LAST=-2;
var Tree_ROOT=-3;
var Tree_FIRST=-4;
var Tree_SIBLING=-5;
var Tree_PREV=-6;
var Tree_NEXT=-7;
var Tree_const_begin_folder=-1;
var Tree_const_folder=0;
var Tree_const_end_folder=1;
var Tree_const_file=2;
var Tree_LINK=3;
var Tree_SCRIPT=4;
var Tree_const_end=5;
var Tree_isNC6 = (document.getElementById && !document.all)?true:false;
var Tree_isIE = (document.all)?true:false;
if(Tree_isNC6==false&&Tree_isIE==false)
	alert("本脚本不支持你的浏览器");
//---------------------------
var Tree_treeView_index=0;
var Tree_node_index=0;
var Tree_treeView_array=new Array();
var Tree_node_array=new Array();
//----------------------------
function Tree_action(type,script,link,target,treeViewIndex)
{
	this.type=type;
	this.link=link;
	this.target=target;
	this.script=script;
	this.treeViewIndex = treeViewIndex;
}
//---------------------------
function Tree_treeView()
{
	this.showLine=false;
	this.lineFolder="./";//连线图片文件夹
	this.Indent=13;
	this.useImage=this.useHint=this.useStatus=this.useTitleAsStatus
		=this.showSelect=this.useTitleAsHint=true;
	this.fileImg=this.folderImg1=this.folderImg2="";	
	this.folderClass1=this.folderClass2=this.folderClass3=
		this.fileClass1=this.fileClass2=this.fileClass3="";
	this.target="_blank";
	//----------------
	this.selectID=null;
	this.id=Tree_treeView_index;
	this.flag=false;
	Tree_treeView_array[this.id]=this;
	var action=new Tree_action(0,0,0,0,Tree_treeView_index++);
	this.container=new Tree_node("","","","","",action);
	this.container.expand=true;	
	//---------call back function
	this.callback_expanding=function callback_expanding(nodeID){return true;}
	this.callback_expanded=function callback_expanded(nodeID){}
	this.callback_collapsing=function callback_collapsing(nodeID){return true;}
	this.callback_collapsed=function callback_collapsed(nodeID){}
	this.callback_click=function callback_click(nodeID){return true;}
	this.callback_rightClick=function callback_rightClick(nodeID){return true;}
	//---------	
	this.getRoot=function getRoot(){
		return this.container.childCount>0?this.container.child[0]:null;
	}
	this.click=function click(nodeID){
		var node=this.getNode(nodeID);
		if(node) Tree_clickNode(nodeID);
	}
	this.helper=function helper(node){
		if(node.childCount==0) return;
		this.expand(node.id,true);
		var i=0;
		while(i<=node.childCount-1)
			this.helper(node.child[i++]);
	}
	this.expandAll=function expandAll(){
		this.flag=true;
		var i=0;
		while(i<=this.container.childCount-1)
			this.helper(this.container.child[i++]);
		this.flag=false;
	}
	this.select=function select(nodeID,flag){
		var node=this.getNode(nodeID);
		if(node){
			flag=(typeof(flag)=="boolean"?flag:true);
			if(flag)Tree_selectNode(nodeID);
			else {
				var td=document.getElementById("Tree_td_"+nodeID);
				this.selectID=null;
				if(this.showSelect && td)
					td.className=Tree_node_array[nodeID].childCount>0?
						this.folderClass1:this.fileClass1;
			}
			node.selected=flag;
		}
	}
	this.setText=function setText(nodeID,text){
		var node=this.getNode(nodeID);
		if(node)
			node.setText(text);	
	}
	this.getImage=function getImage(nodeID){
		var node=this.getNode(nodeID);
		if(node)return node.getImage();
		return null;
	}
	this.getSelect=function getSelect(){//返回选择结点
		if(this.selectID!=null)
			return this.getNode(this.selectID);
		return null;
	}
	this.expand=function expand(nodeID,isExpand){
		var node=this.getNode(nodeID);
		this.flag=true;
		var div=document.getElementById("Tree_expand_"+nodeID);
		var td=document.getElementById("Tree_td_"+nodeID);
		if(node){
			if(node.expanded==isExpand)return;			
			if(td)td.onclick();			
			else node.expanded=isExpand;
		}
		this.flag=false;
	}
	this.clear=function clear(){
		this.container.child.length=this.container.childCount=0;
		this.refresh();
	}
	this.add=function add(relate_ID,nOption,nIndex,text,hint,status,img1,img2){
		if(nOption==Tree_ROOT)	{
			return this.container.addChild(nIndex,text,hint,status,img1,img2);
		}
		if(nOption==Tree_CHILD){
			var parent=this.getNode(relate_ID);
			if(parent==null) return null;
			return parent.addChild(nIndex,text,hint,status,img1,img2);
		}
		if(nOption==Tree_SIBLING){
			if(relate_ID==this.container.id) return null;
			var node=this.getNode(relate_ID);
			if(node==null) return null;
			return node.addSibling(nIndex,text,hint,status,img1,img2);
		}
		return null;
	}
	this.del=function del(id){
		if(id==this.container.id)
			return;
		var obj=this.getNode(id);
		if(obj)obj.parent.delChild(obj.index);
	}
	this.getNode=function getNode(nID){
		if(nID==this.container.id)return null;
		var obj=null;
		try{
			obj=Tree_node_array[nID];
			if(obj&&obj.id==nID)
				return obj.container()==this.container?obj:null;
			return null;
		}
		catch(e){return null;}		
	}
	this.refresh=function refresh(){
		this.container.refresh();		
	}
	this.isReady=function isReady(){
		return document.getElementById("Tree_treeView_"+this.id)!=null;
	}
}
//-----------------------------
function Tree_node(text,hint,status,img1,img2,action)
{
	this.img1=typeof(img1)=="string"?img1:"";
	this.img2=typeof(img2)=="string"?img2:"";
	this.text=typeof(text)=="string"?text:"";
	this.hint=typeof(hint)=="string"?hint:"";
	this.status=typeof(status)=="string"?status:"";
	//------------------
	this.child = new Array();
	this.id=Tree_node_index;
	this.parent=null;
	this.action=action;		
	this.expanded=false;
	this.selected=false;
	this.index=0;
	this.childCount=0;
	Tree_node_array[Tree_node_index++]=this;
	//------------------
	this.addChild=function addChild(index,text,hint,status,img1,img2){
		var action=new Tree_action(0,0,0,0,this.action.treeViewIndex);
		var node=new Tree_node(text,hint,status,img1,img2,action);
		this.add(node,index);
		return node;
	}
	this.getImage=function getImage(){
		return document.getElementById("Tree_img_"+this.id);
	}
	this.refresh=function refresh(){
		if(this.parent)return;
		var html="<DIV id='Tree_treeView_"+this.id+"'>";
		var div=document.getElementById("Tree_treeView_"+this.id);
		if(div==null)
			document.write(html+this.getHtml()+"</DIV>");
		else div.innerHTML=this.getHtml();
	}
	this.setLink=function setLink(link,target){
		if(this.parent==null) return;
		this.action.type=Tree_LINK;
		this.action.target=target;
		this.action.link=link;
	}
	this.setScript=function setScript(script){
		this.action.type=Tree_SCRIPT;
		this.action.script=script;
	}
	this.next=function getNext(){
		if(this.parent==null || this.index>=this.parent.childCount-1)
			return null;
		return (this.parent.child[this.index+1]);
	}
	this.prev=function getPrev(){
		if(this.parent==null || this.index<=0)
			return null;
		return (this.parent.child[this.index-1]);
	}
	this.container=function container(){
		var tmp=this.parent;
		while(tmp && tmp.parent)
			tmp=tmp.parent;
		return tmp;
	}
	this.addSibling=function addSibling(index,text,hint, status,img1,img2){
		if(this.parent==null)return null;
		if(index==Tree_PREV) index=this.index;
		if(index==Tree_NEXT) index=this.index+1;
		return this.parent.addChild(index,text,hint,status,img1,img2);
	}
	this.add=function add(childNode,index){
		if(index==Tree_FIRST)
			index=0;
		if(index==Tree_LAST)
			index=this.childCount;
		if(index<0)
			index=0;
		if(index>this.childCount)
			index=this.childCount;
		var len=this.childCount-1;
		while(len>=index){
			this.child[len+1]=this.child[len];
			this.child[len+1].index=len+1;
			len--;			
		}
		this.child[index]=childNode;
		childNode.index=index;
		childNode.parent=this;
		this.childCount++;
		var tree=this.getTreeView();
		if(tree.flag==true) return;
		if(tree.isReady()) {
			var img = this.getImage();
			if(this.parent && img )
				img.src=Tree_imgSrc(this);
			var line=document.getElementById("Tree_line_"+ this.id);
			if(line)line.src=Tree_GetLineImg(this);			
			var parent=document.getElementById("Tree_expand_"+ this.id);
			if(parent==null)
				parent=document.getElementById("Tree_treeView_"+ this.id);	
			var div=document.createElement("DIV");
			div.innerHTML=Tree_table(childNode)+"<DIV id=Tree_expand_"+ childNode.id+
						" STYLE='{display:"+(childNode.expanded?"block;":"none;")
						+"}'></DIV>";
			var before=null;
			if(this.childCount==1);
			else if(this.childCount-1==index){
				var node=this.child[index-1];
				line=document.getElementById("Tree_line_"+ node.id);
				if(line){
					line.src=Tree_GetLineImg(node);
					line=document.getElementsByName("Tree_td_line_"+ node.id);
					for(var i=line.length-1;i>=0;i--)
						line[i].innerHTML="<IMG  src="+tree.lineFolder+"/tree_I.gif>";
				}
			}
			else {
				line=document.getElementById("Tree_line_"+ this.child[index+1].id);
				if(line)line.src=Tree_GetLineImg(this.child[index+1]);
				before=document.getElementById("Tree_expand_"+this.child[index+1].id).parentNode;
			}
			parent.insertBefore(div,before);			
		}
		else this.getTreeView().refresh();
	}//--------------
	this.contain=function contain(childnodeID)
	{
		if(childnodeID==null) return false;
		var tmp=Tree_node_array[childnodeID];
		while(tmp.parent)
		{
			if(tmp.parent==this||tmp==this)
				return true;
			tmp=tmp.parent;
		}
		return false;
	}
	//-----------
	this.level=function level()	{
		if(this.parent==null) return -1;//container
		var tmp=this;var n=0;
		while(tmp && tmp.parent)	{
			n++;
			tmp=tmp.parent;
		}
		return n;
	}
	this.getParentEx=function getParentEx(level){
		var p=this;var n=this.level();
		if(n<=1)return null;
		while(p && level!=n){
			p=p.parent;n--;
		}
		return p;
	}
	//-------------------

⌨️ 快捷键说明

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