2015-04-07 00:35:27 +00:00
|
|
|
define( [
|
2016-04-03 16:32:14 +00:00
|
|
|
"qunit",
|
2015-04-07 00:35:27 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-07-15 02:03:06 +00:00
|
|
|
"ui/widgets/droppable"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2009-02-02 07:09:15 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "droppable: options", { afterEach: helper.moduleAfterEach } );
|
2009-02-02 07:09:15 +00:00
|
|
|
|
2012-10-31 02:19:49 +00:00
|
|
|
/*
|
2016-04-03 16:32:14 +00:00
|
|
|
Test( "{ accept '*' }, default ", function() {
|
2009-02-02 13:23:51 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
|
|
|
|
2014-08-11 00:46:27 +00:00
|
|
|
test( "{ accept: Selector }", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
|
|
|
|
2014-08-11 00:46:27 +00:00
|
|
|
test( "{ accept: function(draggable) }", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
|
|
|
|
2014-08-11 00:46:27 +00:00
|
|
|
test( "activeClass", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
2012-10-31 02:19:49 +00:00
|
|
|
*/
|
2016-04-03 16:32:14 +00:00
|
|
|
QUnit.test( "{ addClasses: true }, default", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-08-24 12:59:32 +00:00
|
|
|
var el = $( "<div />" ).droppable( { addClasses: true } );
|
2015-01-30 14:57:56 +00:00
|
|
|
assert.hasClasses( el, "ui-droppable" );
|
2014-08-11 00:46:27 +00:00
|
|
|
el.droppable( "destroy" );
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2009-02-02 07:14:19 +00:00
|
|
|
|
2016-04-03 16:32:14 +00:00
|
|
|
QUnit.test( "{ addClasses: false }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-08-24 12:59:32 +00:00
|
|
|
var el = $( "<div />" ).droppable( { addClasses: false } );
|
2015-01-30 14:57:56 +00:00
|
|
|
|
|
|
|
assert.lacksClasses( el, "ui-droppable" );
|
2014-08-11 00:46:27 +00:00
|
|
|
el.droppable( "destroy" );
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2013-10-29 13:48:51 +00:00
|
|
|
|
2016-04-03 16:32:14 +00:00
|
|
|
QUnit.test( "scope", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2013-10-29 13:48:51 +00:00
|
|
|
var droppableOffset, draggableOffset, oldDraggableOffset, dx, dy,
|
2015-08-24 12:59:32 +00:00
|
|
|
draggable1 = $( "<div />" ).appendTo( "#qunit-fixture" ).draggable( { revert: "invalid" } ),
|
2014-08-11 00:46:27 +00:00
|
|
|
draggable2 = $( "<div />" ).appendTo( "#qunit-fixture" ).droppable(),
|
|
|
|
droppable = $( "<div />" ).appendTo( "#qunit-fixture" ).droppable(),
|
|
|
|
newScope = "test";
|
2013-10-29 13:48:51 +00:00
|
|
|
|
|
|
|
draggable1.draggable( "option", "scope", newScope );
|
|
|
|
droppable.droppable( "option", "scope", newScope );
|
|
|
|
|
|
|
|
// Test that droppable accepts draggable with new scope.
|
|
|
|
droppableOffset = droppable.offset();
|
|
|
|
draggableOffset = draggable1.offset();
|
|
|
|
dx = droppableOffset.left - draggableOffset.left;
|
|
|
|
dy = droppableOffset.top - draggableOffset.top;
|
|
|
|
|
|
|
|
draggable1.simulate( "drag", {
|
|
|
|
dx: dx,
|
|
|
|
dy: dy
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2013-10-29 13:48:51 +00:00
|
|
|
|
|
|
|
draggableOffset = draggable1.offset();
|
2016-04-03 16:32:14 +00:00
|
|
|
assert.equal( draggableOffset.left, droppableOffset.left );
|
|
|
|
assert.equal( draggableOffset.top, droppableOffset.top );
|
2013-10-29 13:48:51 +00:00
|
|
|
|
|
|
|
// Test that droppable doesn't accept draggable with old scope.
|
|
|
|
draggableOffset = draggable2.offset();
|
|
|
|
dx = droppableOffset.left - draggableOffset.left;
|
|
|
|
dy = droppableOffset.top - draggableOffset.top;
|
|
|
|
oldDraggableOffset = draggableOffset;
|
|
|
|
|
|
|
|
draggable2.simulate( "drag", {
|
|
|
|
dx: dx,
|
|
|
|
dy: dy
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2013-10-29 13:48:51 +00:00
|
|
|
|
|
|
|
draggableOffset = draggable2.offset();
|
2016-04-03 16:32:14 +00:00
|
|
|
assert.equal( draggableOffset.left, oldDraggableOffset.left );
|
|
|
|
assert.equal( draggableOffset.top, oldDraggableOffset.top );
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2021-06-06 22:58:12 +00:00
|
|
|
|
2012-10-31 02:19:49 +00:00
|
|
|
/*
|
2016-04-03 16:32:14 +00:00
|
|
|
Test( "greedy", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
|
|
|
|
2014-08-11 00:46:27 +00:00
|
|
|
test( "hoverClass", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
|
|
|
|
2014-08-11 00:46:27 +00:00
|
|
|
test( "tolerance, fit", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
2014-08-13 23:36:07 +00:00
|
|
|
*/
|
2009-02-02 07:09:15 +00:00
|
|
|
|
2016-04-03 16:32:14 +00:00
|
|
|
QUnit.test( "tolerance, intersect", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-08-13 23:36:07 +00:00
|
|
|
|
|
|
|
var draggable, droppable,
|
|
|
|
dataset = [
|
|
|
|
[ 0, 0, false, "too far up and left" ],
|
|
|
|
[ 6, 0, false, "too far up" ],
|
|
|
|
[ 0, 6, false, "too far left" ],
|
|
|
|
[ 6, 6, true, "top left corner" ],
|
|
|
|
[ 14, 14, true, "bottom right corner" ],
|
|
|
|
[ 15, 6, false, "too far right" ],
|
|
|
|
[ 6, 15, false, "too far down" ],
|
|
|
|
[ 15, 15, false, "too far down and right" ]
|
|
|
|
];
|
|
|
|
|
|
|
|
draggable = $( "<div />" )
|
|
|
|
.appendTo( "#qunit-fixture" )
|
2015-08-24 12:59:32 +00:00
|
|
|
.css( {
|
2014-08-13 23:36:07 +00:00
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
position: "absolute",
|
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/6876
|
2014-08-13 23:36:07 +00:00
|
|
|
// Droppable: droppable region is offset by draggables margin
|
|
|
|
marginTop: 3,
|
|
|
|
marginLeft: 3
|
2015-08-24 12:59:32 +00:00
|
|
|
} )
|
2014-08-13 23:36:07 +00:00
|
|
|
.draggable();
|
|
|
|
|
|
|
|
droppable = $( "<div />" )
|
|
|
|
.appendTo( "#qunit-fixture" )
|
2015-08-24 12:59:32 +00:00
|
|
|
.css( { width: 10, height: 10, position: "absolute", top: 13, left: 13 } )
|
|
|
|
.droppable( { tolerance: "intersect" } );
|
2014-08-13 23:36:07 +00:00
|
|
|
|
|
|
|
$.each( dataset, function() {
|
|
|
|
var data = this;
|
|
|
|
|
2015-08-24 12:59:32 +00:00
|
|
|
draggable.css( {
|
2014-08-13 23:36:07 +00:00
|
|
|
top: 0,
|
|
|
|
left: 0
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2014-08-13 23:36:07 +00:00
|
|
|
|
2015-05-14 01:58:16 +00:00
|
|
|
droppable.off( "drop" ).on( "drop", function() {
|
2016-04-03 16:32:14 +00:00
|
|
|
assert.equal( true, data[ 2 ], data[ 3 ] );
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2014-08-13 23:36:07 +00:00
|
|
|
|
|
|
|
$( draggable ).simulate( "drag", {
|
|
|
|
dx: data[ 0 ],
|
|
|
|
dy: data[ 1 ]
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2009-02-02 07:09:15 +00:00
|
|
|
|
2016-04-03 16:32:14 +00:00
|
|
|
QUnit.test( "tolerance, pointer", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2014-08-11 00:40:55 +00:00
|
|
|
|
|
|
|
var draggable, droppable,
|
|
|
|
dataset = [
|
|
|
|
[ -1, -1, false, "too far up and left" ],
|
|
|
|
[ -1, 0, false, "too far left" ],
|
|
|
|
[ 0, -1, false, "too far up" ],
|
|
|
|
[ 0, 0, true, "top left corner" ],
|
|
|
|
[ 9, 9, true, "bottom right corner" ],
|
|
|
|
[ 10, 9, false, "too far right" ],
|
|
|
|
[ 9, 10, false, "too far down" ],
|
|
|
|
[ 10, 10, false, "too far down and right" ]
|
|
|
|
];
|
|
|
|
|
|
|
|
draggable = $( "<div />" )
|
|
|
|
.appendTo( "#qunit-fixture" )
|
2015-08-24 12:59:32 +00:00
|
|
|
.css( { width: 10, height: 10, position: "absolute" } )
|
2014-08-11 00:40:55 +00:00
|
|
|
.draggable();
|
|
|
|
|
|
|
|
droppable = $( "<div />" )
|
|
|
|
.appendTo( "#qunit-fixture" )
|
2015-08-24 12:59:32 +00:00
|
|
|
.css( { width: 10, height: 10, position: "absolute", top: 5, left: 5 } )
|
|
|
|
.droppable( { tolerance: "pointer" } );
|
2014-08-11 00:40:55 +00:00
|
|
|
|
|
|
|
$.each( dataset, function() {
|
|
|
|
var data = this;
|
|
|
|
|
2015-05-14 01:58:16 +00:00
|
|
|
droppable.off( "drop" ).on( "drop", function() {
|
2016-04-03 16:32:14 +00:00
|
|
|
assert.equal( true, data[ 2 ], data[ 3 ] );
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2014-08-11 00:40:55 +00:00
|
|
|
|
|
|
|
$( draggable ).simulate( "drag", {
|
|
|
|
dx: ( data[ 0 ] - $( draggable ).position().left ),
|
|
|
|
dy: ( data[ 1 ] - $( draggable ).position().top )
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-05-21 14:19:14 +00:00
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/4977 - tolerance, pointer - bug when pointer outside draggable
|
2015-08-24 12:59:32 +00:00
|
|
|
draggable.css( { top: 0, left: 0 } ).draggable( "option", "axis", "x" );
|
|
|
|
droppable.css( { top: 15, left: 15 } );
|
2013-05-21 14:19:14 +00:00
|
|
|
|
2015-05-14 01:58:16 +00:00
|
|
|
droppable.off( "drop" ).on( "drop", function() {
|
2016-04-03 16:32:14 +00:00
|
|
|
assert.ok( true, "drop fires as long as pointer is within droppable" );
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2013-05-21 14:19:14 +00:00
|
|
|
|
|
|
|
$( draggable ).simulate( "drag", {
|
|
|
|
dx: 10,
|
|
|
|
dy: 10
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-02-02 07:09:15 +00:00
|
|
|
|
2014-08-11 00:40:55 +00:00
|
|
|
/*
|
2016-04-03 16:32:14 +00:00
|
|
|
Test( "tolerance, touch", function() {
|
2009-02-02 07:09:15 +00:00
|
|
|
ok(false, 'missing test - untested code is broken code');
|
|
|
|
});
|
2012-10-31 02:19:49 +00:00
|
|
|
*/
|
2015-04-07 00:35:27 +00:00
|
|
|
} );
|