From 1660c761e7fe3e790ec4dcb3a356a78ac2a1c7ed Mon Sep 17 00:00:00 2001 From: Christian Klammer Date: Thu, 16 May 2013 21:26:13 +1000 Subject: [PATCH] Resizable: Fixed sign error on offset calculation. Fixes #9307 - Resizable: Erratic behavior of contained elements within scrollable grandparents (cherry picked from commit 6df5c1a4ae738e591694e0fe2fa3bbb8b05f6b0a) --- tests/unit/resizable/resizable_events.js | 47 ++++++++++++++++++++++++ ui/jquery.ui.resizable.js | 4 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/unit/resizable/resizable_events.js b/tests/unit/resizable/resizable_events.js index ac222ec106d..18e25bfdf18 100644 --- a/tests/unit/resizable/resizable_events.js +++ b/tests/unit/resizable/resizable_events.js @@ -170,4 +170,51 @@ test("stop", function() { }); +test( "resize (containment) works with parent with negative offset", function() { + + expect( 1 ); + + var widthBefore, widthAfter, + handle = ".ui-resizable-e", + target = $( "#resizable1" ), + absoluteContainer = target.wrap( "
" ).parent(), + fixedContainer = absoluteContainer.wrap( "
" ).parent(), + increaseWidthBy = 50; + + // position fixed container in window top left + fixedContainer.css({ + width: 400, + height: 100, + position: "fixed", + top: 0, + left: 0 + }); + + // position absolute container within fixed on slightly outside window + absoluteContainer.css({ + width: 400, + height: 100, + position: "absolute", + top: 0, + left: -50 + }); + + // set up resizable to be contained within absolute container + target.resizable({ + handles: "all", + containment: "parent" + }).css({ + width: 300 + }); + + widthBefore = target.width(); + + TestHelpers.resizable.drag( handle, increaseWidthBy, 0 ); + + widthAfter = target.width(); + + equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" ); + +}); + })(jQuery); diff --git a/ui/jquery.ui.resizable.js b/ui/jquery.ui.resizable.js index 2468dcaa65f..ac1fceaec5d 100644 --- a/ui/jquery.ui.resizable.js +++ b/ui/jquery.ui.resizable.js @@ -774,8 +774,8 @@ $.ui.plugin.add("resizable", "containment", { isParent = that.containerElement.get(0) === that.element.parent().get(0); isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position")); - if(isParent && isOffsetRelative) { - woset -= that.parentData.left; + if ( isParent && isOffsetRelative ) { + woset -= Math.abs( that.parentData.left ); } if (woset + that.size.width >= that.parentData.width) {