diff options
author | Ben Higgins <ben@extrahop.com> | 2014-01-13 14:51:06 -0800 |
---|---|---|
committer | TJ VanToll <tj.vantoll@gmail.com> | 2014-01-20 13:08:12 -0500 |
commit | 0bb807bb42af87bf4c6dd4d71808b12c08d316e7 (patch) | |
tree | daa5c1e023248b819fd831884bfb1cb85816e091 | |
parent | 998d04d55d4d1da2a9e24eea285349d388a6d0fc (diff) | |
download | jquery-ui-0bb807bb42af87bf4c6dd4d71808b12c08d316e7.tar.gz jquery-ui-0bb807bb42af87bf4c6dd4d71808b12c08d316e7.zip |
Draggable: fix changing containment
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 gh-1176
-rw-r--r-- | tests/unit/draggable/draggable_options.js | 9 | ||||
-rw-r--r-- | ui/jquery.ui.draggable.js | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index f50359f99..0e728f8dc 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -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" ); }); diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 5cbe92fce..2de1d0162 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -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; |