📄 ig_edit.js
字号:
{
var fields=new Array();
if(t==null)t="";
var x,k,i=-1,v=-1,field=-1,n=22;
while(++i<this.mask.length)
{
if((x=this.mask.charCodeAt(i))>21 && n>21)continue;
if(x>21){if(field>=0)fields[field]=v;}
else
{
if(n>21){v=-1; field++;}
if(i>=t.length)continue;
if(x>18)
{
k=t.charCodeAt(i)-48;
if(k>=0 && k<=9)
{
if(v<0)v=k;
else v=v*10+k;
}
}
else if(n!=x)if(this.getAMPM(false).charAt(0).toUpperCase()==t.charAt(i).toUpperCase())
v=1;
}
n=x;
}
fields[field]=v;
return fields;
}
me.curField=function(s,mask)
{
var x,n=22,field=this.n0=this.n1=-1;
for(var i=0;i<mask.length;i++)
{
if(((x=mask.charCodeAt(i))>21)==(n>21))continue;
if(x>21){if(i>=s)break;}
else{this.n0=i; field++;}
n=x;
}
if(this.n0>=0)this.n1=i;
if((field=this.field0IDs[field])==null)return -1;
if(field<8)return (field<4)?0:1;
if(field<20)return Math.floor((field-4)/2);
return (field>21)?8:-1;
}
me.key=function(k,c,t,i,s,mask)
{
var n=0,v=-1,field=this.curField(s,mask);
if(s>=this.n1)if(t.charCodeAt(--s)>21)return this.key(k,c,t,i,s+2,mask);
if(field<0)return -1;
if(field==5)//ampm
{
if(s<=this.n0)
{
v=this.getAMPM(false);
if(v.charAt(0).toUpperCase()!=c.toUpperCase())v=this.getAMPM(true);
if(this.n1==this.n0+1)v=v.charAt(0);
else if((i=v.length)<2)v+=" "; else if(i>2)v=v.substring(0,2);
this.txt=t.substring(0,this.n0)+v+t.substring(this.n1);
}
return this.n1;
}
if(k<48 || k>57)
{
if(s==0 || (k!=47 && k!=58 && (k<44 || k>57)))return -1;
if(mask.charCodeAt(s-1)>=21 || this.n1==i)return s;
while(s<i)
{
if(mask.charCodeAt(s++)>=21)break;
t=t.substring(0,s-1)+mask.charAt(s-1)+t.substring(s);
}
this.txt=t;
return s;
}
k-=48;
if(this.n0==s)
{
v=t.charCodeAt(s+1)-48;
//0-y,1-M,2-d,3-h,4-H,5-AMPM,6-m,7-s,8-ms
switch(field)
{
case 4: k--; v-=2;
case 3: case 1: if(k>1)n=1; else if(k==1 && v>2)n=2;break;
case 2: if(k>3)n=1; else if(k==3 && v>1)n=2;break;
case 6: case 7: if(k>6)n=1; else if(k==6 && v>0)n=2;break;
default: break;
}
}
if(this.n0+1==s)
{
v=t.charCodeAt(s-1)-48;
//0-y,1-M,2-d,3-h,4-H,5-AMPM,6-m,7-s,8-ms
switch(field)
{
case 4: v--; k-=2;
case 3: case 1: if(v>1 || (v==1 && k>2))n=3;break;
case 2: if(v>3 || (v==3 && k>1))n=3;break;
case 6: case 7: if(v>6 || (v==6 && k>0))n=3;break;
default: break;
}
}
if(n==1){t=t.substring(0,s)+mask.charAt(s)+t.substring(s+1); s++;}
if(n==2)t=t.substring(0,s+1)+mask.charAt(s+1)+t.substring(s+2);
if(n==3)
{
while(++s<i)if(mask.charCodeAt(s)<21)break;
if(s>=i)return -1;
return this.key(k+48,c,t,i,s,mask);
}
this.txt=t.substring(0,s)+c+t.substring(s+1);
return ++s;
}
me.spin=function(v)
{
var x,i=this.spinF,d=new Date();
d.setTime(this.date.getTime());
if(i<0 || i>8)
{
if(this.fcs==2)
{
this.getSelectedText();
i=this.curField(this.sel0,this.mask);
if((d=this.toDate(this.elem.value,true,true,true))==null)
d=new Date();
this.spinF=i;
}
else this.spinF=i=this.d_s;
}
//0-y,1-M,2-d,3-h,4-H,5-AMPM,6-m,7-s,8-ms
if(i==5)v=(v>0)?12:-12;
x=this.spinOnlyOneField;
switch(i)
{
case 0: d.setFullYear(v+=d.getFullYear()); if(x && v!=d.getFullYear())i=-1;break;
case 1: d.setMonth(v+=d.getMonth()); if(x && v!=d.getMonth())i=-1;break;
case 2: d.setDate(v+=d.getDate()); if(x && v!=d.getDate())i=-1;break;
case 3: case 4: case 5: i=d.getDate(); d.setHours(v+=d.getHours()); if(x && i!=d.getDate())i=-1;break;
case 6: d.setMinutes(v+=d.getMinutes()); if(x && v!=d.getMinutes())i=-1;break;
case 7: d.setSeconds(v+=d.getSeconds()); if(x && v!=d.getSeconds())i=-1;break;
case 8: for(i=this.n1-this.n0; i++<3;)v*=10;
d.setMilliseconds(v+=d.getMilliseconds()); if(x && v!=d.getMilliseconds())i=-1;break;
}
if(i<0)return;
if((v=this.limits(d))!=null)d=v;
this.text=this.toTxt(d,this.fcs==2,this.promptChar,true);
this.date=d;
this.isNull=false;
this.updatePost(d,"");
this.repaint();
this.select(this.sel0);
}
me.getDate=function(){return this.instant(true);}
me.setDate=function(v){this.setValue(v);}
me.getValueByMode=function(vt,limit)
{
var d=(this.fcs<2)?(this.isNull?null:this.date):this.toDate(this.elem.value,true,limit);
if(vt==0)return d;
return this.toTxt(d,vt==1,this.emptyChar);
}
me.instant=function(date,limit)
{
return this.getValueByMode(date?0:this.mode,limit==true);
}
me.date_7=function(v)
{
if(v.length<10)return null;
var y,o=v.split("-");
if(o.length<7)return null;
v=new Date(y=this.intI(o,0),this.intI(o,1),this.intI(o,2),this.intI(o,3),this.intI(o,4),this.intI(o,5),this.intI(o,6));
if(y<100)v.setFullYear(y);
return v;
}
me.getValue=function(date){return this.instant(date,true);}
me.setValue=function(v,o)
{
if(v!=null && v.getTime==null)
{
if(this.fcs<0)
{
if(v.length<8)v="";
o=v.split(",");
if(o.length>2)this.max=this.date_7(o[2]);
if(o.length>1)this.min=this.date_7(o[1]);
v=this.date_7(o[0]);
}
else v=this.toDate(v.toString(),this.mode<2 && o!=true);
}
o=v;
if((v=this.limits(v))==null)v=o;
this.txt=this.mask;
if(this.isNull=(v==null))
v=new Date();
else this.toTxt(v,true,"",true);
this.date=v;
if(this.good!=false)this.good=v;
this.text=this.focusTxt(this.fcs>1);
this.updatePost(this.isNull?null:v,"");
this.repaint();
if(this.fix==1)this.old=this.instant(true);
}
me.getRenderedValue=function(v)
{
if(v!=null && v.getTime==null)v=this.toDate(v.toString(),false);
return this.toTxt(v,false,"");
}
return me;
}
//
function igedit_mask(elem,id,prop0,prop1)
{
var me=new igedit_new(elem,id,prop0);
var prop=me.valI(prop1,2);
me.promptChar=prop.charAt(0);
me.padChar=prop.charAt(1);
me.emptyChar=prop.charAt(2);
me.mode=parseInt(prop.charAt(3));
me.minF=(prop.length>4)?parseInt(prop.charAt(4)):3;
me.good=prop.length>5;
//
me.flag=function(c,u)
{
switch(c)
{
case '>': return -1;
case '<': return -2;
case '&': c=1;break;
case 'C': c=2;break;
case 'A': c=7;break;
case 'a': c=8;break;
case 'L': c=13;break;
case '?': c=14;break;
case '#': case '0': return 19;
case '9': return 20;
default: return 0;
}
return c+u*2;
}
me.filter=function(flag,s,i,sf)
{
if(i>=s.length)return sf;
var c=s.charCodeAt(i);
s=s.charAt(i);
if(c<21)return sf;
switch(Math.floor((flag-1)/6))
{
case 0: break;
case 1: if(c>47 && c<58)return s;
case 2: if(c>255 || s.toUpperCase()!=s.toLowerCase())break;
return sf;
case 3: return (c>47 && c<58)?s:sf;
}
if((flag=Math.floor((flag-1)/2)%3)==0)return s;
return (flag==2)?s.toLowerCase():s.toUpperCase();
}
me.getTxt=function(vt,prompt,t)
{
var flag,mask=this.mask,o="",non=(t!=null);
if(!non)t=this.txt;
if(non || this.fcs<0)non=this.minF==1;
if(t==null || mask==null)return o;
for(var i=0;i<mask.length;i++)
if((flag=mask.charCodeAt(i))<21)
{
if(i<t.length && t.charCodeAt(i)>=21){o+=t.charAt(i); non=false;}
else if(vt%3==2 || (vt%3==1 && (flag & 1)==1))o+=prompt;
}
else if(vt>=3)o+=mask.charAt(i);
return non?"":o;
}
me.setTxt=function(v,vt,render)
{
var c,flag,j=0,i=-1,mask=this.mask,t=this.mask;
if(v!=null)while(++i<mask.length)
{
if(vt==1000+j)vt=this.mode;
if(j>=v.length)break;
if((flag=mask.charCodeAt(i))<21)
{
if((c=this.filter(mask.charCodeAt(i),v,j))!=null)t=t.substring(0,i)+c+t.substring(i+1);
j++;
}
else if(vt>=3)j++;
}
if(render)return t;
this.txt=t;
this.text=this.focusTxt(this.fcs>1," ");
this.repaint();
}
me.getInputMask=function(){return this.m0;}
me.setInputMask=function(mask)
{
if(mask==null)mask="";
this.m0=mask;
var x,c,i,i0=0,u=0,n="",t="";
var t0=this.getTxt(0);
for(i=0;i<mask.length;i++)
{
if((x=this.flag(c=mask.charAt(i),u))!=0)
{
if(x<0){u=(u==-x)?0:-x; continue;}
n+=(c=String.fromCharCode(x));
c=this.filter(x,t0,i0++,c);
}
else if(c=="\\" && i+1<mask.length && this.flag(mask.charAt(i+1),0)!=0)
n+=(c=mask.charAt(++i));
else n+=c;
t+=c;
}
this.txt=t;
this.mask=n;
}
me.dMask=function(v,d)
{
if(this.field0IDs==null)this.field0IDs=new Array();
if(this.field1IDs==null)this.field1IDs=new Array();
if(v==null)v="";
var x,i,i0=0,flag=-1,t="";
for(i=0;i<v.length;i++)
{
x=v.charCodeAt(i);
if(x<48 || x>57)
{
if(d==true && (flag=v.charAt(i))=="\\" && i+1<v.length)
{
if((x=v.charAt(++i))=="\\")continue;
if(x=="0" || x=="9")t+=flag;
t+=x;
}
else t+=v.charAt(i);
continue;
}
flag=(x-48)*10+v.charCodeAt(++i)-48;
if(d==true){this.field1IDs[i0++]=flag; t+="\01"; continue;}
this.field0IDs[i0++]=flag;
if(flag==14)t+="L"; else if(flag==15)t+="LL";
else if(flag==22)t+="#";
else
{
t+="##";
if(flag==3)t+="##";
while(flag-->23)t+="#";
}
}
return t;
}
prop=me.valI(prop1,1);
if(prop1.length>3)prop=me.dMask(prop);
me.setInputMask(prop);
me.focusTxt=function(foc,e)
{
var t=null;
if(e!=null && !foc)
{
e=e!="";
if(e && this.bad)this.txt=this.setTxt(this.elem.value,5,true);
t=this.txt;
var inv=t.length;
if(!e && this.hadFocus)
{
var iL=inv-this.elem.value.length,s0=this.sel0,s1=this.sel1;
if(iL>0 && s1-s0==iL)
this.txt=t=t.substring(0,s0)+this.mask.substring(s0,s1)+t.substring(s1);
}
while(inv-->0)
{
var c=t.charCodeAt(inv);
if(c<21 && (c & 1)==1)break;
}
if(e && inv>=0)if(this.fireEvent(13))inv=-1;
this.elemViewState.value=(t=this.txt)+((inv<0)?"":String.fromCharCode(30));
this.valid(this.getTxt(this.mode,""));
}
return this.getTxt(foc?5:4,foc?this.promptChar:this.padChar,t);
}
me.enter0=function(){return this.getTxt(this.mode,"");}
me.setText=function(v,s){this.setTxt(v,(s==null)?5:(1000+s)); if(this.fix==1)this.old=this.instant(true);}
me.key=function(k,c,t,i,s,mask){return -2;}
me.doKey=function(k,c,t,i,sel0,sel1,bad)
{
if(i<1 || k<7 || (k>8 && k<32))k=0;
if(bad)
{
if(k==0 || (this.getAMPM!=null && !(this.mask.indexOf(c)>0 || this.getAMPM(false).indexOf(c)>=0 || this.getAMPM(true).indexOf(c)>=0 || (k>=48 && k<=57))))
ig_cancelEvent(e);
return;
}
if(k==0)return;
t=this.txt;
var mask=this.mask;
if(sel0!=sel1){while(--sel1>=sel0)t=t.substring(0,sel1)+mask.charAt(sel1)+t.substring(sel1+1); sel1++;}
else if(k==7)//del
{
while(sel1<i && mask.charCodeAt(sel1)>=21)sel1++;
if(sel1>=i)return;
t=t.substring(0,sel1)+mask.charAt(sel1)+t.substring(sel1+1);
sel1++;
}
else if(k==8)//back
{
while(sel1>0 && mask.charCodeAt(sel1-1)>=21)sel1--;
if(sel1--<1)return;
t=t.substring(0,sel1)+mask.charAt(sel1)+t.substring(sel1+1);
}
if(k>8 && sel1<i)
{
if(sel1>=i)return;
if((sel0=this.key(k,c,t,i,sel1,mask))>=0){t=this.txt; sel1=sel0;}
else{if(sel0==-1)return; while(mask.charCodeAt(sel1)>=21)if(++sel1>=i)return;}
if(sel0>=0){t=this.txt; sel1=sel0;}
else
{
if((c=this.filter(mask.charCodeAt(sel1),c,0))==null)return;
t=t.substring(0,sel1)+c+t.substring(sel1+1);
sel1++;
}
}
this.txt=t;
this.elem.value=this.focusTxt(true);
this.select(sel1);
}
me.getValueByMode=function(vt){return this.getTxt(vt,this.emptyChar);}
me.instant=function(){return this.getValueByMode(this.mode);}
me.getValue=function(){return this.instant();}
me.setValue=function(v){this.setTxt(v,(this.fcs<0)?2:this.mode); if(this.fix==1)this.old=this.instant(true);}
me.getRenderedValue=function(v)
{
v=(v==null)?"":v.toString();
return this.getTxt(4,this.padChar,(this.mode==5)?v:this.setTxt(v,this.mode,true));
}
return me;
}
function igedit_new(elem,id,prop0)
{
this.fcs=-1;
this.valI=function(o,i){o=(o==null || o.length<=i)?null:o[i]; return (o==null)?"":o;}
this.intI=function(o,i){return ig_csom.isEmpty(o=this.valI(o,i))?-1:parseInt(o);}
this.initButElem=function(e,c)
{
if(e==null)return;
if(e.nodeName.toUpperCase()=="IMG" || e.nodeName.toUpperCase()=="TD")
if(c==null)
{
ig_csom.addEventListener(e,"mousedown",igedit_event);
ig_csom.addEventListener(e,"mouseup",igedit_event);
ig_csom.addEventListener(e,"mousemove",igedit_event);
ig_csom.addEventListener(e,"mouseout",igedit_event);
e.unselectable="on";
}
else if(!ig_csom.isEmpty(e.bgColor)){e.bgColor=c; e.style.color=c;}
if(e.childNodes!=null)for(var i=0;i<e.childNodes.length;i++)this.initButElem(e.childNodes[i],c);
}
this.focusTxt=function(foc,e)
{
if(e!=null && !foc)
this.valid(this.elemViewState.value=this.elem.value);
return this.elem.value;
}
if(igedit_all.unload!=true){ig_csom.addEventListener(window,"unload",igedit_event); igedit_all.unload=true;}
// init flag
this.elemID=-10;
this.bad=false;
this.Element=elem;
elem.Object=this;
this.eventID=function(s)
{
switch(s.toLowerCase())
{
case "keydown": return 0;
case "keypress": 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 "initialize": return 10;
case "valuechange": return 11;
case "textchanged": return 12;
case "invalidvalue": return 13;
case "custombutton": return 14;
case "spin": return 15;
}
return -1;
}
this.events=new Array(16);
this.evtH=function(n,fRef,add,o)
{
if(n<0 || n>15)return;
var e=this.events[n];
if(e==null){if(add)e=this.events[n]=new Array(); else return;}
for(n=0;n<e.length;n++)if(e[n]!=null && e[n].fRef==fRef)
{if(!add){delete e[n]; e[n]=null;} return;}
if(add)for(n=0;n<=e.length;n++)if(e[n]==null)
{e[n]=new Object(); e[n].fRef=fRef; e[n].o=o;break;}
}
this.removeEventListener=function(name,fref){this.evtH(this.eventID(name),fref,false);}
this.addEventListener=function(name,fref,o){this.evtH(this.eventID(name),fref,true,o);}
this.getRenderedValue=function(v){return (v==null)?"":v.toString();}
var o,ii,j,i=0,e=ig_csom.getElementById(id+"_p");
if(e==null)e=new Object();
e.value=String.fromCharCode(30);
this.elemViewState=e;
if((e=ig_csom.getElementById(id))==null)if((e=ig_csom.getElementById(id.substring(1)))==null)e=new Object();
this.elemValue=e;
//i=propCounter
this.uniqueId=prop0[i++];
//events
e=prop0[i++];
if(e.length>2)
{
e=e.split(" ");
for(j=0;j<e.length-1;j+=2)
try{this.evtH(this.intI(e,j),eval(this.valI(e,j+1)),true);}catch(ex){}
}
this.nullable=!ig_csom.isEmpty(prop0[i++]);
this.postValue=!ig_csom.isEmpty(prop0[i++]);
this.postButton=!ig_csom.isEmpty(prop0[i++]);
this.postEnter=!ig_csom.isEmpty(prop0[i++]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -