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

📄 ig_webdropdown.js

📁 研究怎样通过手写代码来完成自动生成代码
💻 JS
📖 第 1 页 / 共 3 页
字号:
/* 
Infragistics WebDropDown script. 
Version 5.1.20051.37
js version 1.2.2005.6
Copyright (c) 2003-2005 Infragistics, Inc. All Rights Reserved.
Functions marked public are for use by developers and are documented and supported.
All other functions are for the internal use only.
*/
// private - hides all dropdown select controls for the document.
var igdrp_hidden=false;
function igdrp_hideDropDowns(bHide)
{ 
	if(igdrp_dropDowns==null || bHide==igdrp_hidden)return;
	igdrp_hidden=bHide;
	for(var i=0;i<igdrp_dropDowns.length;i++)igdrp_dropDowns[i].style.visibility=bHide?'hidden':'visible';
}
// public - Retrieves the server-side unique id of the combo
function igdrp_getUniqueId(comboName)
{
	var combo=igdrp_getComboById(comboName);
	return (combo==null)?null:combo.UniqueId;
}
function igdrp_getElementById(id){return ig_csom.getElementById(id);}
// public - returns the combo object for the Item Id
function igdrp_getComboById(id,e)
{
	var o=null,i=0;
	while(e!=null && ig_csom.isEmpty(id))
	{
		try{if(e.getAttribute!=null)id=e.getAttribute("ig_drp");}catch(ex){}
		if(++i>6)return null;
		e=e.parentNode;
	}
	if(!ig_csom.isEmpty(id))if((e=igdrp_all)!=null)if((o=e[igdrp_comboIdById(id)])==null)
		for(i in e){if((o=e[i])!=null)if(o.Id==id || o.ClientUniqueId==id || o.UniqueId==id)break;else o=null;}
	return o;
}
// public - returns the combo object from an Item element
function igdrp_getComboByItem(item){return igdrp_all[igdrp_comboIdById(item.id)];}
// public - returns the combo Name from an itemId
function igdrp_comboIdById(itemId){return itemId.split("_")[0];}
// Fires an event to client-side script and then to the server is necessary
function igdrp_fireEvent(oCombo,eventName,param)
{
	var oEvent=new ig_EventObject();
	ig_fireEvent(oCombo,eventName,param,oEvent);
	return oEvent;
}
// Performed on page initialization
if(typeof igdrp_all!="object")
	var igdrp_all=new Object();
igdrp_all._once=false;
var igdrp_dropDowns;
// initializes the combo object on the client
function igdrp_initCombo(comboId)
{
   var elem=igdrp_getElementById(comboId);
   var oCombo=new igdrp_combo(elem,eval("igdrp_"+comboId+"_Props"));
   ig_fireEvent(oCombo,oCombo.Events.InitializeCombo[0],oCombo,comboId);
   if(ig_csom.IsIE && oCombo.HideDropDowns==true && igdrp_dropDowns==null)igdrp_dropDowns=document.all.tags("SELECT");
   oCombo.Loaded=true;
   return oCombo;
}
function igdrp_button(props)
{
	this.ImageUrl1=props[0];
	this.ImageUrl2=props[1];
	this.DefaultStyleClassName=props[2];
	this.HoverStyleClassName=props[3];
}
function igdrp_evt(e)
{
	if(e==null)if((e=window.event)==null)return;
	var o,t=e.type,src=e.srcElement;
	if(t=="unload"){ig_dispose(igdrp_all);return;}
	if(src==null)if((src=e.target)==null)src=this;
	if((o=igdrp_getComboById(null,src))==null || o.doEvt==null)return;
	o.doEvt(e,t,src);
}
// constructor for the combo object
function igdrp_combo(elem,comboProps)
{
	this.Id=elem.id;
	igdrp_all[this.Id]=this;
	this.Element=elem;
	elem.setAttribute("ig_drp",this.Id);
	ig_csom.addEventListener(elem,"mousedown",igdrp_evt);
	ig_csom.addEventListener(elem,"mouseup",igdrp_evt);
	ig_csom.addEventListener(elem,"mouseout",igdrp_evt);
	ig_csom.addEventListener(elem,"mouseover",igdrp_evt);
	if(!igdrp_all._once)
	{
		ig_csom.addEventListener(window,"unload",igdrp_evt);
		ig_csom.addEventListener(document,"mousedown",igdrp_mouseDown);
		if(document.captureEvent)document.captureEvent(Event.MOUSEDOWN);
	}
	igdrp_all._once=true;
	this.Element.Object=this;
	this.UniqueId=comboProps[0];
	this.DropButton=new igdrp_button(comboProps[1])
	this.EditStyleClassName=comboProps[3];
	this.DropDownStyleClassName=comboProps[4];
	this.HideDropDowns=comboProps[5];
	this.editable=comboProps[6];
	this.readOnly=comboProps[7]
	this.dropDownAlignment=comboProps[8];
	this.getDropDownAlignment=function(){return this.dropDownAlignment;}
	this.setDropDownAlignment=function(align){this.dropDownAlignment=align;ig_ClientState.setPropertyValue(this.stateNode,"DropDownAlignment",align);this.updatePostField();}
	this.autoCloseUp=comboProps[9];
	this.Dropped=comboProps[10];
	this.getAutoCloseUp=function(){return this.autoCloseUp;}
	this.setAutoCloseUp=function(auto){this.autoCloseUp=auto;ig_ClientState.setPropertyValue(this.stateNode,"AutoCloseUp",auto);this.updatePostField();}
	this.isEnabled=function(){return !this.inputBox.disabled;}
	this.setEnabled=function(enable){this.inputBox.disabled=!enable;ig_ClientState.setPropertyValue(this.stateNode,"Enabled",enable);this.updatePostField();}
	this.ClientUniqueId=this.UniqueId.replace(/:/gi,"x").replace(/_/gi,"x");
	var box=this.inputBox=igdrp_getElementById(this.ClientUniqueId+"_input");
	var h=box.offsetHeight;
	if(h<8)if((h=box.parentNode.offsetHeight)>7)box.style.height=h;
	this.DropButton.Image=igdrp_getElementById(this.ClientUniqueId+"_img");
	this.postField=igdrp_getElementById(this.UniqueId+"_hidden");
	this.elemCal=this.container=igdrp_getElementById(this.ClientUniqueId+"_container");
	this.ForeColor=box.style.color;
	this.BackColor=box.style.backgroundColor;
	this.Events=new igdrp_events(eval("igdrp_"+this.ClientUniqueId+"_Events"));
	this.Loaded=false;
	this.TopHoverStarted=false;
	this.focus=function(){try{this.inputBox.focus();}catch(e){}}
	this.isEditable=function(){return this.editable;}
	this.setEditable=function(editable)
	{
		this.editable=editable;
		this.inputBox.readOnly=(!editable)?!editable:this.isReadOnly();
		ig_ClientState.setPropertyValue(this.stateNode,"Editable",editable);
		this.updatePostField();
	}
	this.isReadOnly=function(){return this.readOnly;}
	this.setReadOnly=function(readOnly)
	{
		this.readOnly=readOnly;
		this.inputBox.readOnly=(readOnly==true?readOnly:!this.isEditable());
		ig_ClientState.setPropertyValue(this.stateNode,"ReadOnly",readOnly);
		this.updatePostField();
	}
	this.getValue=function(){return this.value;}
	this.getText=function(){return this.inputBox.value;}
	this.setText=function(newValue,bFireEvent){this.updateValue(newValue,bFireEvent);}
	this.updatePostField=function(value){if(this.postField!=null)this.postField.value=ig_ClientState.getText(this.stateItems);}
	this.fireServerEvent=function(eventName,data){if(!this.posted){this.posted=true;__doPostBack(this.UniqueId,eventName+":"+data);}}
	this.isDropDownVisible=function(){return this.Dropped;}
	this.setDropDownVisible=function(bDrop)
	{
		var evt,tPan=this.transPanel,pan=this.container,edit=this.Element;
		if(pan==null || this.isReadOnly()|| this.Dropped==bDrop)return;
		if(bDrop)
		{
			evt=igdrp_fireEvent(this,this.Events.BeforeDropDown[0],pan);
			if(evt.cancel){delete evt;return;}
			this.focus();
			if(this.Calendar!=null)this.Calendar.setSelectedDate(this.getValue());
			var editH=edit.offsetHeight,editW=edit.offsetWidth,elem=edit,x=pan.parentNode,body=window.document.body;
			if(editH==null)editH=0;
			if(x.tagName!="FORM"&&x.tagName!="BODY"){ig_csom._skipNew=true;x.removeChild(pan);body.appendChild(pan);ig_csom._skipNew=false;}
			pan.style.visibility="visible";
			pan.style.display="";
			var panH=pan.offsetHeight,panW=pan.offsetWidth,z=0;
			if((x=this.elemCal.offsetHeight)>panH)panX=x;
			if((x=this.elemCal.offsetWidth)>panW)panW=x;
			if(tPan==null && this.HideDropDowns && ig_csom.IsIE)
			{	
				this.transPanel=tPan=ig_csom.createTransparentPanel();
				if(tPan!=null)
				{
					while((edit=edit.parentNode)!=null)if(edit.style!=null)if(edit.style.zIndex>z)z=edit.style.zIndex;
					if(++z>tPan.Element.style.zIndex)tPan.Element.style.zIndex=z;
					pan.style.zIndex=tPan.Element.style.zIndex+1;
				}
			}
			var y=editH;x=0;
			while(elem!=null)
			{
				if(elem.offsetLeft!=null)x+=elem.offsetLeft;
				if(elem.offsetTop!=null)y+=elem.offsetTop;
				if(elem.nodeName=="HTML"&&elem.clientHeight>body.clientHeight)body=elem;
				elem=elem.offsetParent;
			}
			if((z=this.dropDownAlignment)==1)x-=(panW-editW)/2;
			else if(z==2)x-=panW-editW;
			if((y-body.scrollTop)*2>body.clientHeight+editH)y-=(panH+editH);
			if(x<(z=body.scrollLeft))x=z;
			else if(x+panW>(z+=body.clientWidth))x=z-panW;
			pan.style.left=x;
			pan.style.top=y;
			this.ExpandEffects.applyFilter();
			if(tPan!=null){tPan.setPosition(y-1,x-1,panW+2,panH+2);tPan.show();}
			this.Dropped=true;
			igdrp_all._droped=this;
			igdrp_fireEvent(this,this.Events.AfterDropDown[0],pan);
		}
		else 
		{
			if((evt=this.editor)!=null)if((evt=evt.elem.Validators)!=null)
				for(var i=0;i<evt.length;i++)try{ValidatorValidate(evt[i]);}catch(ex){}
			evt=igdrp_fireEvent(this,this.Events.BeforeCloseUp[0],pan);
			if(evt.cancel){delete evt;return;}
			pan.style.visibility="hidden";
			pan.style.display="none";
			if(tPan!=null)tPan.hide();
			this.Dropped=false;
			igdrp_all._droped=null;
			igdrp_fireEvent(this,this.Events.AfterCloseUp[0],pan);
			evt=null;
			if(this.changed){this.changed=false;this.updateValue();}
		}
		ig_ClientState.setPropertyValue(this.stateNode,"ShowDropDown",bDrop);this.updatePostField();
	}
	this.getVisible=function(){return (this.Element.style.display!="none" && this.Element.style.visibility!="hidden");}
	this.setVisible=function(show,left,top,width,height)
	{
		var w=width,h=height,bdr=-1,e=this.Element,im=this.DropButton.Image,edit=this.inputBox;
		var s=e.style,t=edit.value;
		if(show)edit.value="";else this.setDropDownVisible(false);
		s.display=show?"":"none";
		s.visibility=show?"visible":"hidden";
		if(top!=null&&show)
		{
			s.position="absolute";
			s.top=top;
			s.left=left;
			if(e.clientWidth)bdr=e.offsetWidth-e.clientWidth;
			if(!(bdr>=0&&bdr<7))bdr=s.borderWidth*2;if(!(bdr>=0&&bdr<7))bdr=0;
			if((h-=bdr)<1)h=1;edit.style.height=im.style.height=h;
			s.height=height;
			if((w-=im.offsetWidth+bdr)<1)w=1;edit.style.width=w;
			s.width=width;
			this.setFocusTop();
		}
		if(show)this.inputBox.value=t;
	}
	this.setFocusTop=function(){this.inputBox.select();this.focus();}
	this.updateValue=function(newValue,suppressEvent)
	{
		if(this.editor!=null)
		{
			var date=this.editor.getDate();
			if(date!=null)newValue=date.getFullYear()+','+(date.getMonth()+1)+','+date.getDate();
		}
		ig_ClientState.setPropertyValue(this.stateNode,"Value",(newValue!=null&&newValue.length>0?newValue:(this.getNullDateLabel!=null&&this.getNullDateLabel().length>0?this.getNullDateLabel():" ")));
		this.updatePostField();
		if(suppressEvent)return;
		var evt=igdrp_fireEvent(this,this.Events.ValueChanged[0],this.getValue());
		if((evt.needPostBack||this.Events.ValueChanged[1])&& !evt.cancelPostBack){
			if(this.getAutoCloseUp())this.setDropDownVisible(false);
			this.fireServerEvent('ValueChanged',this.editor.getText());
		}
		delete evt;
	}
	this.stateItems=ig_ClientState.createRootNode();
	this.stateNode=ig_ClientState.addNode(this.stateItems,"DateChooser");
	this.ExpandEffects=new igdrp_expandEffects(this.container,comboProps[2],this);
	this.onImgKeyDown=function(e)
	{
		var me=igdrp_getComboById(e.srcElement.parentElement.parentElement.parentElement.parentElement.id);
		if(!me || !me.Loaded)return;
		var keyCode=(e.keyCode);
		var bOpening=false;
		if(keyCode==40 || (!me.Dropped && (keyCode==32 || keyCode==13)))
			bOpening=true;
		else if(keyCode==27 || (me.Dropped && (keyCode==32 || keyCode==13)))
			bOpening=false;
		else return;
		if(bOpening)
		{
			me.setDropDownVisible(true);
			me.Calendar.setDefaultTabableDateCell(true);
		}
		else
		{
			me.setDropDownVisible(false);
			me.updateValue(me.getText(),false);
		}
	}
	this.onKeyDown=function(oEditor,value,oEvent)
	{
		var me=oEditor.parent,evnt=oEvent.event;
		if(!me.Loaded)return;
		var keyCode=evnt.keyCode;
		switch(keyCode)
		{
			case 40://DownArrow
				if(evnt.altKey){me.setDropDownVisible(true);return false;}break;
			case 27://Esc
			case 13:me.setDropDownVisible(false);me.updateValue(me.getText(),false);break;
		}
    	ig_fireEvent(me,me.Events.EditKeyDown[0],keyCode,oEvent);
 		me.fireMulticastEvent("keydown",oEvent);
    	if(oEvent.cancel)ig_cancelEvent(evnt);
	}
	this.onKeyUp=function(oEditor,value,oEvent)
	{
		var me=oEditor.parent;
		if(me.Loaded)ig_fireEvent(me,me.Events.EditKeyUp[0],oEvent.event.keyCode,oEvent);
	}
	this.onBlur=function(oEditor,value,oEvent)
	{
		var me=oEditor.parent;
		if(!me.Loaded)return;		
		if(oEditor.changed)if(me.Dropped)me.changed=true;else me.updateValue();
		if(!me.Dropped)
		{
			if(me.endEditCell!=null)me.endEditCell();
			ig_fireEvent(me,me.Events.OnBlur[0],me,oEvent);
			me.fireMulticastEvent("blur",oEvent);
		}
	}
	if(this.Dropped && window.setTimeout!=null)
	{
		window.setTimeout('igdrp_getComboById(\"'+this.Id+'\").setFocusTop();',10);
		window.setTimeout('igdrp_getComboById(\"'+this.Id+'\").setDropDownVisible('+this.Dropped+');',100);
	}
	this.handlers=new Array(11);
	this.removeEventListener=function(name,fref)
	{
		var evtName=name.toLowerCase();
		if(this.handlers==null)return;
		if(this.handlers[evtName]==null||!(this.handlers[evtName].length))return;
		for(i=0;i<this.handlers[evtName].length;i++)
		{
			var listener=this.handlers[evtName][i];
			if(listener!=null)if(listener.handler==fref)this.handlers[evtName][i]=null;
		}
	}
	this.addEventListener=function(name,fref,oParent)
	{
		var evtName=name.toLowerCase();
		var handlerArray=(this.handlers[evtName]);
		if(handlerArray==null)this.handlers[evtName]=handlerArray=new Array();
		handlerArray[handlerArray.length]=new ig_EventListener(fref,oParent);
	}
	this.fireMulticastEvent=function(evtName,evt)
	{
		if(this.handlers==null)return;
		evtName=evtName.toLowerCase();
		if(evt==null)evt=new ig_EventObject();
		try{if(this.handlers.length&&this.handlers[evtName]!=null&&this.handlers[evtName].length){
			for(i=0;i<this.handlers[evtName].length;i++)
			{
				var listener=this.handlers[evtName][i];
				if(listener!=null)
				{
					listener.handler.apply(listener.callBackObject,[this,evt,listener.callBackObject]);
					if(evt!=null&&evt.cancel)return;
				}
			}
		}}catch(ex){}
	}
	this.swapImage=function(imageNo){this.DropButton.Image.src=(imageNo==1?this.DropButton.ImageUrl1:this.DropButton.ImageUrl2);}
	this.doMouseover=function(){this.DropButton.Image.className=this.DropButton.HoverStyleClassName;}
	this.doMouseup=function(){if(this.Loaded && !this.isReadOnly())this.swapImage(1);}
	this.doMousedown=function(evt,src)
	{
		if(src.id!=this.Id+"_img" && this.isEditable())return;
		if(!this.Loaded || this.isReadOnly())return;
		if(igdrp_all._droped!=null && igdrp_all._droped!=this)igdrp_all._droped.setDropDownVisible(false);
		if(this.Dropped)
		{
			this.setDropDownVisible(false);
			igdrp_all._old=this;
			if(window.setTimeout!=null)window.setTimeout("igdrp_all._old.setFocusTop()",10);
		}
		else
		{
			this.swapImage(2);
			this.setDropDownVisible(true);
		}
		ig_cancelEvent(evt);

⌨️ 快捷键说明

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