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

📄 ig_mask.js

📁 研究怎样通过手写代码来完成自动生成代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
			else if(ch == 'm' || ch == 'M')
			{
				if(m++ > 0){o |= 2048; continue;}
				o |= 2 << (sep++ * 3);
			}
			else if(ch == 'y')
			{
				if(y++ > 0){if(y > 2) o |= 4096; continue;}
				o |= 3 << (sep++ * 3);
			}
			else if(sep == 1 && sep0 == null) sep0 = ch;
		}
		if(sep0 != null)
		{
			this.sepCh = sep0;
			this.sep = sep0.charCodeAt(0);
		}
		if(m == 0) o |= 1 << (sep++ * 3);
		if(d == 0) o |= 2 << (sep++ * 3);
		if(y == 0) o |= 3 << (sep++ * 3);
		this.order = o;
		this.mask = v;
	}
	this.setGood = function()
	{
		var d = this.date;
		if(d == null)
		{
			if(this.elem.value.length > 0) d = this.toDate();
			if(d == null && !this.allowNull) d = new Date();
			this.date = d;
		}
		this.good = d;
	}
	this.focusText = function()
	{
		var v, i = -1, t = "", d = this.date;
		if(d == null){if(this.allowNull) return t; this.date = d = new Date();}
		while(++i < 3)
		{
			if((v = (this.order >> i * 3) & 3) == 0) break;
			if(i > 0) t += this.sepCh;
			switch(v)
			{
				case 1: v = d.getDate();
					if(v < 10 && (this.order & 1024) != 0) t += 0;
					break;
				case 2: v = d.getMonth() + 1;
					if(v < 10 && (this.order & 2048) != 0) t += 0;
					break;
				case 3: v = d.getFullYear();
					if((this.order & 4096) == 0) v %= 100;
					if(v < 10) t += 0;
					break;
			}
			t += v;
		}
		return t;
	}
	this.setText = function(v){this.setDate(this.toDate(v));}
	this.toDate = function(t, inv)
	{
		if(t == null){if(this.getReadOnly()) return this.date; t = this.elem.value;}
		var ii = t.length;
		if(ii > 12) return this.date;
		if(ii == 0 && this.allowNull) return null;
		var y = -1, m = -1, d = -1, sep = 0, i = -1, f = 0;
		while(++i <= ii)
		{
			var ch = (i < ii) ? t.charCodeAt(i) : this.sep;
			if(ch == this.sep)
			{
				if(i + 1 == ii) break;
				switch((this.order >> sep * 3) & 3)
				{
					case 1: d = f; break;
					case 2: m = f; break;
					case 3: y = f; break;
				}
				sep++;
			}
			ch -= 48;
			if(ch >= 0 && ch <= 9) f = f * 10 + ch;
			else f = 0;
		}
		f = null;
		i = 0;
		this.extra.year = y; this.extra.month = m; this.extra.day = d; this.extra.reason = (ii > 0) ? 2 : 1;
		if(sep != 3) i++;
		else
		{
			if(d < 1 || d > 31 || m < 1 || m > 12 || y < 0 || y > 9998) i++;
			else
			{
				if(m == 2 && d > 29) i = d = 29;
				if(this.autoCentury){if(y < 37) y += 2000; else if(y < 100) y += 1900;}
				f = new Date(y, m - 1, d);
				if(y < 100 && f.setFullYear != null) f.setFullYear(y);
				if(f.getDate() != d)
				{
					f = new Date(i = y, m - 1, d - 1);
					if(y < 100 && f.setFullYear != null) f.setFullYear(y);
				}
				d = f.getTime();
				if((m = this.max) != null) if(d > m.getTime()){f = m; if(i++ == 0) this.extra.reason = 0;}
				if((m = this.min) != null) if(d < m.getTime()){f = m; if(i++ == 0) this.extra.reason = 0;}
			}
		}
		this.extra.date = f;
		if(inv && i > 0) if(this.fireEvt(11, null)) f = this.date;
		return f;
	}
	this.spin = function(v)
	{
		var d = this.toDate();
		if(d == null) d = new Date();
		this.setDate(new Date(d.getFullYear(), d.getMonth(), d.getDate() + v));
	}
	this.isValid = function(){return this.toDate() != null;}
	this.repaint = function(fire)
	{
		var t = null;
		if(!this.getReadOnly() && this.getEnabled())
		{
			if(this.foc) t = this.focusText();
			else if(this.changed)
			{
				var d = this.toDate(null, true);
				if(d != null || this.allowNull) this.date = d;
			}
		}
		this.text = (t == null) ? this.staticText() : t;
		this.repaint0(fire);
	}
	this.staticText = function()
	{
		if(this.date == null)
		{
			if(this.useLastGoodValue && this.good != null && this.text.length > 0) this.date = this.good;
			else{if(this.allowNull) return this.nullText; this.date = new Date();}
		}
		var t = this.info;
		if(t != null) t = this.longFormat ? t.LongDatePattern : t.ShortDatePattern;
		else if(this.longFormat && this.date.toLocaleDateString != null) return this.date.toLocaleDateString();
		if(t == null || t.length < 2) t = this.mask;
		var f = "yyyy", v = this.date.getFullYear();
		if(t.indexOf(f) < 0)
		{
			if(t.indexOf(f = "yy") < 0) v = -1;
			else if((v %= 100) < 10) v = "0" + v;
		}
		if(v != -1) t = t.replace(f, v);
		f = "MMM";
		v = this.date.getMonth() + 1;
		var mm = null, dd = null;
		if(t.indexOf(f) < 0)
		{
			if(t.indexOf(f = "MM") < 0){if(t.indexOf(f = "M") < 0) v = -1;}
			else if(v < 10) v = "0" + v;
			if(v != -1) t = t.replace(f, v);
		}
		else
		{
			if(t.indexOf("MMMM") >= 0) f = "MMMM";
			if(this.info != null) mm = (f.length == 4) ? this.info.MonthNames : this.info.AbbreviatedMonthNames;
			if(mm != null) mm = (mm.length >= v) ? mm[v - 1] : null;
			t = t.replace(f, (mm == null) ? ("" + v) : "[]");
		}
		f = "ddd";
		v = "";
		if(t.indexOf(f) >= 0)
		{
			if(t.indexOf("dddd") >= 0) f = "dddd";
			if(this.info != null) dd = (f.length == 4) ? this.info.DayNames : this.info.AbbreviatedDayNames;
			v += this.date.getDay();
			if(dd != null) dd = (dd.length >= v) ? dd[v] : null;
			t = t.replace(f, (dd == null) ? v : "()");
		}
		f = "dd";
		v = this.date.getDate();
		if(t.indexOf(f) < 0){if(t.indexOf(f = "d") < 0) v = -1;}
		else if(v < 10) v = "0" + v;
		if(v != -1) t = t.replace(f, v);
		if(mm != null) t = t.replace("[]", mm);
		if(dd != null) t = t.replace("()", dd);
		return t;
	}
	this.getDate = function(){return this.foc ? this.toDate() : this.date;}
	this.setDate = function(v)
	{
		if(v != null && v.length != null) v = (v.length < 3) ? null : this.toDate(v);
		if(v == null && !this.allowNull) if((v = this.date) == null) v = new Date();
		if(v != null)
		{
			var m, d = v.getTime();
			if((m = this.max) != null) if(d > m.getTime()) v = m;
			if((m = this.min) != null) if(d < m.getTime()) v = m;
		}
		else this.good = null;
		var fire = this.date != v;
		if(this.k0 == null && !fire) return;
		this.date = v;
		this.text = this.foc ? this.focusText() : this.staticText();
		this.repaint0(fire);
	}
	// return char that can be added or -1
	this.canAdd=function(k,t)
	{
		var ii=t.length-1;
		if(ii < 0)return (k == this.sep) ? -1 : k;
		if(t.charCodeAt(ii) == this.sep)
			return (k == this.sep) ? -1 : k;
		var f=0,sep=0,i=-1,n=0;
		while(++i <= ii)
		{
			var ch = t.charCodeAt(i);
			if(ch == this.sep){if(sep++ > 1) return -1; n = f = 0; continue;}
			n++;
			f=f*10+ch-48;
		}
		if(sep > 1 && k == this.sep) return -1;
		i = (this.order >> sep * 3) & 3;
		if(i == 1){if(n > 1 || f * 10 + k - 48 > 31) n = 4;}
		if(i == 2){if(n > 1 || f * 10 + k - 48 > 12) n = 4;}
		return (n < 4) ? k : ((sep > 1) ? -1 : this.sep);
	}
	this.afterKey = function(k,fix)
	{
		var t = this.elem.value;
		if(fix)
		{
			var sep = 0, i = -1, f = 0, i0 = 0, ii = t.length, tt = "";
			while(++i <= ii)
			{
				var ch = (i < ii) ? t.charCodeAt(i) : this.sep;
				if(ch == this.sep)
				{
					switch((this.order >> sep * 3) & 3)
					{
						case 1: if(f > 31){while(f > 31) f = Math.floor(f / 10);} else f = -1; break;
						case 2: if(f > 12){while(f > 12) f = Math.floor(f / 10);} else f = -1; break;
						case 3: if(f < 9999) f = -1; else while(f > 9999) f = Math.floor(f / 10); break;
					}
					if(f < 0) tt += t.substring(i0, i);
					else tt += f;
					if(i < ii) tt += this.sepCh;
					sep++;
					i0 = i + 1;
				}
				ch -= 48;
				if(ch >= 0 && ch <= 9) f = f * 10 + ch;
				else f = 0;
			}
			t = tt;
		}
		if(this.k0 > 0) if(this.canAdd(48, t) == this.sep) t += this.sepCh;
		this.elem.value = t;
	}
	this.filterKey = function(k,fix)
	{
		if(k != this.sep && (k < 48 || k > 57))
			// check for -_\/space.,:;"%
			if(this.tr != null && this.isSep(k))k=this.sep;
			else return 0;
		if(k == this.sep && this.sel0 == 0)return 0;
		if(fix && this.canAdd(k,this.elem.value) != k)k=0;
		return k;
	}
	this.isSep=function(k){return k == this.sep || k == 45 || k == 92 || k == 95 || k == 47 || k == 32 || k == 46 || k == 44 || k == 58 || k == 59;}
	this.paste=function(old)
	{
		var ch,sep=true,v="",f=0;
		for(var i=0; i < old.length; i++)
		{
			ch = old.charCodeAt(i);
			if(ch >= 48 && ch <= 57)sep=false;
			else{if(!this.isSep(ch))continue; if(f > 1)break; if(sep)continue; sep=true; f++;}
			v += sep ? this.sepCh : old.charAt(i);
		}
		this.text="";
		this.setText(v);
	}
	this.setLongFormat(lf);
	this.setDateInfo(di);
	this.setDate(v);
	this.text=this.elem.value;
	this.k0=-2;
	igmask_all[id]=this;
}
function igmask_event(e)
{
	if(e == null) if((e=window.event) == null)return;
	var c=null,id=null,i=0,o=e.srcElement;
	if(o == null) if((o=e.target) == null)o=this;
	while(true)
	{
		if(o == null || i++ > 2)return;
		try{if(o.getAttribute != null)id=o.getAttribute("maskID");}catch(ex){}
		if(!ig_csom.isEmpty(id)){c=igmask_getById(id); break;}
		if((c=o.parentNode) != null)o=c;
		else o=o.parentElement;
	}
	if(c != null)c.doEvt(e);
}

⌨️ 快捷键说明

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