📄 comboinput.js
字号:
onKeydown : function(profile, e, src){
var prop=profile.properties,
m=prop.multiLines,
key=linb.Event.getKey(e);
//fire onchange first
if(key[0]=='enter'&& (!m||key[3]))
linb([src]).onChange();
if(key[0]=='down'|| key[0]=='up'){
if(prop.type=='spin'){
profile.box._spin(profile, key[0]=='up');
return false;
}if(key[1] && prop.type){
profile.boxing()._drop(e,src);
return false;
}
}
},
onKeyup : function(profile, e, src){
var prop=profile.properties,
key=linb.Event.getKey(e);
if(key[0]=='down'|| key[0]=='up'){
if(prop.type=='spin'){
linb.Thread.abort(profile.$id+':spin');
return false;
}
}
},
onClick : function(profile, e, src){
if(src.readOnly)
profile.boxing()._drop(e, src);
}
},
R1:{
onMousedown:function(profile){
profile.box._spin(profile, true);
},
onMouseout:function(profile){
linb.Thread.abort(profile.$id+':spin');
},
onMouseup:function(profile){
linb.Thread.abort(profile.$id+':spin');
}
},
R2:{
onMousedown:function(profile){
profile.box._spin(profile, false);
},
onMouseout:function(profile){
linb.Thread.abort(profile.$id+':spin');
},
onMouseup:function(profile){
linb.Thread.abort(profile.$id+':spin');
}
}
},
EventHandlers:{
onFileDlgOpen:function(profile, node){},
onSave:function(profile, node){},
onClickButton:function(profile, pos, e, src){}
},
_posMap:{
none:'',
combobox:'left top',
listbox:'left top',
upload:'-16px top',
getter:'left -27px',
helpinput:'left -91px',
cmdbox:'left -14px',
popbox:'left -40px',
timepicker:'left -53px',
datepicker:'left -66px',
colorpicker:'left -79px'
},
DataModel:{
listKey:{
set:function(v){
var t = this.constructor.getCachedData(v);
return this.each(function(o){
o.boxing().setItems(t?t:o.properties.items);
o.properties.listKey = v;
});
}
},
items:{
ini:[],
action:function(v){
var self=this;
self.boxing().setValue(null,true);
self.SubSerialIdMapItem={};
self.ItemIdMapSubSerialId={};
//for memory map
self.box._prepareItems(self, v);
if(v.domNode)
self.boxing().clearPopCache();
}
},
readonly:{
ini:false,
action:function(v){
if(!v && this.properties.type=='listbox')return;
this.getSubNode('INPUT').css('cursor',v?'pointer':'default').attr('readonly',v);
}
},
type:{
ini:'combobox',
listbox:_.toArr('none,combobox,listbox,upload,getter,helpinput,cmdbox,popbox,timepicker,datepicker,colorpicker,spin'),
set:function(value, flag){
return this.each(function(pro){
if(pro.properties.type!=value||flag){
pro.properties.type=value;
pro.box._iniType(pro);
if(pro.domNode)
pro.boxing().refresh();
}
});
}
},
scale:2,
increment:0.01,
min:0,
max:1,
saveBtn:{
ini:false,
action:function(v){
this.boxing().refresh();
}
},
$border:1
},
RenderTrigger:function(){
var self=this,
instance=self.boxing(),
p=self.properties;
self.box._iniType(self);
if(p.readonly)
instance.setReadonly(true,true);
},
_spin:function(profile, flag){
var id=profile.$id+':spin';
if(linb.Thread.isAlive(id))return;
var prop=profile.properties,
off=prop.increment*(flag?1:-1),
task={delay:300},
fun=function(){
profile.boxing().setUIValue(String((+prop.$UIvalue||0)+off));
task.delay *=0.9;
};
task.task=fun;
linb.Thread(id,[task],500,null,fun,null,true).start();
},
_dynamicTemplate:function(profile){
var properties = profile.properties,
hash = profile._exhash = "$" +
'multiLines:'+properties.multiLines+';'+
'type:'+properties.type+';',
template = profile.box.getTemplate(hash);
properties.$UIvalue = properties.value;
// set template dynamic
if(!template){
template = _.clone(profile.box.getTemplate());
var t=template.FRAME.BORDER;
if(properties.multiLines){
t.BOX.INPUT.tagName='textarea';
delete t.BOX.INPUT.type;
}
switch(properties.type){
case 'spin':
t.RBTN={
$order:5,
style:"{rDisplay}",
R1:{
R1T:{},
R1B:{}
},
R2:{
R2T:{},
R2B:{}
}
};
break;
case 'none':
break;
case 'upload':
t.UPLOAD={
$order:2,
tagName:'input',
type:'file',
size:'1'
};
default:
t.BTN={
$order:4,
style:"{popbtnDisplay}",
TOP:{},
MID:{
style:'{typePos}'
}
};
}
// set template
profile.box.setTemplate(template, hash);
}
profile.template = template;
},
_prepareData:function(profile){
var data=arguments.callee.upper.call(this, profile),
map=profile.box._posMap;
if(map[data.type])
data.typePos = 'background-position:'+map[data.type];
data.saveDisplay = data.saveBtn?'':'display:none';
data.popbtnDisplay = data.type!='none'?'':'display:none';
return data;
},
_ensureValue:function(profile, value){
var me=arguments.callee, reg=me._reg||(me._reg=/^#[\w]{6}$/),prop=profile.properties;
switch(profile.properties.type){
case 'datepicker':
return (value.constructor==Date?value.getTime():value) + "";
case 'colorpicker':
return '#'+linb.UI.ColorPicker._ensureValue(null,value);
case 'timepicker':
return linb.UI.TimePicker._ensureValue(null,value);
case 'spin':
var n=Math.pow(10,prop.scale);
value=+value||0;
value=Math.ceil((value-0.0000000000003)*n)/n;
return String(value>prop.max?prop.max:value<prop.min?prop.min:value);
default:
return String(value);
}
},
_onresize:function(profile,width,height){
var size=linb.UI.Widget._onresize.apply(this,arguments),
prop=profile.properties,
px='px',
f=function(k){return k?profile.getSubNode(k)._nodes[0]:null},
type=prop.type,
input=f('INPUT'),
save=f(prop.saveBtn?'SBTN':null),
btn=f(type=='spin'?'RBTN':type=='none'?null:'BTN')
;
if(!_.isNull(width))
input.style.width = (size.width-(save?save.offsetWidth:0)-(btn?btn.offsetWidth:0))+px;
if(!_.isNull(height)){
height=size.height+px;
/*-(linb.browser.ie6?2:linb.browser.ie?1:linb.browser.kde?1:0)*/
input.style.height=height;
if(save)save.style.height=height;
if(btn)
btn.style.height=height;
if(prop.type=='spin'){
height=size.height/2+px;
f('R1').style.height=height;
f('R2').style.height=height;
}
}
}
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -