| 1 |
define(["dojo/_base/kernel","dojo/_base/lang","dojo/_base/connect","dojo/_base/array","dojo/_base/event", |
| 2 |
"dojo/_base/fx","dojo/_base/window","dojo/fx","dojo/dom","dojo/dom-class", |
| 3 |
"dojo/dom-geometry","dojo/dom-style","dojo/_base/declare", "dojo/touch", |
| 4 |
"dijit/_base/manager","dijit/_Widget","dijit/_TemplatedMixin" |
| 5 |
], function ( |
| 6 |
kernel, lang, connect, arrayUtil, eventUtil, fxBase, windowBase, fxUtil, |
| 7 |
domUtil, domClass, domGeometry, domStyle, declare, touch, manager, Widget, TemplatedMixin) { |
| 8 |
|
| 9 |
kernel.experimental("dojox.layout.ResizeHandle"); |
| 10 |
|
| 11 |
var _ResizeHelper = declare("dojox.layout._ResizeHelper", Widget, { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
show: function(){ |
| 17 |
|
| 18 |
|
| 19 |
domStyle.set(this.domNode, "display", ""); |
| 20 |
}, |
| 21 |
|
| 22 |
hide: function(){ |
| 23 |
|
| 24 |
|
| 25 |
domStyle.set(this.domNode, "display", "none"); |
| 26 |
}, |
| 27 |
|
| 28 |
resize: function(dim){ |
| 29 |
|
| 30 |
|
| 31 |
domGeometry.setMarginBox(this.domNode, dim); |
| 32 |
} |
| 33 |
|
| 34 |
}); |
| 35 |
|
| 36 |
var ResizeHandle = declare("dojox.layout.ResizeHandle",[Widget, TemplatedMixin], |
| 37 |
{ |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
targetId: "", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
targetContainer: null, |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
resizeAxis: "xy", |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
activeResize: false, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
activeResizeClass: "dojoxResizeHandleClone", |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
animateSizing: true, |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
animateMethod: "chain", |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
animateDuration: 225, |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
minHeight: 100, |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
minWidth: 100, |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
constrainMax: false, |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
maxHeight:0, |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
maxWidth:0, |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
fixedAspect: false, |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
intermediateChanges: false, |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
startTopic: "/dojo/resize/start", |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
endTopic:"/dojo/resize/stop", |
| 122 |
|
| 123 |
templateString: '<div dojoAttachPoint="resizeHandle" class="dojoxResizeHandle"><div></div></div>', |
| 124 |
|
| 125 |
postCreate: function(){ |
| 126 |
|
| 127 |
|
| 128 |
this.connect(this.resizeHandle, touch.press, "_beginSizing"); |
| 129 |
if(!this.activeResize){ |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
this._resizeHelper = manager.byId('dojoxGlobalResizeHelper'); |
| 135 |
if(!this._resizeHelper){ |
| 136 |
this._resizeHelper = new _ResizeHelper({ |
| 137 |
id: 'dojoxGlobalResizeHelper' |
| 138 |
}).placeAt(windowBase.body()); |
| 139 |
domClass.add(this._resizeHelper.domNode, this.activeResizeClass); |
| 140 |
} |
| 141 |
}else{ this.animateSizing = false; } |
| 142 |
|
| 143 |
if(!this.minSize){ |
| 144 |
this.minSize = { w: this.minWidth, h: this.minHeight }; |
| 145 |
} |
| 146 |
|
| 147 |
if(this.constrainMax){ |
| 148 |
this.maxSize = { w: this.maxWidth, h: this.maxHeight }; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
this._resizeX = this._resizeY = false; |
| 153 |
var addClass = lang.partial(domClass.add, this.resizeHandle); |
| 154 |
switch(this.resizeAxis.toLowerCase()){ |
| 155 |
case "xy" : |
| 156 |
this._resizeX = this._resizeY = true; |
| 157 |
|
| 158 |
|
| 159 |
addClass("dojoxResizeNW"); |
| 160 |
break; |
| 161 |
case "x" : |
| 162 |
this._resizeX = true; |
| 163 |
addClass("dojoxResizeW"); |
| 164 |
break; |
| 165 |
case "y" : |
| 166 |
this._resizeY = true; |
| 167 |
addClass("dojoxResizeN"); |
| 168 |
break; |
| 169 |
} |
| 170 |
}, |
| 171 |
|
| 172 |
_beginSizing: function( e){ |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
if(this._isSizing){ return; } |
| 177 |
|
| 178 |
connect.publish(this.startTopic, [ this ]); |
| 179 |
this.targetWidget = manager.byId(this.targetId); |
| 180 |
|
| 181 |
this.targetDomNode = this.targetWidget ? this.targetWidget.domNode : domUtil.byId(this.targetId); |
| 182 |
if(this.targetContainer){ this.targetDomNode = this.targetContainer; } |
| 183 |
if(!this.targetDomNode){ return; } |
| 184 |
|
| 185 |
if(!this.activeResize){ |
| 186 |
var c = domGeometry.position(this.targetDomNode, true); |
| 187 |
this._resizeHelper.resize({l: c.x, t: c.y, w: c.w, h: c.h}); |
| 188 |
this._resizeHelper.show(); |
| 189 |
if(!this.isLeftToRight()){ |
| 190 |
this._resizeHelper.startPosition = {l: c.x, t: c.y}; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
this._isSizing = true; |
| 195 |
this.startPoint = { x:e.clientX, y:e.clientY }; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
var style = domStyle.getComputedStyle(this.targetDomNode), |
| 200 |
borderModel = domGeometry.boxModel==='border-model', |
| 201 |
padborder = borderModel?{w:0,h:0}:domGeometry.getPadBorderExtents(this.targetDomNode, style), |
| 202 |
margin = domGeometry.getMarginExtents(this.targetDomNode, style); |
| 203 |
this.startSize = { |
| 204 |
w: domStyle.get(this.targetDomNode, 'width', style), |
| 205 |
h: domStyle.get(this.targetDomNode, 'height', style), |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
pbw: padborder.w, pbh: padborder.h, |
| 210 |
mw: margin.w, mh: margin.h}; |
| 211 |
if(!this.isLeftToRight() && domStyle.get(this.targetDomNode, "position") == "absolute"){ |
| 212 |
var p = domGeometry.position(this.targetDomNode, true); |
| 213 |
this.startPosition = {l: p.x, t: p.y}; |
| 214 |
} |
| 215 |
|
| 216 |
this._pconnects = [ |
| 217 |
connect.connect(windowBase.doc, touch.move, this,"_updateSizing"), |
| 218 |
connect.connect(windowBase.doc, touch.release, this, "_endSizing") |
| 219 |
]; |
| 220 |
|
| 221 |
eventUtil.stop(e); |
| 222 |
}, |
| 223 |
|
| 224 |
_updateSizing: function( e){ |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
if(this.activeResize){ |
| 230 |
this._changeSizing(e); |
| 231 |
}else{ |
| 232 |
var tmp = this._getNewCoords(e, 'border', this._resizeHelper.startPosition); |
| 233 |
if(tmp === false){ return; } |
| 234 |
this._resizeHelper.resize(tmp); |
| 235 |
} |
| 236 |
e.preventDefault(); |
| 237 |
}, |
| 238 |
|
| 239 |
_getNewCoords: function( e, box, startPosition){ |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
try{ |
| 244 |
if(!e.clientX || !e.clientY){ return false; } |
| 245 |
}catch(err){ |
| 246 |
|
| 247 |
return false; |
| 248 |
} |
| 249 |
this._activeResizeLastEvent = e; |
| 250 |
|
| 251 |
var dx = (this.isLeftToRight()?1:-1) * (this.startPoint.x - e.clientX), |
| 252 |
dy = this.startPoint.y - e.clientY, |
| 253 |
newW = this.startSize.w - (this._resizeX ? dx : 0), |
| 254 |
newH = this.startSize.h - (this._resizeY ? dy : 0), |
| 255 |
r = this._checkConstraints(newW, newH) |
| 256 |
; |
| 257 |
|
| 258 |
startPosition = (startPosition || this.startPosition); |
| 259 |
if(startPosition && this._resizeX){ |
| 260 |
|
| 261 |
r.l = startPosition.l + dx; |
| 262 |
if(r.w != newW){ |
| 263 |
r.l += (newW - r.w); |
| 264 |
} |
| 265 |
r.t = startPosition.t; |
| 266 |
} |
| 267 |
|
| 268 |
switch(box){ |
| 269 |
case 'margin': |
| 270 |
r.w += this.startSize.mw; |
| 271 |
r.h += this.startSize.mh; |
| 272 |
|
| 273 |
case "border": |
| 274 |
r.w += this.startSize.pbw; |
| 275 |
r.h += this.startSize.pbh; |
| 276 |
break; |
| 277 |
|
| 278 |
} |
| 279 |
|
| 280 |
return r; |
| 281 |
}, |
| 282 |
|
| 283 |
_checkConstraints: function(newW, newH){ |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
if(this.minSize){ |
| 289 |
var tm = this.minSize; |
| 290 |
if(newW < tm.w){ |
| 291 |
newW = tm.w; |
| 292 |
} |
| 293 |
if(newH < tm.h){ |
| 294 |
newH = tm.h; |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
if(this.constrainMax && this.maxSize){ |
| 300 |
var ms = this.maxSize; |
| 301 |
if(newW > ms.w){ |
| 302 |
newW = ms.w; |
| 303 |
} |
| 304 |
if(newH > ms.h){ |
| 305 |
newH = ms.h; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
if(this.fixedAspect){ |
| 310 |
var w = this.startSize.w, h = this.startSize.h, |
| 311 |
delta = w * newH - h * newW; |
| 312 |
if(delta<0){ |
| 313 |
newW = newH * w / h; |
| 314 |
}else if(delta>0){ |
| 315 |
newH = newW * h / w; |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
return { w: newW, h: newH }; |
| 320 |
}, |
| 321 |
|
| 322 |
_changeSizing: function( e){ |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
var isWidget = this.targetWidget && lang.isFunction(this.targetWidget.resize), |
| 327 |
tmp = this._getNewCoords(e, isWidget && 'margin'); |
| 328 |
if(tmp === false){ return; } |
| 329 |
|
| 330 |
if(isWidget){ |
| 331 |
this.targetWidget.resize(tmp); |
| 332 |
}else{ |
| 333 |
if(this.animateSizing){ |
| 334 |
var anim = fxUtil[this.animateMethod]([ |
| 335 |
fxBase.animateProperty({ |
| 336 |
node: this.targetDomNode, |
| 337 |
properties: { |
| 338 |
width: { start: this.startSize.w, end: tmp.w } |
| 339 |
}, |
| 340 |
duration: this.animateDuration |
| 341 |
}), |
| 342 |
fxBase.animateProperty({ |
| 343 |
node: this.targetDomNode, |
| 344 |
properties: { |
| 345 |
height: { start: this.startSize.h, end: tmp.h } |
| 346 |
}, |
| 347 |
duration: this.animateDuration |
| 348 |
}) |
| 349 |
]); |
| 350 |
anim.play(); |
| 351 |
}else{ |
| 352 |
domStyle.set(this.targetDomNode,{ |
| 353 |
width: tmp.w + "px", |
| 354 |
height: tmp.h + "px" |
| 355 |
}); |
| 356 |
} |
| 357 |
} |
| 358 |
if(this.intermediateChanges){ |
| 359 |
this.onResize(e); |
| 360 |
} |
| 361 |
}, |
| 362 |
|
| 363 |
_endSizing: function( e){ |
| 364 |
|
| 365 |
|
| 366 |
arrayUtil.forEach(this._pconnects, connect.disconnect); |
| 367 |
var pub = lang.partial(connect.publish, this.endTopic, [ this ]); |
| 368 |
if(!this.activeResize){ |
| 369 |
this._resizeHelper.hide(); |
| 370 |
this._changeSizing(e); |
| 371 |
setTimeout(pub, this.animateDuration + 15); |
| 372 |
}else{ |
| 373 |
pub(); |
| 374 |
} |
| 375 |
this._isSizing = false; |
| 376 |
this.onResize(e); |
| 377 |
}, |
| 378 |
|
| 379 |
onResize: function(e){ |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
} |
| 385 |
|
| 386 |
}); |
| 387 |
|
| 388 |
return ResizeHandle; |
| 389 |
}); |