@@ -293,6 +293,8 @@ $.widget("ui.resizable", $.ui.mouse, {
293293 // Calculate the attrs that will be change
294294 var data = trigger . apply ( this , [ event , dx , dy ] ) , ie6 = $ . browser . msie && $ . browser . version < 7 , csdif = this . sizeDiff ;
295295
296+ // Put this in the mouseDrag handler since the user can start pressing shift while resizing
297+ this . _updateVirtualBoundaries ( event . shiftKey ) ;
296298 if ( this . _aspectRatio || event . shiftKey )
297299 data = this . _updateRatio ( data , event ) ;
298300
@@ -351,6 +353,32 @@ $.widget("ui.resizable", $.ui.mouse, {
351353
352354 } ,
353355
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+
354382 _updateCache : function ( data ) {
355383 var o = this . options ;
356384 this . offset = this . helper . offset ( ) ;
@@ -364,8 +392,8 @@ $.widget("ui.resizable", $.ui.mouse, {
364392
365393 var o = this . options , cpos = this . position , csize = this . size , a = this . axis ;
366394
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 ) ;
369397
370398 if ( a == 'sw' ) {
371399 data . left = cpos . left + ( csize . width - data . width ) ;
@@ -381,7 +409,7 @@ $.widget("ui.resizable", $.ui.mouse, {
381409
382410 _respectSize : function ( data , event ) {
383411
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 ,
385413 ismaxw = isNumber ( data . width ) && o . maxWidth && ( o . maxWidth < data . width ) , ismaxh = isNumber ( data . height ) && o . maxHeight && ( o . maxHeight < data . height ) ,
386414 isminw = isNumber ( data . width ) && o . minWidth && ( o . minWidth > data . width ) , isminh = isNumber ( data . height ) && o . minHeight && ( o . minHeight > data . height ) ;
387415
0 commit comments