2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.layout.ResizeHandle"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.layout.ResizeHandle"] = true;
|
|
|
3 |
dojo.provide("dojox.layout.ResizeHandle");
|
|
|
4 |
dojo.experimental("dojox.layout.ResizeHandle");
|
|
|
5 |
|
|
|
6 |
dojo.require("dijit._Widget");
|
|
|
7 |
dojo.require("dijit._Templated");
|
|
|
8 |
dojo.require("dojo.fx");
|
|
|
9 |
|
|
|
10 |
dojo.declare("dojox.layout.ResizeHandle", [dijit._Widget, dijit._Templated], {
|
|
|
11 |
// summary
|
|
|
12 |
// The handle on the bottom-right corner of FloatingPane or other widgets that allows
|
|
|
13 |
// the widget to be resized.
|
|
|
14 |
// Typically not used directly.
|
|
|
15 |
|
|
|
16 |
// targetId: String
|
|
|
17 |
// id of the Widget OR DomNode that I will size
|
|
|
18 |
targetId: '',
|
|
|
19 |
|
|
|
20 |
// targetContainer: DomNode
|
|
|
21 |
// over-ride targetId and attch this handle directly to a reference of a DomNode
|
|
|
22 |
targetContainer: null,
|
|
|
23 |
|
|
|
24 |
// resizeAxis: String
|
|
|
25 |
// one of: x|y|xy limit resizing to a single axis, default to xy ...
|
|
|
26 |
resizeAxis: "xy",
|
|
|
27 |
|
|
|
28 |
// activeResize: Boolean
|
|
|
29 |
// if true, node will size realtime with mouse movement,
|
|
|
30 |
// if false, node will create virtual node, and only resize target on mouseUp
|
|
|
31 |
activeResize: false,
|
|
|
32 |
|
|
|
33 |
// activeResizeClass: String
|
|
|
34 |
// css class applied to virtual resize node.
|
|
|
35 |
activeResizeClass: 'dojoxResizeHandleClone',
|
|
|
36 |
|
|
|
37 |
// animateSizing: Boolean
|
|
|
38 |
// only applicable if activeResize = false. onMouseup, animate the node to the
|
|
|
39 |
// new size
|
|
|
40 |
animateSizing: true,
|
|
|
41 |
|
|
|
42 |
// animateMethod: String
|
|
|
43 |
// one of "chain" or "combine" ... visual effect only. combine will "scale"
|
|
|
44 |
// node to size, "chain" will alter width, then height
|
|
|
45 |
animateMethod: 'chain',
|
|
|
46 |
|
|
|
47 |
// animateDuration: Integer
|
|
|
48 |
// time in MS to run sizing animation. if animateMethod="chain", total animation
|
|
|
49 |
// playtime is 2*animateDuration
|
|
|
50 |
animateDuration: 225,
|
|
|
51 |
|
|
|
52 |
// minHeight: Integer
|
|
|
53 |
// smallest height in px resized node can be
|
|
|
54 |
minHeight: 100,
|
|
|
55 |
|
|
|
56 |
// minWidth: Integer
|
|
|
57 |
// smallest width in px resize node can be
|
|
|
58 |
minWidth: 100,
|
|
|
59 |
|
|
|
60 |
// resize handle template, fairly easy to override:
|
|
|
61 |
templateString: '<div dojoAttachPoint="resizeHandle" class="dojoxResizeHandle"><div></div></div>',
|
|
|
62 |
|
|
|
63 |
// private propteries and holders
|
|
|
64 |
_isSizing: false,
|
|
|
65 |
_connects: [],
|
|
|
66 |
_activeResizeNode: null,
|
|
|
67 |
_activeResizeLastEvent: null,
|
|
|
68 |
// defaults to match default resizeAxis. set resizeAxis variable to modify.
|
|
|
69 |
_resizeX: true,
|
|
|
70 |
_resizeY: true,
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
postCreate: function(){
|
|
|
74 |
// summary: setup our one major listener upon creation
|
|
|
75 |
dojo.connect(this.resizeHandle, "onmousedown", this, "_beginSizing");
|
|
|
76 |
if(!this.activeResize){
|
|
|
77 |
this._activeResizeNode = document.createElement('div');
|
|
|
78 |
dojo.addClass(this._activeResizeNode,this.activeResizeClass);
|
|
|
79 |
}else{ this.animateSizing = false; }
|
|
|
80 |
|
|
|
81 |
if (!this.minSize) {
|
|
|
82 |
this.minSize = { w: this.minWidth, h: this.minHeight };
|
|
|
83 |
}
|
|
|
84 |
// should we modify the css for the cursor hover to n-resize nw-resize and w-resize?
|
|
|
85 |
this._resizeX = this._resizeY = false;
|
|
|
86 |
switch (this.resizeAxis.toLowerCase()) {
|
|
|
87 |
case "xy" :
|
|
|
88 |
this._resizeX = this._resizeY = true;
|
|
|
89 |
// FIXME: need logic to determine NW or NE class to see
|
|
|
90 |
// based on which [todo] corner is clicked
|
|
|
91 |
dojo.addClass(this.resizeHandle,"dojoxResizeNW");
|
|
|
92 |
break;
|
|
|
93 |
case "x" :
|
|
|
94 |
this._resizeX = true;
|
|
|
95 |
dojo.addClass(this.resizeHandle,"dojoxResizeW");
|
|
|
96 |
break;
|
|
|
97 |
case "y" :
|
|
|
98 |
this._resizeY = true;
|
|
|
99 |
dojo.addClass(this.resizeHandle,"dojoxResizeN");
|
|
|
100 |
break;
|
|
|
101 |
}
|
|
|
102 |
},
|
|
|
103 |
|
|
|
104 |
_beginSizing: function(/*Event*/ e){
|
|
|
105 |
// summary: setup movement listeners and calculate initial size
|
|
|
106 |
|
|
|
107 |
if (this._isSizing){ return false; }
|
|
|
108 |
|
|
|
109 |
this.targetWidget = dijit.byId(this.targetId);
|
|
|
110 |
|
|
|
111 |
// FIXME: resizing widgets does weird things, disable virtual resizing for now:
|
|
|
112 |
if (this.targetWidget) { this.activeResize = true; }
|
|
|
113 |
|
|
|
114 |
this.targetDomNode = this.targetWidget ? this.targetWidget.domNode : dojo.byId(this.targetId);
|
|
|
115 |
if (this.targetContainer) { this.targetDomNode = this.targetContainer; }
|
|
|
116 |
if (!this.targetDomNode){ return; }
|
|
|
117 |
|
|
|
118 |
if (!this.activeResize) {
|
|
|
119 |
this.targetDomNode.appendChild(this._activeResizeNode);
|
|
|
120 |
dojo.fadeIn({ node: this._activeResizeNode, duration:120,
|
|
|
121 |
beforeBegin: dojo.hitch(this,function(){
|
|
|
122 |
this._activeResizeNode.style.display='';
|
|
|
123 |
})
|
|
|
124 |
}).play();
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
this._isSizing = true;
|
|
|
128 |
this.startPoint = {'x':e.clientX, 'y':e.clientY};
|
|
|
129 |
|
|
|
130 |
// FIXME: this is funky: marginBox adds height, contentBox ignores padding (expected, but foo!)
|
|
|
131 |
var mb = (this.targetWidget) ? dojo.marginBox(this.targetDomNode) : dojo.contentBox(this.targetDomNode);
|
|
|
132 |
this.startSize = { 'w':mb.w, 'h':mb.h };
|
|
|
133 |
|
|
|
134 |
this._connects = [];
|
|
|
135 |
this._connects.push(dojo.connect(document,"onmousemove",this,"_updateSizing"));
|
|
|
136 |
this._connects.push(dojo.connect(document,"onmouseup", this, "_endSizing"));
|
|
|
137 |
|
|
|
138 |
e.preventDefault();
|
|
|
139 |
},
|
|
|
140 |
|
|
|
141 |
_updateSizing: function(/*Event*/ e){
|
|
|
142 |
// summary: called when moving the ResizeHandle ... determines
|
|
|
143 |
// new size based on settings/position and sets styles.
|
|
|
144 |
|
|
|
145 |
if(this.activeResize){
|
|
|
146 |
this._changeSizing(e);
|
|
|
147 |
}else{
|
|
|
148 |
var tmp = this._getNewCoords(e);
|
|
|
149 |
if(tmp === false){ return; }
|
|
|
150 |
dojo.style(this._activeResizeNode,"width",tmp.width+"px");
|
|
|
151 |
dojo.style(this._activeResizeNode,"height",tmp.height+"px");
|
|
|
152 |
this._activeResizeNode.style.display='';
|
|
|
153 |
}
|
|
|
154 |
},
|
|
|
155 |
|
|
|
156 |
_getNewCoords: function(/* Event */ e){
|
|
|
157 |
|
|
|
158 |
// On IE, if you move the mouse above/to the left of the object being resized,
|
|
|
159 |
// sometimes clientX/Y aren't set, apparently. Just ignore the event.
|
|
|
160 |
try{
|
|
|
161 |
if(!e.clientX || !e.clientY){ return false; }
|
|
|
162 |
}catch(e){
|
|
|
163 |
// sometimes you get an exception accessing above fields...
|
|
|
164 |
return false;
|
|
|
165 |
}
|
|
|
166 |
this._activeResizeLastEvent = e;
|
|
|
167 |
|
|
|
168 |
var dx = this.startPoint.x - e.clientX;
|
|
|
169 |
var dy = this.startPoint.y - e.clientY;
|
|
|
170 |
|
|
|
171 |
var newW = (this._resizeX) ? this.startSize.w - dx : this.startSize.w;
|
|
|
172 |
var newH = (this._resizeY) ? this.startSize.h - dy : this.startSize.h;
|
|
|
173 |
|
|
|
174 |
// minimum size check
|
|
|
175 |
if(this.minSize){
|
|
|
176 |
//var mb = dojo.marginBox(this.targetDomNode);
|
|
|
177 |
if(newW < this.minSize.w){
|
|
|
178 |
newW = this.minSize.w;
|
|
|
179 |
}
|
|
|
180 |
if(newH < this.minSize.h){
|
|
|
181 |
newH = this.minSize.h;
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
return {width:newW, height:newH}; // Object
|
|
|
185 |
},
|
|
|
186 |
|
|
|
187 |
_changeSizing: function(/*Event*/ e){
|
|
|
188 |
// summary: apply sizing information based on information in (e) to attached node
|
|
|
189 |
var tmp = this._getNewCoords(e);
|
|
|
190 |
if(tmp===false){ return; }
|
|
|
191 |
|
|
|
192 |
if(this.targetWidget && typeof this.targetWidget.resize == "function"){
|
|
|
193 |
this.targetWidget.resize({ w: tmp.width, h: tmp.height });
|
|
|
194 |
}else{
|
|
|
195 |
if(this.animateSizing){
|
|
|
196 |
var anim = dojo.fx[this.animateMethod]([
|
|
|
197 |
dojo.animateProperty({
|
|
|
198 |
node: this.targetDomNode,
|
|
|
199 |
properties: {
|
|
|
200 |
width: { start: this.startSize.w, end: tmp.width, unit:'px' }
|
|
|
201 |
},
|
|
|
202 |
duration: this.animateDuration
|
|
|
203 |
}),
|
|
|
204 |
dojo.animateProperty({
|
|
|
205 |
node: this.targetDomNode,
|
|
|
206 |
properties: {
|
|
|
207 |
height: { start: this.startSize.h, end: tmp.height, unit:'px' }
|
|
|
208 |
},
|
|
|
209 |
duration: this.animateDuration
|
|
|
210 |
})
|
|
|
211 |
]);
|
|
|
212 |
anim.play();
|
|
|
213 |
}else{
|
|
|
214 |
dojo.style(this.targetDomNode,"width",tmp.width+"px");
|
|
|
215 |
dojo.style(this.targetDomNode,"height",tmp.height+"px");
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
e.preventDefault();
|
|
|
219 |
},
|
|
|
220 |
|
|
|
221 |
_endSizing: function(/*Event*/ e){
|
|
|
222 |
// summary: disconnect listenrs and cleanup sizing
|
|
|
223 |
dojo.forEach(this._connects,function(c){
|
|
|
224 |
dojo.disconnect(c);
|
|
|
225 |
});
|
|
|
226 |
if(!this.activeResize){
|
|
|
227 |
dojo.fadeOut({ node:this._activeResizeNode, duration:250,
|
|
|
228 |
onEnd: dojo.hitch(this,function(){
|
|
|
229 |
this._activeResizeNode.style.display="none";
|
|
|
230 |
})
|
|
|
231 |
}).play();
|
|
|
232 |
this._changeSizing(e);
|
|
|
233 |
}
|
|
|
234 |
this._isSizing = false;
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
});
|
|
|
238 |
|
|
|
239 |
}
|