root / trunk / web / dojo / dojox / layout / ResizeHandle.js
History | View | Annotate | Download (5.1 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.layout.ResizeHandle"]){ |
9 |
dojo._hasResource["dojox.layout.ResizeHandle"]=true; |
10 |
dojo.provide("dojox.layout.ResizeHandle");
|
11 |
dojo.experimental("dojox.layout.ResizeHandle");
|
12 |
dojo.require("dijit._Widget");
|
13 |
dojo.require("dijit._Templated");
|
14 |
dojo.require("dojo.fx");
|
15 |
dojo.require("dojo.window");
|
16 |
dojo.declare("dojox.layout.ResizeHandle",[dijit._Widget,dijit._Templated],{targetId:"",targetContainer:null,resizeAxis:"xy",activeResize:false,activeResizeClass:"dojoxResizeHandleClone",animateSizing:true,animateMethod:"chain",animateDuration:225,minHeight:100,minWidth:100,constrainMax:false,maxHeight:0,maxWidth:0,fixedAspect:false,intermediateChanges:false,startTopic:"/dojo/resize/start",endTopic:"/dojo/resize/stop",templateString:"<div dojoAttachPoint=\"resizeHandle\" class=\"dojoxResizeHandle\"><div></div></div>",postCreate:function(){ |
17 |
this.connect(this.resizeHandle,"onmousedown","_beginSizing"); |
18 |
if(!this.activeResize){ |
19 |
this._resizeHelper=dijit.byId("dojoxGlobalResizeHelper"); |
20 |
if(!this._resizeHelper){ |
21 |
this._resizeHelper=new dojox.layout._ResizeHelper({id:"dojoxGlobalResizeHelper"}).placeAt(dojo.body()); |
22 |
dojo.addClass(this._resizeHelper.domNode,this.activeResizeClass); |
23 |
} |
24 |
}else{
|
25 |
this.animateSizing=false; |
26 |
} |
27 |
if(!this.minSize){ |
28 |
this.minSize={w:this.minWidth,h:this.minHeight}; |
29 |
} |
30 |
if(this.constrainMax){ |
31 |
this.maxSize={w:this.maxWidth,h:this.maxHeight}; |
32 |
} |
33 |
this._resizeX=this._resizeY=false; |
34 |
var _1=dojo.partial(dojo.addClass,this.resizeHandle); |
35 |
switch(this.resizeAxis.toLowerCase()){ |
36 |
case "xy": |
37 |
this._resizeX=this._resizeY=true; |
38 |
_1("dojoxResizeNW");
|
39 |
break;
|
40 |
case "x": |
41 |
this._resizeX=true; |
42 |
_1("dojoxResizeW");
|
43 |
break;
|
44 |
case "y": |
45 |
this._resizeY=true; |
46 |
_1("dojoxResizeN");
|
47 |
break;
|
48 |
} |
49 |
},_beginSizing:function(e){ |
50 |
if(this._isSizing){ |
51 |
return false; |
52 |
} |
53 |
dojo.publish(this.startTopic,[this]); |
54 |
this.targetWidget=dijit.byId(this.targetId); |
55 |
this.targetDomNode=this.targetWidget?this.targetWidget.domNode:dojo.byId(this.targetId); |
56 |
if(this.targetContainer){ |
57 |
this.targetDomNode=this.targetContainer; |
58 |
} |
59 |
if(!this.targetDomNode){ |
60 |
return false; |
61 |
} |
62 |
if(!this.activeResize){ |
63 |
var c=dojo.position(this.targetDomNode,true); |
64 |
this._resizeHelper.resize({l:c.x,t:c.y,w:c.w,h:c.h}); |
65 |
this._resizeHelper.show();
|
66 |
} |
67 |
this._isSizing=true; |
68 |
this.startPoint={x:e.clientX,y:e.clientY}; |
69 |
var mb=this.targetWidget?dojo.marginBox(this.targetDomNode):dojo.contentBox(this.targetDomNode); |
70 |
this.startSize={w:mb.w,h:mb.h}; |
71 |
if(this.fixedAspect){ |
72 |
var _2,_3;
|
73 |
if(mb.w>mb.h){
|
74 |
_2="w";
|
75 |
_3=mb.w/mb.h; |
76 |
}else{
|
77 |
_2="h";
|
78 |
_3=mb.h/mb.w; |
79 |
} |
80 |
this._aspect={prop:_2}; |
81 |
this._aspect[_2]=_3;
|
82 |
} |
83 |
this._pconnects=[];
|
84 |
this._pconnects.push(dojo.connect(dojo.doc,"onmousemove",this,"_updateSizing")); |
85 |
this._pconnects.push(dojo.connect(dojo.doc,"onmouseup",this,"_endSizing")); |
86 |
dojo.stopEvent(e); |
87 |
},_updateSizing:function(e){ |
88 |
if(this.activeResize){ |
89 |
this._changeSizing(e);
|
90 |
}else{
|
91 |
var _4=this._getNewCoords(e); |
92 |
if(_4===false){ |
93 |
return;
|
94 |
} |
95 |
this._resizeHelper.resize(_4);
|
96 |
} |
97 |
e.preventDefault(); |
98 |
},_getNewCoords:function(e){ |
99 |
try{
|
100 |
if(!e.clientX||!e.clientY){
|
101 |
return false; |
102 |
} |
103 |
} |
104 |
catch(e){
|
105 |
return false; |
106 |
} |
107 |
this._activeResizeLastEvent=e;
|
108 |
var dx=(this.isLeftToRight()?this.startPoint.x-e.clientX:e.clientX-this.startPoint.x),dy=this.startPoint.y-e.clientY,_5=this.startSize.w-(this._resizeX?dx:0),_6=this.startSize.h-(this._resizeY?dy:0); |
109 |
return this._checkConstraints(_5,_6); |
110 |
},_checkConstraints:function(_7,_8){ |
111 |
if(this.minSize){ |
112 |
var tm=this.minSize; |
113 |
if(_7<tm.w){
|
114 |
_7=tm.w; |
115 |
} |
116 |
if(_8<tm.h){
|
117 |
_8=tm.h; |
118 |
} |
119 |
} |
120 |
if(this.constrainMax&&this.maxSize){ |
121 |
var ms=this.maxSize; |
122 |
if(_7>ms.w){
|
123 |
_7=ms.w; |
124 |
} |
125 |
if(_8>ms.h){
|
126 |
_8=ms.h; |
127 |
} |
128 |
} |
129 |
if(this.fixedAspect){ |
130 |
var ta=this._aspect[this._aspect.prop]; |
131 |
if(_7<_8){
|
132 |
_8=_7*ta; |
133 |
}else{
|
134 |
if(_8<_7){
|
135 |
_7=_8*ta; |
136 |
} |
137 |
} |
138 |
} |
139 |
return {w:_7,h:_8}; |
140 |
},_changeSizing:function(e){ |
141 |
var _9=this._getNewCoords(e); |
142 |
if(_9===false){ |
143 |
return;
|
144 |
} |
145 |
if(this.targetWidget&&dojo.isFunction(this.targetWidget.resize)){ |
146 |
this.targetWidget.resize(_9);
|
147 |
}else{
|
148 |
if(this.animateSizing){ |
149 |
var _a=dojo.fx[this.animateMethod]([dojo.animateProperty({node:this.targetDomNode,properties:{width:{start:this.startSize.w,end:_9.w}},duration:this.animateDuration}),dojo.animateProperty({node:this.targetDomNode,properties:{height:{start:this.startSize.h,end:_9.h}},duration:this.animateDuration})]); |
150 |
_a.play(); |
151 |
}else{
|
152 |
dojo.style(this.targetDomNode,{width:_9.w+"px",height:_9.h+"px"}); |
153 |
} |
154 |
} |
155 |
if(this.intermediateChanges){ |
156 |
this.onResize(e);
|
157 |
} |
158 |
},_endSizing:function(e){ |
159 |
dojo.forEach(this._pconnects,dojo.disconnect);
|
160 |
var _b=dojo.partial(dojo.publish,this.endTopic,[this]); |
161 |
if(!this.activeResize){ |
162 |
this._resizeHelper.hide();
|
163 |
this._changeSizing(e);
|
164 |
setTimeout(_b,this.animateDuration+15); |
165 |
}else{
|
166 |
_b(); |
167 |
} |
168 |
this._isSizing=false; |
169 |
this.onResize(e);
|
170 |
},onResize:function(e){ |
171 |
}}); |
172 |
dojo.declare("dojox.layout._ResizeHelper",dijit._Widget,{show:function(){ |
173 |
dojo.fadeIn({node:this.domNode,duration:120,beforeBegin:function(n){ |
174 |
dojo.style(n,"display",""); |
175 |
}}).play(); |
176 |
},hide:function(){ |
177 |
dojo.fadeOut({node:this.domNode,duration:250,onEnd:function(n){ |
178 |
dojo.style(n,"display","none"); |
179 |
}}).play(); |
180 |
},resize:function(_c){ |
181 |
dojo.marginBox(this.domNode,_c);
|
182 |
}}); |
183 |
} |