Skip to content

Resizable : Width calculation is wrong #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/unit/resizable/resizable_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test( "aspectRatio: Resizing can move objects", function() {
});

test( "containment", function() {
expect( 6 );
expect( 8 );
var element = $( "#resizable1" ).resizable({
containment: "#container"
});
Expand All @@ -168,6 +168,19 @@ test( "containment", function() {
equal( element.width(), 300, "constrained width at containment edge" );
equal( element.height(), 200, "constrained height at containment edge" );

// http://bugs.jqueryui.com/ticket/10140 - Resizable: Width calculation is wrong when containment element is "position: relative"
// when containment element is immediate parent
element = $( "#child" ).resizable({
containment: "parent",
handles: "all"
});

TestHelpers.resizable.drag( ".ui-resizable-e", 300, 0 );
equal( element.width(), 300, "element able to resize itself to max allowable width within container" );

TestHelpers.resizable.drag( ".ui-resizable-s", 0, 300 );
equal( element.height(), 300, "element able to resize itself to max allowable height within container" );

// http://bugs.jqueryui.com/ticket/7485 - Resizable: Containment calculation is wrong
// when containment element is not the immediate parent
element = $( "#child" ).resizable({
Expand Down
11 changes: 5 additions & 6 deletions ui/resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,16 +800,15 @@ $.ui.plugin.add( "resizable", "containment", {
that.offset.left = that.parentData.left + that.position.left;
that.offset.top = that.parentData.top + that.position.top;

woset = Math.abs( ( that._helper ? that.offset.left - cop.left : ( that.offset.left - co.left ) ) + that.sizeDiff.width );
hoset = Math.abs( ( that._helper ? that.offset.top - cop.top : ( that.offset.top - co.top ) ) + that.sizeDiff.height );
woset = Math.abs( ( that._helper ? that.offset.left - cop.left :
( that.offset.left - co.left ) ) + that.sizeDiff.width + (
( isParent && isOffsetRelative ) ? Math.abs( that.parentData.left ) : 0 ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be a valid fix since isParent and isOffsetRelative are always undefined at this point.

hoset = Math.abs( ( that._helper ? that.offset.top - cop.top :
( that.offset.top - co.top ) ) + that.sizeDiff.height );

isParent = that.containerElement.get( 0 ) === that.element.parent().get( 0 );
isOffsetRelative = /relative|absolute/.test( that.containerElement.css( "position" ) );

if ( isParent && isOffsetRelative ) {
woset -= Math.abs( that.parentData.left );
}

if ( woset + that.size.width >= that.parentData.width ) {
that.size.width = that.parentData.width - woset;
if ( pRatio ) {
Expand Down