📄 input.js
字号:
{caption : "DD/MM/YYYY",id:"^\(\([0-2][0-9]\)|\([3][0-1]\)\)\/\(\([0][0-9]\)|\([1][0-2]\)\)\/\([0-9]{4}\)$"}
]
},
mask:{
action:function(value){
var ns=this,
b=ns.box;
if(value){
ns.$MaskFormat=function(ns, v){
var m=ns._maskMap,a=[],r=/[A-Za-z0-9]/;
_.arr.each(v.split(''),function(o,i){
a.push(m[o]||(r.test(o)?"":"\\")+o)
});
return '^'+a.join('')+'$';
}(b, value);
ns.$Mask = function(ns, v){
var m=ns._maskMap,a=[],s=ns._maskSpace;
_.arr.each(v.split(''),function(o,i){
a.push(m[o]?s:o);
});
return a.join('');
}(b,value);
//add event for cut/paste text
if(ns.domNode){
var ie=linb.browser.ie,
src=ns.getSubNode('INPUT').get(0),
f=function(o){
b._maskF(ns, src, ie&&o.propertyName);
};
if(ie){
src.attachEvent("onpropertychange",f);
src.attachEvent("ondrop",f);
ns.$ondestory=function(){
src.detachEvent("onpropertychange",f);
src.detachEvent("ondrop",f);
}
}else{
src.addEventListener("input",f,false);
//firefox drop
if(linb.browser.gek)
src.addEventListener("dragdrop",f,false);
ns.$ondestory=function(){
src.removeEventListener("input",f,false);
src.addEventListener("dragdrop",f,false);
}
}
}
}else{
delete ns.$MaskFormat;
delete ns.$Mask;
if(ns.domNode)
_.tryF(ns.$ondestory);
}
}
},
value:'',
width:120,
height:20,
tabindex:{
action:function(value){
if(this.domNode)
this.getSubNode('INPUT').attr('tabIndex',value);
}
},
disabled:{
ini:false,
action: function(v){
this.root.css('opacity',v?0.5:1);
this.getSubNode('INPUT').attr('disabled',v);
}
},
readonly:{
ini:false,
action: function(v){
this.getSubNode('INPUT').attr('readonly',v).css('cursor',v?'default':'');
}
},
type:{
ini:'text',
listbox:['text','password'],
action: function(value){
this.getSubNode('INPUT').attr('type',value);
}
},
multiLines:{
ini:false,
action: function(value){
var str = this.getSubNode('INPUT').outerHTML();
str = str.replace(/^(<)[a-zA-Z]+(\s)/i, '$1'+(value?'textarea':'input')+'$2');
var v = this.boxing().getValue();
this.getSubNode('INPUT').outerHTML(str);
this.boxing().setUIValue(v);
}
},
tipsBinder:'',
$border:1
},
EventHandlers:{
onFocus:function(profile){},
onBlur:function(profile){},
beforeFormatCheck:function(profile, value){},
beforeFormatMark:function(profile, formatErr){}
},
_prepareData:function(profile){
var d=arguments.callee.upper.call(this, profile);
d.cursor = d.readonly?'default':'';
d.type = d.type || '';
if(linb.browser.kde)
d._css='resize:none;';
return d;
},
_dynamicTemplate:function(profile){
var properties = profile.properties,
hash = profile._exhash = "$" +'multiLines:'+properties.multiLines,
template = profile.box.getTemplate(hash);
properties.$UIvalue = properties.value;
// set template dynamic
if(!template){
template = _.clone(profile.box.getTemplate());
if(properties.multiLines){
template.FRAME.BORDER.BOX.INPUT.tagName='textarea';
delete template.FRAME.BORDER.BOX.INPUT.type;
}
// set template
profile.box.setTemplate(template, hash);
}
profile.template = template;
},
RenderTrigger:function(){
var ns=this,p=ns.properties;
_.asyRun(function(){
ns.boxing()._setTB(1);
});
ns.getSubNode('BOX').$firfox2();
},
LayoutTrigger:function(){
var p = this.properties;
if(p.mask)this.boxing().setMask(p.mask,true);
},
//v=value.substr(0,caret);
//i=v.lastIndexOf(ms);
_changeMask:function(profile,src,v,dir){
var ns=this,
p=profile.properties,
map=ns._maskMap,
ms=ns._maskSpace,
maskTxt=p.mask,
maskStr = profile.$Mask,
input = linb([src]),
caret = input.caret();
//for backspace
if(dir===false && caret[0]==caret[1] && caret[0]>0)
input.caret(caret[0]-1,caret[0]);
//for delete
if(dir===undefined && caret[0]==caret[1])
input.caret(caret[0],caret[0]+1);
//for caret is from a fix char, nav to the next 'input allow' char
if(dir===true){
if(maskStr.charAt(caret[0])!=ms){
var from = caret[0] + maskStr.substr(caret[0],maskStr.length).indexOf(ms);
input.caret(from,Math.max(caret[1],from))
}
}
var caret = input.caret(),
value=src.value,
reg = ns._maskMap[p.mask.charAt(caret[0])],
i,t;
if(reg && new RegExp('^'+reg+'$').test(v) || v==''){
t=value;
//if select some text
if(caret[0]!=caret[1])
t=t.substr(0,caret[0]) + maskStr.substr(caret[0],caret[1]-caret[0]) + t.substr(caret[1],t.length-caret[1]);
//if any char input
if(v)
t=t.substr(0,caret[0])+v+t.substr(caret[0]+1,t.length-caret[0]-1);
//get corret string according to maskTxt
var a=[];
_.arr.each(maskTxt.split(''),function(o,i){
a.push( (new RegExp('^'+(map[o]?map[o]:'\\'+o)+'$').test(t.charAt(i))) ? t.charAt(i) : maskStr.charAt(i))
});
//if input visible char
if(dir===true){
v=maskStr.substr(caret[0]+1,value.length-caret[0]-1);
i=v.indexOf(ms);
i=caret[0] + (i==-1?0:i) + 1;
}else
i=caret[0];
//in opera, delete/backspace cant be stopbubbled
//add a dummy maskSpace
if(linb.browser.opr){
//delete
if(dir===undefined)
_.arr.insertAny(a,ms,i);
//backspace
if(dir===false)
_.arr.insertAny(a,ms,i++);
}
profile.boxing().setUIValue(src.value=a.join(''));
ns._setCaret(profile,src,i);
}
},
_setCaret:function(profile, src, pos){
if(profile.properties.mask){
if(typeof pos !='number')
pos=src.value.indexOf(this._maskSpace);
linb([src]).caret(pos,pos);
}
},
//check valid manually
_checkValid:function(profile, value){
var p=profile.properties,
vf1 = (p.mask&&profile.$MaskFormat) ,
vf2 = p.valueFormat || profile.$valueFormat;
if( (profile.beforeFormatCheck && (profile.boxing().beforeFormatCheck(profile, value)===false)) ||
(vf1 && typeof vf1=='string' && !(new RegExp(vf1)).test(value||'')) ||
(vf2 && typeof vf2=='string' && !(new RegExp(vf2)).test(value||''))
){
profile.inValid=2;
return false;
}{
profile.inValid=3;
return true;
}
},
_maskF:function(profile,src, pro){
var id=src.id;
_.resetRun(profile.$id+"_mask",function(){
if(linb.browser.ie && pro!='value')return;
var src=linb.Dom.byId(id);
if(src.value.length != profile.$Mask.length)
profile.box._changeMask(profile,src,'',true);
});
},
_onresize:function(profile,width,height){
var size = arguments.callee.upper.apply(this,arguments),
v=profile.getSubNodes(['INPUT','BOX']),
b=linb.browser;
if(null!==width)
v.width(size.width);
if(null!==height)
v.height(size.height/* -(b.ie6?2:b.ie?1:b.kde?1:0)*/);
return size;
}
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -