Skip to content

Commit c03cb80

Browse files
dekajpmikesherov
authored andcommitted
Resizable: containment now works with non - immediate children
Fixes #7485 Closes jquerygh-1130
1 parent 38c6cf1 commit c03cb80

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

tests/unit/resizable/resizable.html

+22
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@
4444
height: 100px;
4545
width: 100px;
4646
}
47+
#container2 {
48+
position: relative;
49+
width: 400px;
50+
height: 400px;
51+
margin: 30px 0 0 30px;
52+
}
53+
#parent {
54+
position: relative;
55+
width: 300px;
56+
height: 300px;
57+
}
58+
#child {
59+
position: relative;
60+
width: 100px;
61+
height: 100px;
62+
}
4763
</style>
4864
</head>
4965
<body>
@@ -58,6 +74,12 @@ <h2 id="qunit-userAgent"></h2>
5874
<div id="container">
5975
<div id="resizable1">I'm a resizable.</div>
6076
</div>
77+
78+
<div id="container2">
79+
<div id="parent">
80+
<div id="child">I'm a resizable.</div>
81+
</div>
82+
</div>
6183
<img src="images/test.jpg" id="resizable2" alt="solid gray">
6284

6385
</div>

tests/unit/resizable/resizable_options.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test("aspectRatio: 'preserve' (ne)", function() {
124124
});
125125

126126
test( "containment", function() {
127-
expect( 4 );
127+
expect( 6 );
128128
var element = $( "#resizable1" ).resizable({
129129
containment: "#container"
130130
});
@@ -136,6 +136,19 @@ test( "containment", function() {
136136
TestHelpers.resizable.drag( ".ui-resizable-se", 400, 400 );
137137
equal( element.width(), 300, "constrained width at containment edge" );
138138
equal( element.height(), 200, "constrained height at containment edge" );
139+
140+
// http://bugs.jqueryui.com/ticket/7485 - Resizable: Containment calculation is wrong
141+
// when containment element is not the immediate parent
142+
element = $( "#child" ).resizable({
143+
containment: "#container2",
144+
handles: "all"
145+
});
146+
147+
TestHelpers.resizable.drag( ".ui-resizable-e", 300, 0 );
148+
equal( element.width(), 400, "element able to resize itself to max allowable width within container" );
149+
150+
TestHelpers.resizable.drag( ".ui-resizable-s", 0, 300 );
151+
equal( element.height(), 400, "element able to resize itself to max allowable height within container" );
139152
});
140153

141154
test("grid", function() {

ui/jquery.ui.resizable.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ $.ui.plugin.add("resizable", "containment", {
792792
that.offset.left = that.parentData.left+that.position.left;
793793
that.offset.top = that.parentData.top+that.position.top;
794794

795-
woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width );
796-
hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
795+
woset = Math.abs( ( that._helper ? that.offset.left - cop.left : ( that.offset.left - co.left ) ) + that.sizeDiff.width );
796+
hoset = Math.abs( ( that._helper ? that.offset.top - cop.top : ( that.offset.top - co.top ) ) + that.sizeDiff.height );
797797

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

0 commit comments

Comments
 (0)