Skip to content

Commit 6358695

Browse files
committed
Draggable: Fix border containment. Fixed #5569 - Draggable: Containment incorrectly calculates padding and border
1 parent 5b2da7c commit 6358695

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

tests/unit/draggable/draggable_options.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,37 @@ test( "{ containment: 'parent' }, absolute", function() {
346346
deepEqual( offsetAfter, expected, "compare offset to parent" );
347347
});
348348

349+
test( "containment, account for border", function() {
350+
expect( 2 );
351+
352+
var el = $("#draggable1").appendTo("#main"),
353+
parent = el.parent().css({
354+
height: "100px",
355+
width: "100px",
356+
borderStyle: "solid",
357+
borderWidth: "5px 10px 15px 20px"
358+
}),
359+
parentBottom = parent.offset().top + parent.outerHeight(),
360+
parentRight = parent.offset().left + parent.outerWidth(),
361+
parentBorderBottom = TestHelpers.draggable.border( parent, "bottom" ),
362+
parentBorderRight = TestHelpers.draggable.border( parent, "right" );
363+
364+
el.css({
365+
height: "5px",
366+
width: "5px"
367+
}).draggable({ containment: "parent" });
368+
369+
el.simulate( "drag", {
370+
dx: 100,
371+
dy: 100
372+
});
373+
374+
equal( el.offset().top, parentBottom - parentBorderBottom - el.height(),
375+
"The draggable should be on top of its parent's bottom border" );
376+
equal( el.offset().left, parentRight - parentBorderRight - el.width(),
377+
"The draggable should be to the right of its parent's right border" );
378+
});
379+
349380
test( "containment, default, switching after initialization", function() {
350381
expect( 2 );
351382

ui/jquery.ui.draggable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ $.widget("ui.draggable", $.ui.mouse, {
421421
this.containment = [
422422
(parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
423423
(parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
424-
(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
425-
(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
424+
(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderRightWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
425+
(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderBottomWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
426426
];
427427
this.relative_container = c;
428428

0 commit comments

Comments
 (0)