treeview_kernel.js

来自「精美的AJAX树形菜单」· JavaScript 代码 · 共 1,421 行 · 第 1/3 页

JS
1,421
字号
function ComponentArt_TreeView(qzrm,qzvh){
	this.TreeViewID=qzrm;
	if(!qzvh){
		this.qqGa=new Array();
		}
	else{
		this.qqGa=qzvh;
		};
	this.CollapseImageUrl='';
	this.ExpandImageUrl='';
	this.NoExpandImageUrl='';
	this.LeafNodeImageUrl='';
	this.ParentNodeImageUrl='';
	this.ExpandedParentNodeImageUrl='';
	this.LineImagesFolderUrl='';
	this.NodeCssClass='';
	this.HoverNodeCssClass='';
	this.NodeRowCssClass='';
	this.HoverNodeRowCssClass='';
	this.SelectedNodeCssClass='';
	this.SelectedHoverNodeCssClass='';
	this.SelectedNodeRowCssClass='';
	this.SelectedHoverNodeRowCssClass='';
	this.CollapseTransitionCustomFilter='';
	this.ExpandTransitionCustomFilter='';
	this.NodeEditCssClass='';
	this.FocusedCssClass='';
	this.CssClass='';
	this.ForceHighlightedNodeID='';
	this.qzfw=0;
	this.qzap=0;
	this.qzkj=0;
	}
;
ComponentArt_TreeView.prototype.qqGo=['PostBackID',                'ParentStorageIndex',
																			'ChildIndices',              'Text',
																			'ID',                        'Expanded',
																			'AutoPostBackOnSelect',      'AutoPostBackOnMove',
																			'AutoPostBackOnRename',      'AutoPostBackOnCheckChanged',
																			'AutoPostBackOnExpand',      'AutoPostBackOnCollapse',
																			'ClientSideCommand',         'NavigateUrl',
																			'Target',                    'ImageUrl',
																			'ImageHeight',               'ImageWidth',
																			'LabelPadding',              'Indent',
																			'Selectable',                'ExtendNodeCell',
																			'EditingEnabled',            'DraggingEnabled',
																			'DroppingEnabled',           'ShowCheckBox',
																			'Checked',                   'CssClass',
																			'HoverCssClass',             'RowCssClass',
																			'HoverRowCssClass',          'ContentCallbackUrl',
																			'ExpandedImageUrl',          'SelectedCssClass',
																			'SelectedHoverCssClass',     'SelectedRowCssClass',
																			'SelectedHoverRowCssClass',  'Value',
																			'ToolTip',                   'DraggingAcrossTreesEnabled',
																			'DroppingAcrossTreesEnabled','MarginImageUrl',
																			'PageViewId'];
ComponentArt_TreeView.prototype.AddNode=function(qzz){
	qzz.StorageIndex=-1;
	qzz.ParentStorageIndex=-1;
	qzz.ParentTreeView=this;
	qzz.qzcu=0;
	qzz.SaveState();
	};
ComponentArt_TreeView.prototype.CheckAll=function(){
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		nodes[qzAde].CheckAll();
		}

	;
	};
ComponentArt_TreeView.prototype.CollapseAll=function(){
	this.CollapseTo(0);
	};
ComponentArt_TreeView.prototype.CollapseTo=function(qzcu,qzz){
	var nodes;
	if(!qzz){
		nodes=this.Nodes();
		}
	else{
		nodes=qzz.Nodes();
		};
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		this.CollapseTo(qzcu,nodes[qzAde]);
		if(nodes[qzAde].Expanded&&nodes[qzAde].ChildIndices.length>0&&nodes[qzAde].CalculateDepth()>=qzcu){
			nodes[qzAde].Collapse(true);
			};
		}

	;
	};
ComponentArt_TreeView.prototype.UnCheckAll=function(){
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		nodes[qzAde].UnCheckAll();
		}

	;
	};
ComponentArt_TreeView.prototype.ExpandAll=function(){
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		if(!nodes[qzAde].Expanded&&nodes[qzAde].ChildIndices.length>0){
			nodes[qzAde].Expand(true);
			nodes[qzAde].ExpandAll();
			};
		}

	;
	};
ComponentArt_TreeView.prototype.Nodes=function(){
	var qqSi=FindInArray(this.qqGo,'ParentStorageIndex'),qztn=new Array();
	for(var qzba=0;qzba<this.qqGa.length;qzba++){
		if(this.qqGa[qzba][qqSi]==-1){
			qztn[qztn.length]=this.qzo(qzba);
			};
		}
	;
	return qztn;
	};
ComponentArt_TreeView.prototype.FindNodeById=function(id,bPostbackId){
	var qqSh=FindInArray(this.qqGo,'PostBackID'),qqSg=FindInArray(this.qqGo,'ID'),qzgv=this.qqGa,length=qzgv.length;
	for(var qzba=0;qzba<length;qzba++){
		var qzan=qzgv[qzba];
		if(bPostbackId){
			if(qzan[qqSh]==id){
				return this.qzo(qzba);
				};
			}
		else{
			if(qzan[qqSg]==id){
				var qzsz=this.qzo(qzba);
				qzsz.ResolveAncestors();
				return qzsz;
				};
			};
		}

	;
	};
ComponentArt_TreeView.prototype.Render=function(qzja){
	var qzww=false;
	if(!qzja){
		qzja=this.qzAgh;
		}
	else{
		this.qzAgh=qzja;
		qzww=true;
		};
	var qzn=document.getElementById(qzja);
	qzn.innerHtml="";
	var qzAls='',qzsm=this.Nodes();
	for(var qzba=0;qzba<qzsm.length;qzba++){
		qzAls+=qzsm[qzba].GetHtml();
		}
	;
	qzn.innerHTML=qzAls;
	this.SelectedNodeDom=null;
	this.SelectedNodeCellDom=null;
	if(qzww&&document.all){
		var qzux=document.getElementById(this.TreeViewID+"_ScrollData");
		if(qzux){
			var qzAif=qzux.value.split(',');
			setTimeout(
				'if('+qzja+'.scrollLeft==0) '+qzja+'.scrollLeft='+qzAif[0]+';if('+qzja+'.scrollTop==0) '+qzja+'.scrollTop='
					+qzAif[1]+';',
				100);
			};
		};

	qzn.onmousemove=ComponentArt_CancelEvent;
	};
ComponentArt_TreeView.prototype.SelectNodeById=function(itemId,qzma){
	var qzm=this.FindNodeById(itemId,qzma);
	if(!qzm||!qzm.Selectable){
		return;
		};
	var qzcd=document.getElementById(this.TreeViewID+'_item_'+qzm.StorageIndex);
	if(!qzcd&&this.ExpandSelectedPath){
		var qzee=qzm,qzfk=null,qzdg=null;
		while(qzee.ParentStorageIndex>=0){
			qzee=qzee.GetParentNode();
			if(qzee.Expanded){
				break;
				};
			qzdg=qzfk;
			qzfk=qzee;
			if(qzdg){
				qzdg.Expanded=true;
				qzdg.SaveState();
				};
			}
		;
		if(qzfk){
			ComponentArt_ExpandCollapse(qzfk.StorageIndex,this.TreeViewID,qzfk.CalculateDepth())
			};
		qzcd=document.getElementById(this.TreeViewID+'_item_'+qzm.StorageIndex);
		};

	if(!qzcd){
		this.SelectedNode=qzm;
		}
	else{
		var qzgo=document.getElementById(this.TreeViewID+'_item_'+qzm.StorageIndex+'_cell');
		qzrb(this,qzm,qzcd,qzgo,qzma);
		qzAgv(qzcd,qzma);
		};
	};
ComponentArt_TreeView.prototype.GetFirstRootNodeIndex=function(){
	var qqSi=FindInArray(this.qqGo,'ParentStorageIndex');
	for(var qzba=0;qzba<this.qqGa.length;qzba++){
		if(this.qqGa[qzba][qqSi]==-1){
			return qzba;
			};
		}
	;
	return 0;
	};
ComponentArt_TreeView.prototype.GetLastRootNodeIndex=function(){
	var qqSi=FindInArray(this.qqGo,'ParentStorageIndex');
	for(var qzba=this.qqGa.length-1;qzba>=0;qzba--){
		if(this.qqGa[qzba][qqSi]==-1){
			return qzba;
			};
		}
	;
	return 0;
	};
ComponentArt_TreeView.prototype.qzo=function(qzgc,qzbo){
	if(qzgc<0){
		return null;
		};
	var qzan=this.qqGa[qzgc],qzm=new ComponentArt_TreeViewNode();
	for(var qzba=0;qzba<this.qqGo.length;qzba++){
		if(qzan[qzba]!=null)
			qzm[this.qqGo[qzba]]=qzan[qzba];
		}
	;
	if(!qzm.Text)
		qzm.Text='';
	if(qzbo){
		qzm.ParentNode=qzbo;
		qzm.qzcu=qzbo.qzcu+1;
		};
	qzm.ParentTreeView=this;
	qzm.StorageIndex=qzgc;
	return qzm;
	};
function ComponentArt_TreeViewNode(){
	this.ID='';
	this.PostBackID='';
	this.ParentTreeView=null;
	this.ParentNode=null;
	this.qzcu=0;
	this.Text='';
	this.Value='';
	this.LabelPadding=0;
	this.Indent=0;
	this.StorageIndex=-1;
	this.ParentStorageIndex=-1;
	this.ChildIndices=new Array();
	}
;
ComponentArt_TreeViewNode.prototype.AddNode=function(qzz,qzgc){
	qzz.ParentStorageIndex=this.StorageIndex;
	qzz.ParentTreeView=this.ParentTreeView;
	qzz.qzcu=this.qzcu+1;
	qzz.SaveState();
	this.ChildIndices[this.ChildIndices.length]=qzz.StorageIndex;

	if((qzgc||qzgc==0)&&qzgc<this.ChildIndices.length-1){
		for(var qzba=this.ChildIndices.length-1;qzba>qzgc;qzba--){
			this.ChildIndices[qzba]=this.ChildIndices[qzba-1];
			}
		;
		this.ChildIndices[qzba]=qzz.StorageIndex;
		};
	};
ComponentArt_TreeViewNode.prototype.CalculateDepth=function(){
	var qzcu=0;
	for(var qzz=this;qzz.ParentStorageIndex>=0;qzz=qzz.ParentNode?qzz.ParentNode:qzz.GetParentNode()){
		qzcu++;
		}
	;
	this.qzcu=qzcu;
	return qzcu;
	};
ComponentArt_TreeViewNode.prototype.ClearChildren=function(){
	for(var qzba=0;qzba<this.ChildIndices.length;qzba++){
		this.RemoveNode(this.ChildIndices[qzba]);
		}

	;
	};
ComponentArt_TreeViewNode.prototype.CheckAll=function(){
	if(this.ShowCheckBox&&!this.Checked){
		this.Checked=true;
		this.SaveState();
		};
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		nodes[qzAde].CheckAll();
		}

	;
	};
ComponentArt_TreeViewNode.prototype.UnCheckAll=function(){
	if(this.ShowCheckBox&&this.Checked){
		this.Checked=false;
		this.SaveState();
		};
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		nodes[qzAde].UnCheckAll();
		}

	;
	};
ComponentArt_TreeViewNode.prototype.Collapse=function(qqZj){
	if(this.Expanded){
		qzqp(this.ParentTreeView,document.getElementById(this.ParentTreeView.TreeViewID+'_item_'+this.StorageIndex+'_div'),
				 this,               qqZj);
		};
	};
ComponentArt_TreeViewNode.prototype.CollapseAll=function(){
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		if(nodes[qzAde].Expanded&&nodes[qzAde].ChildIndices.length>0){
			nodes[qzAde].Collapse(true);
			nodes[qzAde].CollapseAll();
			};
		}

	;
	};
ComponentArt_TreeViewNode.prototype.Expand=function(qqZj){
	if(!this.Expanded&&this.ChildIndices.length>0){
		qzzn(this.ParentTreeView,document.getElementById(this.ParentTreeView.TreeViewID+'_item_'+this.StorageIndex+'_div'),
				 this,               this.CalculateDepth(),
				 qqZj);
		};
	};
ComponentArt_TreeViewNode.prototype.ExpandAll=function(){
	var nodes=this.Nodes();
	for(var qzAde=0;qzAde<nodes.length;qzAde++){
		if(!nodes[qzAde].Expanded&&nodes[qzAde].ChildIndices.length>0){
			nodes[qzAde].Expand(true);
			nodes[qzAde].ExpandAll();
			};
		}

	;
	};
ComponentArt_TreeViewNode.prototype.GetCurrentIndex=function(){
	if(this.ParentStorageIndex>=0){
		if(!this.ParentNode)
			this.ParentNode=this.GetParentNode();
		for(var qzgc=0;qzgc<this.ParentNode.ChildIndices.length;qzgc++){
			if(this.ParentNode.ChildIndices[qzgc]==this.StorageIndex){
				return qzgc;
				};
			}
		;
		}
	else{
		if(this.ParentTreeView){
			var qzsm=this.ParentTreeView.Nodes();
			for(var qzgc=0;qzgc<qzsm.length;qzgc++){
				if(qzsm[qzgc].StorageIndex==this.StorageIndex){
					return qzgc;
					};
				}
			;
			};
		};

	return -1;
	};
ComponentArt_TreeViewNode.prototype.GetParentNode=function(){
	if(this.ParentStorageIndex<0){
		return null;
		}
	else{
		this.ParentNode=this.ParentTreeView.qzo(this.ParentStorageIndex);
		return this.ParentNode;
		};
	};
ComponentArt_TreeViewNode.prototype.Nodes=function(param){
	if(!param){
		var qzie=new Array(),length=this.ChildIndices.length;
		for(var qzba=0;qzba<length;qzba++){
			var qzm=this.ParentTreeView.qzo(this.ChildIndices[qzba],this);
			qzie[qzie.length]=qzm;
			}
		;
		return qzie;
		}
	else{
		if(typeof (param)=='number'){
			return this.ParentTreeView.qzo(this.ChildIndices[param],this);
			}
		else{
			};
		};

	return null;
	};
ComponentArt_TreeViewNode.prototype.Remove=function(){
	if(this.ParentTreeView.SelectedNode!=null&&this.ParentTreeView.SelectedNode.StorageIndex==this.StorageIndex){
		this.ParentTreeView.SelectedNode=null;
		};
	if(this.ParentTreeView.KeyboardEnabled){
		ComponentArt_InitKeyboard(this.ParentTreeView);
		};
	var qzsi=this.GetParentNode();

	if(qzsi!=null){
		qzsi.RemoveNode(this.StorageIndex);
		}
	else{
		this.ParentStorageIndex=-33;
		this.SaveState();
		};
	};
ComponentArt_TreeViewNode.prototype.RemoveNode=function(qzgc){
	var qzba;
	for(qzba=0;qzba<this.ChildIndices.length;qzba++){
		if(this.ChildIndices[qzba]==qzgc){
			break;
			};
		}
	;
	for(;qzba<this.ChildIndices.length-1;qzba++){
		this.ChildIndices[qzba]=this.ChildIndices[qzba+1];
		}
	;
	this.ChildIndices.length--;
	};
ComponentArt_TreeViewNode.prototype.ResolveAncestors=function(){
	var qzAer=this;
	while(qzAer.ParentStorageIndex>=0){
		qzAer.ParentNode=qzAer.GetParentNode();
		qzAer=qzAer.ParentNode;
		}

	;
	};
ComponentArt_TreeViewNode.prototype.SaveState=function(){
	var qzam;
	if(this.ParentTreeView&&this.StorageIndex>=0){
		qzam=this.ParentTreeView.qqGa[this.StorageIndex];
		}
	else{
		qzam=new Array();
		};
	for(var qzba=0;qzba<this.ParentTreeView.qqGo.length;qzba++){
		var qqGz=this.ParentTreeView.qqGo[qzba];
		if(qqGz=='Text'&&qzam[qzba]!=this.Text){
			this.qzAdh();
			};
		if(qqGz=='Expanded'&&qzam[qzba]!=this.Expanded){
			this.qzAbp();
			};
		if(qqGz=='Checked'&&qzam[qzba]!=this.Checked){
			this.qzAat();
			};
		if(qqGz=='Value'&&qzam[qzba]!=this.Value){
			this.qzAdg();
			};
		qzam[qzba]=this[qqGz];
		}
	;
	var qzgv=this.ParentTreeView.qqGa;
	if(this.StorageIndex<0){

⌨️ 快捷键说明

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