Draggable: Changed the way handle and exclude is detected

This commit is contained in:
Dave Stein 2013-02-24 19:48:08 -05:00
parent 78500111da
commit 04a50ff49f
2 changed files with 54 additions and 2 deletions

View File

@ -219,6 +219,32 @@ test( "{ cancel: ? }, unexpected", function() {
});
});
test("{ cancel: Selectors }, matching parent selector", function() {
expect( 5 );
var el = $("#draggable2").draggable({ cancel: "span a" });
$("#qunit-fixture").append( "<span id='wrapping'><a></a></span>" );
el.find( "span" ).append( "<a>" );
$("#wrapping a").append( el );
TestHelpers.draggable.testDrag(el, "#draggable2 span", 50, 50, 50, 50, "drag span child");
TestHelpers.draggable.shouldNotMove( $("#draggable2 span a") );
TestHelpers.draggable.shouldNotMove( $("#wrapping a") );
$("#draggable2").draggable( "option", "cancel", "span > a" );
$("#draggable2").find( "a" ).append( "<a>" );
TestHelpers.draggable.testDrag(el, $("#draggable2 span a").last(), 50, 50, 50, 50, "drag span child");
TestHelpers.draggable.shouldNotMove( $("#draggable2 span a").first() );
});
test("cancel, default, switching after initialization", function() {
expect( 3 );
@ -556,6 +582,30 @@ test("{ handle: 'span' }", function() {
TestHelpers.draggable.shouldNotMove(el, "drag element");
});
test("{ handle: Selectors }, matching parent selector", function() {
expect( 4 );
var el = $("#draggable2").draggable({ handle: "span a" });
$("#qunit-fixture").append( "<span id='wrapping'><a></a></span>" );
el.find( "span" ).append( "<a>" );
$("#wrapping a").append( el );
TestHelpers.draggable.testDrag(el, "#draggable2 span a", 50, 50, 50, 50, "drag span child");
TestHelpers.draggable.shouldNotMove( $("#wrapping a") );
$("#draggable2").draggable( "option", "handle", "span > a" );
$("#draggable2").find( "a" ).append( "<a>" );
TestHelpers.draggable.testDrag(el, $("#draggable2 span a").first(), 50, 50, 50, 50, "drag span child");
TestHelpers.draggable.shouldNotMove( $("#draggable2 span a").last() );
});
test("handle, default, switching after initialization", function() {
expect( 6 );

View File

@ -74,8 +74,10 @@ $.widget( "ui.draggable", $.ui.interaction, {
/** interaction interface **/
_isValidTarget: function( element ) {
var handle = this.options.handle ? element.closest( this.options.handle ).length : true,
exclude = this.options.exclude ? element.closest( this.options.exclude ).length : false;
var handle = this.options.handle ? element.is( this.element.find( this.options.handle ) ) : true,
exclude = this.options.exclude ? element.is( this.element.find( this.options.exclude ) ) : false;
// Enforce boolean
return !!( handle && !exclude );