@@ -80,12 +80,18 @@ $.widget( "ui.resizable", $.ui.mouse, {
8080
8181 _hasScroll : function ( el , a ) {
8282
83- if ( $ ( el ) . css ( "overflow" ) === "hidden" ) {
83+ var scroll ,
84+ has = false ,
85+ overflow = $ ( el ) . css ( "overflow" ) ;
86+
87+ if ( overflow === "hidden" ) {
8488 return false ;
8589 }
90+ if ( overflow === "scroll" ) {
91+ return true ;
92+ }
8693
87- var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop" ,
88- has = false ;
94+ scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop" ;
8995
9096 if ( el [ scroll ] > 0 ) {
9197 return true ;
@@ -362,7 +368,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
362368
363369 _mouseStart : function ( event ) {
364370
365- var curleft , curtop , cursor ,
371+ var curleft , curtop , cursor , calculatedSize ,
366372 o = this . options ,
367373 el = this . element ;
368374
@@ -381,20 +387,24 @@ $.widget( "ui.resizable", $.ui.mouse, {
381387 this . offset = this . helper . offset ( ) ;
382388 this . position = { left : curleft , top : curtop } ;
383389
390+ if ( ! this . _helper ) {
391+ calculatedSize = this . _calculateAdjustedElementDimensions ( el ) ;
392+ }
393+
384394 this . size = this . _helper ? {
385395 width : this . helper . width ( ) ,
386396 height : this . helper . height ( )
387397 } : {
388- width : el . width ( ) ,
389- height : el . height ( )
398+ width : calculatedSize . width ,
399+ height : calculatedSize . height
390400 } ;
391401
392402 this . originalSize = this . _helper ? {
393403 width : el . outerWidth ( ) ,
394404 height : el . outerHeight ( )
395405 } : {
396- width : el . width ( ) ,
397- height : el . height ( )
406+ width : calculatedSize . width ,
407+ height : calculatedSize . height
398408 } ;
399409
400410 this . sizeDiff = {
@@ -690,6 +700,52 @@ $.widget( "ui.resizable", $.ui.mouse, {
690700 } ;
691701 } ,
692702
703+ _calculateAdjustedElementDimensions : function ( element ) {
704+ var elWidth , elHeight , paddingBorder ,
705+ ce = element . get ( 0 ) ;
706+
707+ if ( element . css ( "box-sizing" ) !== "content-box" ||
708+ ( ! this . _hasScroll ( ce ) && ! this . _hasScroll ( ce , "left" ) ) ) {
709+ return {
710+ height : parseFloat ( element . css ( "height" ) ) ,
711+ width : parseFloat ( element . css ( "width" ) )
712+ } ;
713+ }
714+
715+ // Check if CSS inline styles are set and use those (usually from previous resizes)
716+ elWidth = parseFloat ( ce . style . width ) ;
717+ elHeight = parseFloat ( ce . style . height ) ;
718+
719+ paddingBorder = this . _getPaddingPlusBorderDimensions ( element ) ;
720+ elWidth = isNaN ( elWidth ) ?
721+ this . _getElementTheoreticalSize ( element , paddingBorder , "width" ) :
722+ elWidth ;
723+ elHeight = isNaN ( elHeight ) ?
724+ this . _getElementTheoreticalSize ( element , paddingBorder , "height" ) :
725+ elHeight ;
726+
727+ return {
728+ height : elHeight ,
729+ width : elWidth
730+ } ;
731+ } ,
732+
733+ _getElementTheoreticalSize : function ( element , extraSize , dimension ) {
734+
735+ // offsetWidth/offsetHeight is a rounded sum of content, padding, scroll gutter, and border
736+ var size = Math . max ( 0 , Math . ceil (
737+ element . get ( 0 ) [ "offset" + dimension [ 0 ] . toUpperCase ( ) + dimension . slice ( 1 ) ] -
738+ extraSize [ dimension ] -
739+ 0.5
740+
741+ // If offsetWidth/offsetHeight is unknown, then we can't determine theoretical size.
742+ // Use an explicit zero to avoid NaN.
743+ // See https://github.com/jquery/jquery/issues/3964
744+ ) ) || 0 ;
745+
746+ return size ;
747+ } ,
748+
693749 _proportionallyResize : function ( ) {
694750
695751 if ( ! this . _proportionallyResizeElements . length ) {
@@ -1044,9 +1100,11 @@ $.ui.plugin.add( "resizable", "alsoResize", {
10441100 o = that . options ;
10451101
10461102 $ ( o . alsoResize ) . each ( function ( ) {
1047- var el = $ ( this ) ;
1103+ var el = $ ( this ) ,
1104+ elSize = that . _calculateAdjustedElementDimensions ( el ) ;
1105+
10481106 el . data ( "ui-resizable-alsoresize" , {
1049- width : parseFloat ( el . css ( " width" ) ) , height : parseFloat ( el . css ( " height" ) ) ,
1107+ width : elSize . width , height : elSize . height ,
10501108 left : parseFloat ( el . css ( "left" ) ) , top : parseFloat ( el . css ( "top" ) )
10511109 } ) ;
10521110 } ) ;
0 commit comments