Skip to content

Commit a90f83a

Browse files
committed
Changed implementation to avoid getBoundingClientRect().
1 parent 673b069 commit a90f83a

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

ui/widgets/resizable.js

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ $.widget( "ui.resizable", $.ui.mouse, {
8080

8181
_hasScroll: function( el, a ) {
8282

83-
if ( $( el ).css( "overflow" ) === "hidden" ) {
83+
var overflow = $( el ).css( "overflow" );
84+
if ( overflow === "hidden" ) {
8485
return false;
8586
}
87+
if ( overflow === "scroll" ) {
88+
return true;
89+
}
8690

8791
var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
8892
has = false;
@@ -381,15 +385,26 @@ $.widget( "ui.resizable", $.ui.mouse, {
381385
this.offset = this.helper.offset();
382386
this.position = { left: curleft, top: curtop };
383387

388+
var calculatedSize = undefined;
389+
if ( !this._helper ) {
390+
calculatedSize = this._calculateAdjustedElementDimensions( el );
391+
}
392+
384393
this.size = this._helper ? {
385394
width: this.helper.width(),
386395
height: this.helper.height()
387-
} : this._calculateAdjustedElementDimensions( el );
396+
} : {
397+
width: calculatedSize.width,
398+
height: calculatedSize.height
399+
};
388400

389401
this.originalSize = this._helper ? {
390402
width: el.outerWidth(),
391403
height: el.outerHeight()
392-
} : this._calculateAdjustedElementDimensions( el );
404+
} : {
405+
width: calculatedSize.width,
406+
height: calculatedSize.height
407+
};
393408

394409
this.sizeDiff = {
395410
width: el.outerWidth() - el.width(),
@@ -685,20 +700,44 @@ $.widget( "ui.resizable", $.ui.mouse, {
685700
},
686701

687702
_calculateAdjustedElementDimensions: function( element ) {
688-
if ( !( /content-box/ ).test( element.css( "box-sizing" ) ) ) {
689-
return {
690-
height: parseFloat( element.css( "height" ) ),
691-
width: parseFloat( element.css( "width" ) )
692-
};
703+
var ce = element.get( 0 );
704+
705+
if ( element.css( "box-sizing" ) !== "content-box" ||
706+
( !this._hasScroll( ce ) && !this._hasScroll( ce, "left" ) ) ) {
707+
return {
708+
height: parseFloat( element.css( "height" ) ),
709+
width: parseFloat( element.css( "width" ) )
710+
};
711+
}
712+
713+
// Check if CSS inline styles are set and use those (usually from previous resizes)
714+
var elWidth = ce.style.width === "" ? "" : parseFloat( ce.style.width );
715+
var elHeight = ce.style.height === "" ? "" : parseFloat( ce.style.height );
716+
717+
if ( elWidth === "" ) {
718+
elWidth = this._getElementSizeWithoutOverflow( element, "width" );
719+
}
720+
if ( elHeight === "" ) {
721+
elHeight = this._getElementSizeWithoutOverflow( element, "height" );
693722
}
694723

695-
var outerDimensions = this._getPaddingPlusBorderDimensions( element );
696724
return {
697-
height: element[ 0 ].getBoundingClientRect().height - outerDimensions.height,
698-
width: element[ 0 ].getBoundingClientRect().width - outerDimensions.width
725+
height: elHeight,
726+
width: elWidth
699727
};
700728
},
701729

730+
_getElementSizeWithoutOverflow: function( element, sizeProperty ) {
731+
var overflowProperty = sizeProperty === "width" ? "overflow-y" : "overflow-x";
732+
733+
var origOverflow = element.css( overflowProperty );
734+
element.css( overflowProperty, "hidden" );
735+
var elSize = parseFloat( element.css( sizeProperty ) );
736+
element.css( overflowProperty, origOverflow );
737+
738+
return elSize;
739+
},
740+
702741
_proportionallyResize: function() {
703742

704743
if ( !this._proportionallyResizeElements.length ) {

0 commit comments

Comments
 (0)