]> source.dussan.org Git - jquery-ui.git/commitdiff
Resizable: Fixed sign error on offset calculation. Fixes #9307 - Resizable: Erratic...
authorChristian Klammer <christian314159@gmail.com>
Thu, 16 May 2013 11:26:13 +0000 (21:26 +1000)
committerScott González <scott.gonzalez@gmail.com>
Tue, 26 Nov 2013 15:25:24 +0000 (10:25 -0500)
(cherry picked from commit 6df5c1a4ae738e591694e0fe2fa3bbb8b05f6b0a)

tests/unit/resizable/resizable_events.js
ui/jquery.ui.resizable.js

index ac222ec106d87c79102e5c8d1a6557698fb82baa..18e25bfdf18062f0ee7055010a0c5770014ba88f 100644 (file)
@@ -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( "<div />" ).parent(),
+               fixedContainer = absoluteContainer.wrap( "<div />" ).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);
index 2468dcaa65f9f141529410c38a388f8d64b76d10..ac1fceaec5df197f75515bbaacc3c13c6f3eaada 100644 (file)
@@ -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) {