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

📄 ig_mask.js

📁 研究怎样通过手写代码来完成自动生成代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* 
Infragistics DateChooser editor Script 
Version 5.1.20051.37
js-version 1.1.20041.1033
Copyright (c) 2003-2005 Infragistics, Inc. All Rights Reserved.
*/
if(typeof(igmask_all) != "object")
	var igmask_all = new Object();
// public: Obtains the editor object using its id
function igmask_getById(id){return igmask_all[id];}
// Params:
//   e - reference to <INPUT>
//   di - container of format values: ig_DateFormatInfo
//   v - initial date value.
//   lf - True: long date-format, false: short date format
function igmask_date(e,di,v,lf)
{
	if(e == null)return;
	this.changed=false;
	this.extra=new Object();
	//
	this.repaint0=function(fire)
	{
		if(this.changed && this.elem.value == this.text) return;
		this.elem.value = this.text;
		if(!fire) return;
		this.changed = true;
		this.fireEvt(10, null);
	}
	var id=e.id;
	if(ig_csom.isEmpty(id)){id = "_mask_"; for(var q in igmask_all) id += "0";}
	while(igmask_getById(id) != null) id += "x";
	//
	ig_csom.addEventListener(e,"keydown",igmask_event,false);
	ig_csom.addEventListener(e,"keypress",igmask_event,false);
	ig_csom.addEventListener(e,"keyup",igmask_event,false);
	ig_csom.addEventListener(e,"focus",igmask_event,false);
	ig_csom.addEventListener(e,"blur",igmask_event,false);
	ig_csom.addEventListener(e,"mousedown",igmask_event,false);
	ig_csom.addEventListener(e,"mouseup",igmask_event,false);
	ig_csom.addEventListener(e,"mousemove",igmask_event,false);
	ig_csom.addEventListener(e,"mouseover",igmask_event,false);
	ig_csom.addEventListener(e,"mouseout",igmask_event,false);
	this.id=id;
	e.setAttribute("maskID",id);
	this.elem=e;
	if(e.createTextRange != null) this.tr = e.createTextRange();
	this.getElement = function(){return this.elem;}
	//
	this.setBounds=function(x,y,w,h,z)
	{
		var s=this.elem.style;
		if(x != null)
		{
			s.position="absolute";
			s.left=x;
			s.top=y;
		}
		if(w != null)s.width=w;
		if(h != null)s.height=h;
		if(z != null)s.zIndex=z;
	}
	//
	this.k1=0;
	this.fixKey=0;
	this.allowNull=true;
	this.useLastGoodValue=true;
	this.getAllowNull = function(){return this.allowNull;}
	this.setAllowNull = function(v){this.allowNull = v; repaint(true);}
	this.getEnabled = function(){return this.elem.disabled != true;}
	this.setEnabled = function(v){this.elem.disabled = (v == false);}
	this.getVisible = function(){return this.elem.style.display != "none";}
	this.setVisible = function(v){this.elem.style.display = v ? "" : "none";}
	this.getReadOnly = function(){return this.elem.readOnly;}
	this.setReadOnly = function(v){this.elem.readOnly = v;}
	this.getText = function(){return this.text;}
	this.getMaxValue = function(){return this.max;}
	this.setMaxValue = function(v){this.max = v;}
	this.getMinValue = function(){return this.min;}
	this.setMinValue = function(v){this.min = v;}
	this.nullText = "null";
	this.getNullText = function(){return this.nullText;}
	this.setNullText = function(v){this.nullText = v;}
	this.delta = 1;
	//
	this.doKey = function(e, a)
	{
		if(a == 1 && (e.ctrlKey || e.altKey)) return;
		var k = e.keyCode;
		if(k == 0 || k == null) if((k = e.which) == null) return;
//		if(k == 13 && a == 1) this.fireEvt(9);
		if(k < 32 && k != 8) return;
		if(a == 1) this.k1 = k;
		var t0 = this.text, t1 = this.elem.value;
		var i = t1.length;
		if(a == 2)
		{
			this.k1 = 0;
			if(this.k0 < 32) return;
			if(t0 != t1)
			{
				this.changed = true;
				if(this.fixKey > 0 || i == 1) this.afterKey(k, this.fixKey++ == 1);
				else if(this.fixKey == 0) if(i-- == 0){this.fixKey = 2; return;}
			}
			this.k0 = -2;
			return;
		}
		switch(k)
		{
			//end//right//home//left
			case 35: case 39: case 36: case 37: if(this.k1 == k) return;
				break;
			//back//del
			case 8: case 46: if(this.k1 == k) return;
				break;
			//up//down
			case 38: case 40:
				if(a == 1 && this.delta != 0 && !e.shiftKey) this.spin((k == 38) ? this.delta : -this.delta);
				if(this.k1 == k) return;
				break;
		}
		if(a == 1)
		{
			t0 = this.getSelectedText();
			if(t0.length > 0 || this.sel0 < i) this.fixKey = 0;
			else if(this.fixKey == 0 && this.sel0 == i) this.fixKey = 1;
			return;
		}
		// fast typing!
		if(this.k0 > 0)
		{
			if(t0 != t1) this.changed = true;
			if(this.fixKey > 0)
				this.afterKey(this.k0, this.fixKey > 0);
		}
		var newK = this.filterKey(k, this.fixKey > 0);
		if(newK != k && this.tr == null) newK = 0;
		if(newK == 0) ig_cancelEvent(e);
		else if(newK != k && this.tr != null) e.keyCode = newK;
		this.k0 = newK;
	}
	this.stoi = function(s)
	{
		switch(s.toLowerCase())
		{
			case "keypress": return 0;
			case "keydown": return 1;
			case "keyup": return 2;
			case "mousedown": return 3;
			case "mouseup": return 4;
			case "mousemove": return 5;
			case "mouseover": return 6;
			case "mouseout": return 7;
			case "focus": return 8;
			case "blur": return 9;
			case "invalidvalue": return 11;
		}
		return 10;//valuechanged
	}
	this.doEvt = function(e)
	{
		if(e == null || !this.getEnabled()) return;
		var v = !this.getReadOnly(), a = this.stoi(e.type);
		if(a < 8) this.fireEvt(a, e);
		if(a < 3 && v) this.doKey(e, a);
		if(a >= 8)
		{
			if((a == 8) == this.foc) return;
			this.foc = (a == 8);
			if(a == 9 && v)
			{
				if(!this.changed) this.changed = this.text != this.elem.value;
				if(this.changed)
				{
					this.text = this.elem.value;
					if(this.elem.onchange != null) this.elem.onchange();
				}
			}
			if(a == 8 && v)
			{
				if(this.useLastGoodValue) this.setGood();
				if((v = this.elem.value) != this.text){this.paste(v); return;}
			}
			this.repaint(a == 9 && this.changed);
			this.fireEvt(a, e);
			if(this.foc){this.changed = false; this.select();}
			return;
		}
		if((v=this.elem.value) != this.text && (this.k1 == 0 || a < 4))
		{
			this.changed=true;
			if(a > 3 && this.k1 == 0)this.paste(v);
			else this.text=v;
			this.fireEvt(10,e);
		}
	}
	this.events=new Array(11);
	this.evtH=function(n,f,add)
	{
		n=this.stoi(n);
		var e=this.events[n];
		if(e == null){if(add)e=this.events[n]=new Array(); else return;}
		n=e.length;
		while(n-- > 0)if(e[n] == f){if(!add) e[n]=null; return;}
		if(add)e[e.length]=f;
	}
	this.removeEventHandler=function(name,fref){this.evtH(name,fref,false);}
	this.addEventHandler=function(name,fref){this.evtH(name,fref,true);}
	this.fireEvt=function(id,e)
	{
		var evts=this.events[id];
		var i=(evts == null) ? 0 : evts.length;
		if(i == 0)return false;
		var evt=this.Event;
		if(evt == null)evt=this.Event=new ig_EventObject();
		var cancel=false;
		while(i-- > 0)
		{
			if(evts[i] == null)continue;
			evt.reset();
			evt.event=e;
			evts[i](this,this.elem.value,evt,this.extra);
			if(evt.cancel)cancel=true;
		}
		return cancel;
	}
	this.select = function(s0, s1)
	{
		var i = this.elem.value.length;
		if(s1 == null) if((s1 = s0) == null){s0 = 0; s1 = i;}
		if(s1 >= i) s1 = i;
		else if(s1 < s0) s1 = s0;
		if(s0 > s1) s0 = s1;
		if(this.elem.selectionStart != null)
		{
			this.elem.selectionStart = this.sel0 = s0;
			this.elem.selectionEnd = this.sel1 = s1;
		}
		if(this.tr == null) return;
		this.sel0 = s0; this.sel1 = s1;
		s1 -= s0;
		this.tr.move("textedit", -1);
		this.tr.move("character", s0);
		if(s1 > 0) this.tr.moveEnd("character", s1);
		this.tr.select();
	}
	this.getSelectedText = function()
	{
		var r = "";
		this.sel0 = this.sel1 = -1;
		if(this.elem.selectionStart != null)
		{
			if((this.sel0 = this.elem.selectionStart) < (this.sel1 = this.elem.selectionEnd))
				r = this.elem.value.substring(this.sel0, this.sel1);
			return r;
		}
		if(this.tr == null) return r;
		var sel = document.selection.createRange();
		r = sel.duplicate();
		r.move("textedit", -1);
		this.sel0 = 0;
		try{while(r.compareEndPoints("StartToStart", sel) < 0)
		{
			if(this.sel0++ > 1000) break;
			r.moveStart("character", 1);
		}}catch(ex){}
		r = sel.text;
		this.sel1 = this.sel0 + r.length;
		return r;
	}
	//date==>>
	// 1 - d, 2 - m, 3 - y
	// 00007 - 1st
	// 00070 - 2nd
	// 00700 - 3rd
	// 01000 - dd
	// 02000 - mm
	// 04000 - yyyy
	this.order = 7370;//2 | (1 << 3) | (3 << 6) | (1 << 10) | (1 << 11) | (1 << 12)
	this.sepCh = "/";
	this.sep = 47;
	this.autoCentury = true;
	this.setLongFormat = function(v){this.longFormat = v;}
	this.getLongFormat = function(){return this.longFormat;}
	this.getDateInfo = function(){return this.info;}
	this.setDateInfo = function(v)
	{
		this.info = v;
		var sep0 = null;
		if(v != null)
		{
			v = this.info.ShortDatePattern;
			if(ig_csom.isEmpty(sep0 = this.info.DateSeparator)) sep0 = null;
		}
		if(v == null || v.length < 3) v = "MM/dd/yyyy";
		var ii = v.length;
		var y = 0, m = 0, d = 0, sep = 0, i = -1, o = 0;
		while(++i < ii)
		{
			var ch = v.charAt(i);
			if(ch == 'd')
			{
				if(d++ > 0){o |= 1024; continue;}
				o |= 1 << (sep++ * 3);
			}

⌨️ 快捷键说明

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