📄 resizer.js
字号:
//resizer class, add a plug in to linb.Dom
Class("linb.UI.Resizer","linb.UI",{
Instance:{
_attachTo:function(target, parent){
var self=this, v=self.get(0);
//set target first
v._target= linb(target);
v._parent= parent || linb('body');
//add to dom
v._parent.append(self);
v.$resizeId = linb(target).id();
return self;
},
show:function(){
var self=this;
self.each(function(o){
o.root.css('display',o.$display||'block');
});
if(linb.browser.ie)
self.reBoxing().ieRemedy();
return self;
},
hide:function(){
var self=this;
self.each(function(o){
o.$display = o.root.css('display');
});
self.reBoxing().css('display','none');
return self;
}
},
Initialize:function(){
this.addTemplateKeys(['HANDLER','HIDDEN','MOVE','L','R','T','B','LT','RT','LB','RB']);
_.each({
// add resizer to linb.Dom plugin
addResizer:function(properties, onUpdate){
var target=linb([this.get(0)]);
properties=properties||{};
_.merge(properties,{
_attached:true
});
var r = new linb.UI.Resizer(properties)._attachTo(target, target);
//set event
if(onUpdate) r.onUpdate(onUpdate);
return r;
},
removeResizer:function(){
var s = this.id();
_.arr.each(linb.UI.Resizer._cache,function(o){
if(o.$resizeId==s)
o.boxing().destroy();
});
return this;
},
$getResizer:function(){
var s = this.id(), b;
_.arr.each(linb.UI.Resizer._cache,function(o){
if(o.$resizeId==s){b=o;return false;}
});
return b && b.boxing();
}
},function(o,i){
linb.Dom.plugIn(i,o);
});
//for linb.UI.Widget
_.each({
_resizer:function(key, args){
return this.each(function(o){
var target = o.getSubNode('BORDER'),
d = o.properties;
if(target.$getResizer())return;
args = args || {};
var update = function(pro, target, size, cssPos){
var profile=arguments.callee.profile,
node=profile.root,
prop=profile.properties,
t
;
if(size){
var w=null,h=null;
if(t=size.width){
node.widthBy(t);
prop.width = w = node.width();
}
if(t=size.height){
node.heightBy(t);
prop.height = h = node.height();
}
linb.UI.$tryResize(profile,w,h,true);
}
if(cssPos){
if((t=cssPos.left) && !(prop.left=='auto'&&parseInt(prop.right)>=0)){
node.leftBy(t);
prop.left= node.left();
}
if((t=cssPos.top) && !(prop.top=='auto'&&parseInt(prop.bottom)>=0)){
node.topBy(t);
prop.top = node.top();
}
}
};
update.profile = o;
o.$resizer = target.addResizer(args, update);
});
},
_unResizer:function(){
return this.each(function(o){
var target = o.getSubNode('BORDER');
if(!target.$getResizer())return;
target.removeResizer();
delete o.$resizer;
});
}
},function(o,i){
linb.UI.Widget.plugIn(i,o);
});
linb.UI.Widget.setDataModel({
resizer:{
ini:false,
action: function(v){
var b=this.boxing();
if(v){
var t = this.properties,
arg={};
_.each('minHeight,minWidth,maxHeight,maxWidth'.split(','),function(i){
if(i in t)arg[i]=t[i];
});
b._resizer(v,arg);
}else
b._unResizer();
}
}
});
},
Static:{
Templates:{
tagName:'div',
style:'{_style};'
},
Appearances:{
KEY:{
position:'absolute',
margin:'0 -1px -1px 0',
visibility: 'visible',
'_font-size':0,
'_line-height':0,
//for ie
'*background': 'url('+linb.ini.path+'bg.gif)',
/*for get top Index, when it's static*/
'z-index':60,
cursor:'move'
},
MOVE:{
position:'absolute',
display:'block',
'z-index':100,
visibility: 'visible',
background: linb.UI.$bg('icons.gif', 'no-repeat -17px -244px', true),
'_font-size':0,
'_line-height':0
},
HANDLER:{
$order:0,
position:'absolute',
display:'block',
border:'solid 1px',
'background-color':'#fff',
'z-index':100,
visibility: 'visible',
'_font-size':0,
'_line-height':0
},
T:{
$order:1,
left:'50%',
cursor: 'n-resize'
},
RT:{
$order:1,
cursor: 'ne-resize',
'z-index': 110
},
R:{
$order:1,
top:'50%',
cursor: 'e-resize'
},
RB:{
$order:1,
cursor: 'se-resize',
'z-index': 110
},
B:{
$order:1,
left:'50%',
cursor: 's-resize'
},
LB:{
$order:1,
cursor: 'sw-resize',
'z-index': 110
},
L:{
$order:1,
top:'50%',
cursor: 'w-resize'
},
LT:{
$order:1,
cursor: 'nw-resize',
'z-index': 110
},
//must after HANDLER
HIDDEN:{
$order:10,
'background-color':'transparent',
'border-width': 0
}
},
Behaviors:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {move:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {move:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {move:true} );
},
LT:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {left:true, top:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {left:true, top:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {left:true, top:true});
}
},
RT:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {right:true, top:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {right:true, top:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {right:true, top:true});
}
},
LB:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {left:true, bottom:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {left:true, bottom:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {left:true, bottom:true});
}
},
RB:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {right:true, bottom:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {right:true, bottom:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {right:true, bottom:true});
}
},
L:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {left:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {left:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {left:true});
}
},
T:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {top:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {top:true});
},
onDragstop:function(profile, e, src){
profile.box._onDragstop(profile, e, src, {top:true});
}
},
R:{
onMousedown:function(profile, e, src){
profile.box._onMousedown(profile, e, src, {right:true});
},
onDragbegin:function(profile, e, src){
profile.box._onDragbegin(profile, e, src);
},
onDrag:function(profile, e, src){
profile.box._onDrag(profile, e, src, {right:true});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -