?? input.js
字號:
Class("linb.UI.Input", ["linb.UI.Widget","linb.absValue"] ,{
Instance:{
_setTB:function(type){
var profile=this.get(0), p=profile.properties, o, t;
if(!profile.host|| !p.tipsBinder)return;
t = profile.tips = profile.tips||p.tips||'';
o = profile.host[p.tipsBinder];
if(o && o.KEY=='linb.UI.Div'){
//use innerHTML, not setHtml
o.get(0).domNode.innerHTML = t.charAt(0)=='$'?linb.wrapRes(t):t;
o.reBoxing().css('color', type==1?'gray':type==2?'red':'#000');
}
},
activate:function(){
var profile = this.get(0);
if(profile.domNode){
var node=profile.getSubNode('INPUT').get(0);
node.focus();
if(!node.readOnly && node.select)node.select();
}
return this;
},
_setCtrlValue:function(value){
if(_.isNull(value) || !_.exists(value))value='';
return this.each(function(profile){
profile.getSubNode('INPUT').attr('value',value+"");
});
},
_getCtrlValue:function(){
var profile=this.get(0);
return profile.getSubNode('INPUT').attr('value');
},
_setDirtyMark:function(){
return this.each(function(profile){
var properties = profile.properties,
o=profile.getSubNode('INPUT'),
cls=profile.box,
box=profile.boxing(),
d=linb.UI.$css_tag_dirty,
v=linb.UI.$css_tag_invalid,
flag=properties.value !== properties.$UIvalue;
//dirty mark
if(profile.beforeDirtyMark && false===box.beforeDirtyMark(profile,flag)){}
else{
if(flag)
o.addClass(d);
else
o.removeClass(d);
}
//format statux
if(profile.beforeFormatMark && false===box.beforeFormatMark(profile, profile.inValid==2)){}
else{
var err = profile.getSubNode('ERROR');
if(profile.inValid==2){
o.addClass(v);
err.css('display','block');
}else{
o.removeClass(v);
err.css('display','none');
}
}
if(profile.inValid==2){
//display tips
profile.tips = properties.tipsErr || properties.tips;
if(properties.mask)
_.asyRun(function(){
box.setUIValue(o.get(0).value=profile.$Mask)
});
}else{
if(profile.inValid==1)
profile.tips = properties.tips;
else{
profile.tips = properties.tipsOK || properties.tips;
}
}
box._setTB(profile.inValid);
});
}
},
Initialize:function(){
//modify default template fro shell
var t = this.getTemplate();
_.merge(t.FRAME.BORDER,{
BOX:{
tagName : 'div',
INPUT:{
tagName : 'input',
type : '{type}',
tabindex:'{tabindex}',
cursor:'{cursor}',
style:'{_css}'
}
}
},'all');
t.FRAME.ERROR = {};
this.setTemplate(t)
},
Static:{
_maskMap:{
'~':'[+-]',
'1':'[0-9]',
'a':'[A-Za-z]',
'*':'[A-Za-z0-9]'
},
_maskSpace:'_',
Appearances:{
KEY:{
'font-family': '"Verdana", "Helvetica", "sans-serif"',
position:'relative'
},
BORDER:{
'line-height':'0px',
'font-size':'0px',
'background-color':'#fff',
border: '1px solid #7F9DB9'
},
'BORDER-focus, BORDER-mouseover':{
$order:1,
border: '1px solid #FFD700'
},
BOX:{
left:0,
top:0,
//for firefox bug: cursor not show
position:'absolute',
overflow:linb.browser.gek?'auto':'',
'z-index':'10'
},
INPUT:{
border:0,
padding:0,
margin:0,
'font-size':'12px',
position:'relative',
overflow:'auto',
'background-color':'transparent',
'overflow-y':(linb.browser.gek||linb.browser.ie)?'auto':'',
'overflow-x':(linb.browser.gek||linb.browser.ie)?'hidden':''
},
ERROR:{
width:'16px',
height:'16px',
position:'absolute',
right:0,
top:0,
display:'none',
'font-size':0,
background: linb.UI.$bg('icon.gif', ' no-repeat left top', true),
'z-index':'50'
}
},
Behaviors:{
HoverEffected:{KEY:['BORDER']},
NavKeys:{INPUT:1},
INPUT:{
onChange:function(profile, e, src){
var o=profile.inValid;
profile.boxing().setUIValue(src.value);
//input/textarea is special, ctrl value will be set before the $UIvalue
profile.properties.$UIvalue=src.value;
if(o!==profile.inValid) if(profile.domNode)profile.boxing()._setDirtyMark();
},
//if properties.mask exists, onHotKeyxxx wont be tigger any more
onKeydown:function(profile, e, src){
var p=profile.properties,
m=p.multiLines,
b=profile.box,
evt=linb.Event,
k=evt.getKey(e);
//fire onchange first
if(k[0]=='enter'&& (!m||k[3]))
linb([src]).onChange();
if(p.mask){
if(k[0].length>1)profile.$ignore=true;
else delete profile.$ignore;
switch(k[0]){
case 'backspace':
b._changeMask(profile,src,'',false);
return false;
case 'delete':
b._changeMask(profile,src,'');
return false;
}
}
},
onKeypress:function(profile, e, src){
var p=profile.properties,cls=profile.box,map=cls._maskMap;
if(p.mask){
if(profile.$ignore){
delete profile.$ignore;
return true;
}
var evt=linb.Event,
k=evt.getKey(e);
if(k[1]||k[3])return true;
cls._changeMask(profile,src,k[0],true);
return false;
}
},
onKeyup:function(profile, e, src){
var p=profile.properties;
if(p.dynCheck){
profile.box._checkValid(profile, src.value);
profile.boxing()._setDirtyMark();
}
},
onFocus:function(profile, e, src){
var p=profile.properties,b=profile.box;
if(p.disabled)return false;
if(profile.onFocus)profile.boxing().onFocus(profile);
profile.getSubNode('BORDER').tagClass('-focus');
//if no value, add mask
if(p.mask){
//ondrop in opera or safari will trigger onfocus event.
if(linb.browser.opr ||linb.browser.kde)
b._maskF(profile,src);
if(!src.value)
_.asyRun(function(){
profile.boxing().setUIValue(src.value=profile.$Mask);
b._setCaret(profile,src)
});
}
//show tips color
profile.boxing()._setTB(3);
},
onBlur:function(profile, e, src){
var p=profile.properties;
if(p.disabled)return false;
if(profile.onBlur)profile.boxing().onBlur(profile);
profile.getSubNode('BORDER').tagClass('-focus',false);
//onblur check it
if(p.$UIvalue==src.value)
profile.box._checkValid(profile, src.value);
profile.boxing()._setDirtyMark();
}
}
},
DataModel:{
tipsErr:'',
tipsOK:'',
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]\)$"},
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -