@@ -555,32 +555,56 @@ $.widget("ui.resizable", $.ui.mouse, {
555
555
return data ;
556
556
} ,
557
557
558
+ _getPaddingPlusBorderDimensions : function ( element ) {
559
+ var i = 0 ,
560
+ widths = [ ] ,
561
+ borders = [
562
+ element . css ( "borderTopWidth" ) ,
563
+ element . css ( "borderRightWidth" ) ,
564
+ element . css ( "borderBottomWidth" ) ,
565
+ element . css ( "borderLeftWidth" )
566
+ ] ,
567
+ paddings = [
568
+ element . css ( "paddingTop" ) ,
569
+ element . css ( "paddingRight" ) ,
570
+ element . css ( "paddingBottom" ) ,
571
+ element . css ( "paddingLeft" )
572
+ ] ;
573
+
574
+ for ( ; i < 4 ; i ++ ) {
575
+ widths [ i ] = ( parseInt ( borders [ i ] , 10 ) || 0 ) ;
576
+ widths [ i ] += ( parseInt ( paddings [ i ] , 10 ) || 0 ) ;
577
+ }
578
+
579
+ return {
580
+ height : widths [ 0 ] + widths [ 2 ] ,
581
+ width : widths [ 1 ] + widths [ 3 ]
582
+ } ;
583
+ } ,
584
+
558
585
_proportionallyResize : function ( ) {
559
586
560
587
if ( ! this . _proportionallyResizeElements . length ) {
561
588
return ;
562
589
}
563
590
564
- var i , j , borders , paddings , prel ,
591
+ var prel ,
592
+ i = 0 ,
565
593
element = this . helper || this . element ;
566
594
567
- for ( i = 0 ; i < this . _proportionallyResizeElements . length ; i ++ ) {
595
+ for ( ; i < this . _proportionallyResizeElements . length ; i ++ ) {
568
596
569
597
prel = this . _proportionallyResizeElements [ i ] ;
570
598
571
- if ( ! this . borderDif ) {
572
- this . borderDif = [ ] ;
573
- borders = [ prel . css ( "borderTopWidth" ) , prel . css ( "borderRightWidth" ) , prel . css ( "borderBottomWidth" ) , prel . css ( "borderLeftWidth" ) ] ;
574
- paddings = [ prel . css ( "paddingTop" ) , prel . css ( "paddingRight" ) , prel . css ( "paddingBottom" ) , prel . css ( "paddingLeft" ) ] ;
575
-
576
- for ( j = 0 ; j < borders . length ; j ++ ) {
577
- this . borderDif [ j ] = ( parseInt ( borders [ j ] , 10 ) || 0 ) + ( parseInt ( paddings [ j ] , 10 ) || 0 ) ;
578
- }
599
+ // TODO: Seems like a bug to cache this.outerDimensions
600
+ // considering that we are in a loop.
601
+ if ( ! this . outerDimensions ) {
602
+ this . outerDimensions = this . _getPaddingPlusBorderDimensions ( prel ) ;
579
603
}
580
604
581
605
prel . css ( {
582
- height : ( element . height ( ) - this . borderDif [ 0 ] - this . borderDif [ 2 ] ) || 0 ,
583
- width : ( element . width ( ) - this . borderDif [ 1 ] - this . borderDif [ 3 ] ) || 0
606
+ height : ( element . height ( ) - this . outerDimensions . height ) || 0 ,
607
+ width : ( element . width ( ) - this . outerDimensions . width ) || 0
584
608
} ) ;
585
609
586
610
}
@@ -972,7 +996,8 @@ $.ui.plugin.add("resizable", "ghost", {
972
996
$ . ui . plugin . add ( "resizable" , "grid" , {
973
997
974
998
resize : function ( ) {
975
- var that = $ ( this ) . resizable ( "instance" ) ,
999
+ var outerDimensions ,
1000
+ that = $ ( this ) . resizable ( "instance" ) ,
976
1001
o = that . options ,
977
1002
cs = that . size ,
978
1003
os = that . originalSize ,
@@ -993,16 +1018,16 @@ $.ui.plugin.add("resizable", "grid", {
993
1018
o . grid = grid ;
994
1019
995
1020
if ( isMinWidth ) {
996
- newWidth = newWidth + gridX ;
1021
+ newWidth += gridX ;
997
1022
}
998
1023
if ( isMinHeight ) {
999
- newHeight = newHeight + gridY ;
1024
+ newHeight += gridY ;
1000
1025
}
1001
1026
if ( isMaxWidth ) {
1002
- newWidth = newWidth - gridX ;
1027
+ newWidth -= gridX ;
1003
1028
}
1004
1029
if ( isMaxHeight ) {
1005
- newHeight = newHeight - gridY ;
1030
+ newHeight -= gridY ;
1006
1031
}
1007
1032
1008
1033
if ( / ^ ( s e | s | e ) $ / . test ( a ) ) {
@@ -1017,19 +1042,25 @@ $.ui.plugin.add("resizable", "grid", {
1017
1042
that . size . height = newHeight ;
1018
1043
that . position . left = op . left - ox ;
1019
1044
} else {
1045
+ if ( newHeight - gridY <= 0 || newWidth - gridX <= 0 ) {
1046
+ outerDimensions = that . _getPaddingPlusBorderDimensions ( this ) ;
1047
+ }
1048
+
1020
1049
if ( newHeight - gridY > 0 ) {
1021
1050
that . size . height = newHeight ;
1022
1051
that . position . top = op . top - oy ;
1023
1052
} else {
1024
- that . size . height = gridY ;
1025
- that . position . top = op . top + os . height - gridY ;
1053
+ newHeight = gridY - outerDimensions . height ;
1054
+ that . size . height = newHeight ;
1055
+ that . position . top = op . top + os . height - newHeight ;
1026
1056
}
1027
1057
if ( newWidth - gridX > 0 ) {
1028
1058
that . size . width = newWidth ;
1029
1059
that . position . left = op . left - ox ;
1030
1060
} else {
1031
- that . size . width = gridX ;
1032
- that . position . left = op . left + os . width - gridX ;
1061
+ newWidth = gridY - outerDimensions . height ;
1062
+ that . size . width = newWidth ;
1063
+ that . position . left = op . left + os . width - newWidth ;
1033
1064
}
1034
1065
}
1035
1066
}
0 commit comments