Skip to content

Commit 48ea2aa

Browse files
committed
Draggable: Ensure overflow:visible containments are correctly measured
Fixes #7016
1 parent d10440f commit 48ea2aa

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

tests/unit/draggable/draggable_options.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,36 @@ test( "containment, account for border", function() {
374374
"The draggable should be to the right of its parent's right border" );
375375
});
376376

377+
// http://bugs.jqueryui.com/ticket/7016
378+
// draggable can be pulled out of containment in Chrome and IE8
379+
test( "containment, element cant be pulled out of container", function() {
380+
expect( 1 );
381+
382+
var offsetBefore,
383+
parent = $( "<div>").css({ width: 200, height: 200 }).appendTo( "#qunit-fixture" ),
384+
element = $( "#draggable1" ).appendTo( parent );
385+
386+
element
387+
.css({
388+
height: "5px",
389+
width: "5px"
390+
})
391+
.draggable({ containment: "parent" })
392+
.simulate( "drag", {
393+
dx: 200,
394+
dy: 200
395+
});
396+
397+
offsetBefore = element.offset();
398+
399+
element.simulate( "drag", {
400+
dx: 200,
401+
dy: 200
402+
});
403+
404+
deepEqual( element.offset(), offsetBefore, "The draggable should not move past bottom right edge" );
405+
});
406+
377407
test( "containment, default, switching after initialization", function() {
378408
expect( 8 );
379409

ui/draggable.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ $.widget("ui.draggable", $.ui.mouse, {
439439

440440
_setContainment: function() {
441441

442-
var over, c, ce,
442+
var isUserScrollable, c, ce,
443443
o = this.options,
444444
document = this.document[ 0 ];
445445

@@ -486,13 +486,23 @@ $.widget("ui.draggable", $.ui.mouse, {
486486
return;
487487
}
488488

489-
over = c.css( "overflow" ) !== "hidden";
489+
isUserScrollable = /(scroll|auto)/.test( c.css( "overflow" ) );
490490

491491
this.containment = [
492492
( parseInt( c.css( "borderLeftWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingLeft" ), 10 ) || 0 ),
493493
( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingTop" ), 10 ) || 0 ),
494-
( over ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) - ( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) - ( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) - this.helperProportions.width - this.margins.left - this.margins.right,
495-
( over ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) - ( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) - ( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) - this.helperProportions.height - this.margins.top - this.margins.bottom
494+
( isUserScrollable ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -
495+
( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) -
496+
( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) -
497+
this.helperProportions.width -
498+
this.margins.left -
499+
this.margins.right,
500+
( isUserScrollable ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -
501+
( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) -
502+
( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) -
503+
this.helperProportions.height -
504+
this.margins.top -
505+
this.margins.bottom
496506
];
497507
this.relativeContainer = c;
498508
},

0 commit comments

Comments
 (0)