@@ -769,25 +769,39 @@ $.ui.plugin.add("resizable", "grid", {
769
769
resize : function ( ) {
770
770
var that = $ ( this ) . data ( "resizable" ) , o = that . options , cs = that . size , os = that . originalSize , op = that . originalPosition , a = that . axis ;
771
771
o . grid = typeof o . grid == "number" ? [ o . grid , o . grid ] : o . grid ;
772
- var ox = Math . round ( ( cs . width - os . width ) / ( o . grid [ 0 ] || 1 ) ) * ( o . grid [ 0 ] || 1 ) , oy = Math . round ( ( cs . height - os . height ) / ( o . grid [ 1 ] || 1 ) ) * ( o . grid [ 1 ] || 1 ) ;
772
+ var gridX = ( o . grid [ 0 ] || 1 ) , gridY = ( o . grid [ 1 ] || 1 ) ,
773
+ ox = Math . round ( ( cs . width - os . width ) / gridX ) * gridX , oy = Math . round ( ( cs . height - os . height ) / gridY ) * gridY ,
774
+ newWidth = os . width + ox , newHeight = os . height + oy ,
775
+ isMaxWidth = o . maxWidth && ( o . maxWidth < newWidth ) , isMaxHeight = o . maxHeight && ( o . maxHeight < newHeight ) ,
776
+ isMinWidth = o . minWidth && ( o . minWidth > newWidth ) , isMinHeight = o . minHeight && ( o . minHeight > newHeight ) ;
777
+
778
+ if ( isMinWidth ) {
779
+ newWidth = newWidth + gridX ;
780
+ }
781
+ if ( isMinHeight ) {
782
+ newHeight = newHeight + gridY ;
783
+ }
784
+ if ( isMaxWidth ) {
785
+ newWidth = newWidth - gridX ;
786
+ }
787
+ if ( isMaxHeight ) {
788
+ newHeight = newHeight - gridY ;
789
+ }
773
790
774
791
if ( / ^ ( s e | s | e ) $ / . test ( a ) ) {
775
- that . size . width = os . width + ox ;
776
- that . size . height = os . height + oy ;
777
- }
778
- else if ( / ^ ( n e ) $ / . test ( a ) ) {
779
- that . size . width = os . width + ox ;
780
- that . size . height = os . height + oy ;
792
+ that . size . width = newWidth ;
793
+ that . size . height = newHeight ;
794
+ } else if ( / ^ ( n e ) $ / . test ( a ) ) {
795
+ that . size . width = newWidth ;
796
+ that . size . height = newHeight ;
781
797
that . position . top = op . top - oy ;
782
- }
783
- else if ( / ^ ( s w ) $ / . test ( a ) ) {
784
- that . size . width = os . width + ox ;
785
- that . size . height = os . height + oy ;
798
+ } else if ( / ^ ( s w ) $ / . test ( a ) ) {
799
+ that . size . width = newWidth ;
800
+ that . size . height = newHeight ;
786
801
that . position . left = op . left - ox ;
787
- }
788
- else {
789
- that . size . width = os . width + ox ;
790
- that . size . height = os . height + oy ;
802
+ } else {
803
+ that . size . width = newWidth ;
804
+ that . size . height = newHeight ;
791
805
that . position . top = op . top - oy ;
792
806
that . position . left = op . left - ox ;
793
807
}
0 commit comments