@@ -293,6 +293,8 @@ $.widget("ui.resizable", $.ui.mouse, {
293
293
// Calculate the attrs that will be change
294
294
var data = trigger . apply ( this , [ event , dx , dy ] ) , ie6 = $ . browser . msie && $ . browser . version < 7 , csdif = this . sizeDiff ;
295
295
296
+ // Put this in the mouseDrag handler since the user can start pressing shift while resizing
297
+ this . _updateVirtualBoundaries ( event . shiftKey ) ;
296
298
if ( this . _aspectRatio || event . shiftKey )
297
299
data = this . _updateRatio ( data , event ) ;
298
300
@@ -351,6 +353,32 @@ $.widget("ui.resizable", $.ui.mouse, {
351
353
352
354
} ,
353
355
356
+ _updateVirtualBoundaries : function ( forceAspectRatio ) {
357
+ var o = this . options , pMinWidth , pMaxWidth , pMinHeight , pMaxHeight , b ;
358
+
359
+ b = {
360
+ minWidth : isNumber ( o . minWidth ) ? o . minWidth : 0 ,
361
+ maxWidth : isNumber ( o . maxWidth ) ? o . maxWidth : Infinity ,
362
+ minHeight : isNumber ( o . minHeight ) ? o . minHeight : 0 ,
363
+ maxHeight : isNumber ( o . maxHeight ) ? o . maxHeight : Infinity
364
+ } ;
365
+
366
+ if ( this . _aspectRatio || forceAspectRatio ) {
367
+ // We want to create an enclosing box whose aspect ration is the requested one
368
+ // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
369
+ pMinWidth = b . minHeight * this . aspectRatio ;
370
+ pMinHeight = b . minWidth / this . aspectRatio ;
371
+ pMaxWidth = b . maxHeight * this . aspectRatio ;
372
+ pMaxHeight = b . maxWidth / this . aspectRatio ;
373
+
374
+ if ( pMinWidth > b . minWidth ) b . minWidth = pMinWidth ;
375
+ if ( pMinHeight > b . minHeight ) b . minHeight = pMinHeight ;
376
+ if ( pMaxWidth < b . maxWidth ) b . maxWidth = pMaxWidth ;
377
+ if ( pMaxHeight < b . maxHeight ) b . maxHeight = pMaxHeight ;
378
+ }
379
+ this . _vBoundaries = b ;
380
+ } ,
381
+
354
382
_updateCache : function ( data ) {
355
383
var o = this . options ;
356
384
this . offset = this . helper . offset ( ) ;
@@ -364,8 +392,8 @@ $.widget("ui.resizable", $.ui.mouse, {
364
392
365
393
var o = this . options , cpos = this . position , csize = this . size , a = this . axis ;
366
394
367
- if ( data . height ) data . width = ( csize . height * this . aspectRatio ) ;
368
- else if ( data . width ) data . height = ( csize . width / this . aspectRatio ) ;
395
+ if ( isNumber ( data . height ) ) data . width = ( data . height * this . aspectRatio ) ;
396
+ else if ( isNumber ( data . width ) ) data . height = ( data . width / this . aspectRatio ) ;
369
397
370
398
if ( a == 'sw' ) {
371
399
data . left = cpos . left + ( csize . width - data . width ) ;
@@ -381,7 +409,7 @@ $.widget("ui.resizable", $.ui.mouse, {
381
409
382
410
_respectSize : function ( data , event ) {
383
411
384
- var el = this . helper , o = this . options , pRatio = this . _aspectRatio || event . shiftKey , a = this . axis ,
412
+ var el = this . helper , o = this . _vBoundaries , pRatio = this . _aspectRatio || event . shiftKey , a = this . axis ,
385
413
ismaxw = isNumber ( data . width ) && o . maxWidth && ( o . maxWidth < data . width ) , ismaxh = isNumber ( data . height ) && o . maxHeight && ( o . maxHeight < data . height ) ,
386
414
isminw = isNumber ( data . width ) && o . minWidth && ( o . minWidth > data . width ) , isminh = isNumber ( data . height ) && o . minHeight && ( o . minHeight > data . height ) ;
387
415
0 commit comments