From 2779212a0e6e34fdea3f0d442e4d92218ac943fa Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Mon, 4 Aug 2014 08:18:35 -0400 Subject: [PATCH] Resizable: Fix containment calculation with relative parent Remove an incorrect fix introduced in 47cd5b6f that causes width calculations to be incorrect once the correct fix was introduced in c03cb807 Fixes #10140 --- tests/unit/resizable/resizable_options.js | 16 +++++++++++++++- ui/resizable.js | 9 +-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index 34fef47f0..d0f9f5f05 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -155,7 +155,8 @@ test( "aspectRatio: Resizing can move objects", function() { }); test( "containment", function() { - expect( 6 ); + expect( 8 ); + var element = $( "#resizable1" ).resizable({ containment: "#container" }); @@ -180,6 +181,19 @@ test( "containment", function() { TestHelpers.resizable.drag( ".ui-resizable-s", 0, 300 ); equal( element.height(), 400, "element able to resize itself to max allowable height within container" ); + + // http://bugs.jqueryui.com/ticket/10140 - Resizable: Width calculation is wrong + // when containment element is "position: relative" + 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" ); }); test("grid", function() { diff --git a/ui/resizable.js b/ui/resizable.js index b2e3a6626..8c65a12c8 100644 --- a/ui/resizable.js +++ b/ui/resizable.js @@ -774,7 +774,7 @@ $.ui.plugin.add( "resizable", "containment", { }, resize: function( event ) { - var woset, hoset, isParent, isOffsetRelative, + var woset, hoset, that = $( this ).resizable( "instance" ), o = that.options, co = that.containerOffset, @@ -815,13 +815,6 @@ $.ui.plugin.add( "resizable", "containment", { 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 ); - 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 ) {