Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Resizable: containment now works with non - immediate children
Fixes #7485
Closes gh-1130
  • Loading branch information
dekajp authored and mikesherov committed Dec 15, 2013
1 parent 38c6cf1 commit c03cb80
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
22 changes: 22 additions & 0 deletions tests/unit/resizable/resizable.html
Expand Up @@ -44,6 +44,22 @@
height: 100px;
width: 100px;
}
#container2 {
position: relative;
width: 400px;
height: 400px;
margin: 30px 0 0 30px;
}
#parent {
position: relative;
width: 300px;
height: 300px;
}
#child {
position: relative;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
Expand All @@ -58,6 +74,12 @@ <h2 id="qunit-userAgent"></h2>
<div id="container">
<div id="resizable1">I'm a resizable.</div>
</div>

<div id="container2">
<div id="parent">
<div id="child">I'm a resizable.</div>
</div>
</div>
<img src="images/test.jpg" id="resizable2" alt="solid gray">

</div>
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/resizable/resizable_options.js
Expand Up @@ -124,7 +124,7 @@ test("aspectRatio: 'preserve' (ne)", function() {
});

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

// http://bugs.jqueryui.com/ticket/7485 - Resizable: Containment calculation is wrong
// when containment element is not the immediate parent
element = $( "#child" ).resizable({
containment: "#container2",
handles: "all"
});

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

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

test("grid", function() {
Expand Down
4 changes: 2 additions & 2 deletions ui/jquery.ui.resizable.js
Expand Up @@ -792,8 +792,8 @@ $.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 - cop.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 );
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"));
Expand Down

0 comments on commit c03cb80

Please sign in to comment.