📄 input.js
字号:
profile.box._checkValid(profile, src.value);
profile.boxing()._setDirtyMark();
}
}
},
DataModel:{
_customBorder:'BOX',
tipsErr:'',
tipsOK:'',
border:true,
dynCheck:false,
valueFormat:{
helpinput:[
{caption : 'required', id: "[^.*]"},
{caption : 'email',id:"^[\\w\\.=-]+@[\\w\\.-]+\\.[\\w\\.-]{2,4}$"},
{caption : 'charOnly',id:"^[a-zA-Z]*$"},
{caption : 'words',id:"^[\\w ]*$"},
{caption : 'integer',id:"^-?\\d\\d*$"},
{caption : 'positiveInteger',id:"^\\d\\d*$"},
{caption : 'number',id:"^-?(\\d\\d*\\.\\d*$)|(^-?\\d\\d*$)|(^-?\\.\\d\\d*$)"},
{caption : 'filepath',id:"([\\/]?[\\w_]+)+\\.\\w{1,9}$"},
{caption : 'URL', id:"^(http|https|ftp)\\:\\/\\/[\\w\\-\\_\\.]+[\\w\\-\\_](:[\\w]*)?\\/?([\\w\\-\\._\\?\\,\\'\\/\\\\\\+&%\\$#\\=~])*$"},
{caption : 'color',id:"^\\#[0-9A-Fa-f]{6}$"},
{caption : "HH:MM", id:"^\(\([0-1][0-9]\)|\([2][0-3])\)\:\([0-5][0-9]\)$"},
{caption : "HH:MM:SS", id:"^\(\([0-1][0-9]\)|\([2][0-3])\)\:\([0-5][0-9]\)\\:\([0-5][0-9]\)$"},
{caption : "YYYY-MM-DD",id:"^\([0-9]{4}\)\\-\(\([0][0-9]\)|\([1][0-2]\)\)\\-\([0-3][0-9]\)$"},
{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:22,
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:''
},
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,t,
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){
t=template.FRAME.BORDER.BOX.WRAP.INPUT;
t.tagName='textarea';
delete t.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('WRAP').$firfox2();
if(p.readonly)
ns.boxing().setReadonly(true,true);
},
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 $hborder=1, $vborder=1,
toff=linb.UI.$getCSSValue('linb-input-wrap','top');
var t = profile.properties,
o = profile.getSubNode('BOX'),
v1=profile.getSubNode('INPUT'),
region,
ww=width,
hh=height,
left=Math.max(0, (t.$b_lw||0)-$hborder),
top=Math.max(0, (t.$b_tw||0)-$vborder);
if(null!==ww){
ww -= Math.max($hborder*2, (t.$b_lw||0)+(t.$b_rw||0));
/*for ie6 bug*/
/*for example, if single number, 100% width will add 1*/
/*for example, if single number, attached shadow will overlap*/
if(linb.browser.ie6)ww=(parseInt(ww/2))*2;
}
if(null!==hh){
hh -=Math.max($vborder*2, (t.$b_lw||0) + (t.$b_rw||0));
if(linb.browser.ie6)hh=(parseInt(hh/2))*2;
/*for ie6 bug*/
if(linb.browser.ie6&&null===width)o.ieRemedy();
}
region={left:left,top:top,width:ww,height:hh};
o.cssRegion(region);
if(ww||hh)
v1.cssSize({width:ww,height:hh?(hh-toff):null});
/*for ie6 bug*/
if((profile.$border||profile.$shadow||profile.$resizer) && linb.browser.ie)o.ieRemedy();
}
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -