Skip to content

Commit

Permalink
Draggable: fix changing containment
Browse files Browse the repository at this point in the history
If containment was set such that relative_container is set by
_setContainment, and then containment changes to e.g. "document",
"window", or an array, relative_container would not be unset, causing
incorrect containment of the draggable.

Add a unittest to check that containment with an array works after
previously being set to "parent".

Fixes #9733
Closes jquerygh-1176
  • Loading branch information
bhiggins authored and tjvantoll committed Jan 20, 2014
1 parent 998d04d commit 0bb807b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/unit/draggable/draggable_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,20 @@ test( "containment, account for border", function() {
});

test( "containment, default, switching after initialization", function() {
expect( 6 );
expect( 8 );

var element = $( "#draggable1" ).draggable({ containment: false, scroll: false });
var element = $( "#draggable1" ).draggable({ containment: false, scroll: false }),
po = element.parent().offset(),
containment = [ po.left - 100, po.top - 100, po.left + 500, po.top + 500 ];

TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100, "containment: default" );

element.draggable( "option", "containment", "parent" ).css({ top: 0, left: 0 });
TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0, "containment: parent as option" );

element.draggable( "option", "containment", containment ).css({ top: 0, left: 0 });
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100, "containment: array as option" );

element.draggable( "option", "containment", false );
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100, "containment: false as option" );
});
Expand Down
2 changes: 2 additions & 0 deletions ui/jquery.ui.draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ $.widget("ui.draggable", $.ui.mouse, {
o = this.options,
document = this.document[ 0 ];

this.relative_container = null;

if ( !o.containment ) {
this.containment = null;
return;
Expand Down

0 comments on commit 0bb807b

Please sign in to comment.