2015-04-06 16:42:49 +00:00
|
|
|
define( [
|
2016-04-03 16:21:57 +00:00
|
|
|
"qunit",
|
2015-04-06 16:42:49 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:59:40 +00:00
|
|
|
"ui/widgets/draggable",
|
2015-07-15 02:03:06 +00:00
|
|
|
"ui/widgets/droppable",
|
2015-07-15 02:08:51 +00:00
|
|
|
"ui/widgets/sortable"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper, testHelper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "draggable: options", { afterEach: helper.moduleAfterEach } );
|
2015-10-17 19:12:26 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
// TODO: This doesn't actually test whether append happened, possibly remove
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: 'parent' }, default, no clone", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { appendTo: "parent" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "absolute appendTo: parent" );
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { appendTo: "parent" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "relative appendTo: parent" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
// TODO: This doesn't actually test whether append happened, possibly remove
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: Element }, no clone", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { appendTo: $( "#draggable2" ).parent()[ 0 ] } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "absolute appendTo: Element" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { appendTo: $( "#draggable2" ).parent()[ 0 ] } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "relative appendTo: Element" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
// TODO: This doesn't actually test whether append happened, possibly remove
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: Selector }, no clone", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { appendTo: "#main" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "absolute appendTo: Selector" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { appendTo: "#main" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "relative appendTo: Selector" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: 'parent' }, default", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.draggable( "option", "appendTo" ), "parent" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: Element }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var appendTo = $( "#draggable2" ).parent()[ 0 ],
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { appendTo: appendTo } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_parent" ), appendTo );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: jQuery }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var appendTo = $( "#draggable2" ).parent(),
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { appendTo: appendTo } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_parent" ), appendTo[ 0 ] );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ appendTo: Selector }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var appendTo = "#main",
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { appendTo: appendTo } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_parent" ), $( appendTo )[ 0 ] );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "appendTo, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( { helper: "clone" } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
// Move and make sure element was appended to fixture
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
// Move and make sure element was appended to main
|
2013-10-19 19:47:13 +00:00
|
|
|
element.draggable( "option", "appendTo", $( "#qunit-fixture" ) );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 2, 2 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ axis: false }, default", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { axis: false } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "axis: false" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ axis: 'x' }", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { axis: "x" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 50, 50, 50, 0, "axis: x" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ axis: 'y' }", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { axis: "y" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 50, 50, 0, 50, "axis: y" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ axis: ? }, unexpected", function( assert ) {
|
2013-03-04 06:32:23 +00:00
|
|
|
var element,
|
2012-11-03 20:17:16 +00:00
|
|
|
unexpected = {
|
|
|
|
"true": true,
|
|
|
|
"{}": {},
|
|
|
|
"[]": [],
|
|
|
|
"null": null,
|
|
|
|
"undefined": undefined,
|
|
|
|
"function() {}": function() {}
|
|
|
|
};
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( 12 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$.each( unexpected, function( key, val ) {
|
|
|
|
element = $( "#draggable2" ).draggable( { axis: val } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "axis: " + key );
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "destroy" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "axis, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( { axis: false } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
// Any Direction
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "axis: default" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Only horizontal
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "axis", "x" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 50, 50, 50, 0, "axis: x as option" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Vertical only
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "axis", "y" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 50, 50, 0, 50, "axis: y as option" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ cancel: 'input,textarea,button,select,option' }, default", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-10-23 15:04:10 +00:00
|
|
|
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#qunit-fixture" );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable-option-cancel-default" ).draggable( { cancel: "input,textarea,button,select,option" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "cancel: default, element dragged" );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "destroy" );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable-option-cancel-default" ).draggable( { cancel: "input,textarea,button,select,option" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, "cancel: default, input dragged", "#draggable-option-cancel-default input" );
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "destroy" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ cancel: 'span' }", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable();
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "cancel: default, span dragged", "#draggable2 span" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "destroy" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( { cancel: "span" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, "cancel: span, span dragged", "#draggable2 span" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ cancel: ? }, unexpected", function( assert ) {
|
|
|
|
assert.expect( 12 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element,
|
2012-11-03 20:17:16 +00:00
|
|
|
unexpected = {
|
|
|
|
"true": true,
|
|
|
|
"false": false,
|
|
|
|
"{}": {},
|
|
|
|
"[]": [],
|
|
|
|
"null": null,
|
2013-01-12 05:33:45 +00:00
|
|
|
"undefined": undefined
|
2012-11-03 20:17:16 +00:00
|
|
|
};
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
$.each( unexpected, function( key, val ) {
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( { cancel: val } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "cancel: " + key );
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "destroy" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-10-20 13:35:12 +00:00
|
|
|
/*
|
2016-04-03 16:21:57 +00:00
|
|
|
Test( "{ cancel: Selectors }, matching parent selector", function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-10-21 14:59:54 +00:00
|
|
|
expect( 4 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ cancel: "span a" });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#qunit-fixture" ).append( "<span id='wrapping'><a></a></span>" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.find( "span" ).append( "<a>" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#wrapping a" ).append( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "drag span child", "#draggable2 span" );
|
|
|
|
testHelper.shouldNotDrag( assert, $( "#draggable2 span a" ), "drag span a" );
|
|
|
|
testHelper.shouldNotDrag( assert, $( "#wrapping a" ), "drag wrapping a" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#draggable2" ).draggable( "option", "cancel", "span > a" );
|
|
|
|
$( "#draggable2" ).find( "a" ).append( "<a>" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "drag span child", $( "#draggable2 span a" ).last() );
|
|
|
|
testHelper.shouldNotDrag( assert, $( "#draggable2 span a" ).first(), "drag span a first child" );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
2013-01-12 05:33:45 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "cancelement, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-10-23 15:04:10 +00:00
|
|
|
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#qunit-fixture" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var input = $( "#draggable-option-cancel-default input" ),
|
|
|
|
element = $( "#draggable-option-cancel-default" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, "cancel: default, input dragged", input );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cancel", "textarea" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "cancel: textarea, input dragged", input );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cancel", "input" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, "cancel: input, input dragged", input );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "connectToSortable, dragging out of a sortable", function( assert ) {
|
2019-12-08 21:23:08 +00:00
|
|
|
assert.expect( 5 );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
2019-12-08 21:23:08 +00:00
|
|
|
var sortItem, dragHelper, result,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggableSortable" ).draggable( {
|
2014-08-22 19:16:41 +00:00
|
|
|
scroll: false,
|
|
|
|
connectToSortable: "#sortable"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
|
|
|
sortable = $( "#sortable" ).sortable( { revert: 100 } ),
|
2014-08-22 19:16:41 +00:00
|
|
|
dx = 50,
|
|
|
|
dy = 50,
|
|
|
|
offsetBefore = element.offset(),
|
|
|
|
offsetExpected = {
|
|
|
|
left: offsetBefore.left + dx,
|
|
|
|
top: offsetBefore.top + dy
|
|
|
|
};
|
|
|
|
|
|
|
|
$( sortable ).one( "sortstart", function( event, ui ) {
|
|
|
|
sortItem = ui.item;
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
|
|
|
$( element ).one( "drag", function( event, ui ) {
|
|
|
|
dragHelper = ui.helper;
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
|
|
|
$( element ).one( "dragstop", function( event, ui ) {
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/8809
|
2014-08-22 19:16:41 +00:00
|
|
|
// Position issue when connected to sortable
|
2019-12-08 21:23:08 +00:00
|
|
|
result = ui.helper.offset();
|
|
|
|
|
|
|
|
// Support: Chrome <=45 - 73+
|
|
|
|
// In recent Chrome these values differ a little.
|
|
|
|
assert.ok( Math.abs( result.top - offsetExpected.top ) < 0.25, "draggable offset is within 0.25 of expected" );
|
|
|
|
assert.ok( Math.abs( result.left - offsetExpected.left ) < 0.25, "draggable offset is within 0.25 of expected" );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/7734
|
2014-08-22 19:16:41 +00:00
|
|
|
// HTML IDs are removed when dragging to a Sortable
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( sortItem[ 0 ], dragHelper[ 0 ], "both have the same helper" );
|
|
|
|
assert.equal( sortItem.attr( "id" ), dragHelper.attr( "id" ), "both have the same id" );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9481
|
2014-08-26 12:50:50 +00:00
|
|
|
// connectToSortable causes sortable revert to fail on second attempt
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( sortable.sortable( "option", "revert" ), 100, "sortable revert behavior is preserved" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: dx,
|
|
|
|
dy: dy
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2020-05-16 07:16:24 +00:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
element.stop( true );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "connectToSortable, dragging clone into sortable", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
2014-08-26 12:50:50 +00:00
|
|
|
var offsetPlaceholder,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggableSortableClone" ).draggable( {
|
2014-08-22 19:16:41 +00:00
|
|
|
scroll: false,
|
|
|
|
connectToSortable: "#sortable",
|
|
|
|
helper: "clone"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
|
|
|
sortable = $( "#sortable" ).sortable( { revert: 100 } ),
|
2014-08-22 19:16:41 +00:00
|
|
|
offsetSortable = sortable.offset();
|
|
|
|
|
2014-08-25 14:28:39 +00:00
|
|
|
$( sortable ).one( "sort", function( event, ui ) {
|
2014-08-26 12:50:50 +00:00
|
|
|
offsetPlaceholder = ui.placeholder.offset();
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/8809
|
2014-08-22 19:16:41 +00:00
|
|
|
// Position issue when connected to sortable
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( ui.helper.offset(), offsetSortable, "sortable offset is correct" );
|
|
|
|
assert.notDeepEqual( ui.helper.offset(), offsetPlaceholder, "offset not equal to placeholder" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
$( sortable ).one( "sortstop", function( event, ui ) {
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9675
|
2014-08-26 12:50:50 +00:00
|
|
|
// Animation issue with revert and connectToSortable
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( ui.item.offset(), offsetPlaceholder, "offset eventually equals placeholder" );
|
|
|
|
ready();
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
x: offsetSortable.left + 1,
|
|
|
|
y: offsetSortable.top + 1,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-22 19:16:41 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "connectToSortable, dragging multiple elements in and out of sortable", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggableSortableClone" ).draggable( {
|
2014-08-26 12:50:50 +00:00
|
|
|
scroll: false,
|
|
|
|
connectToSortable: "#sortable",
|
|
|
|
helper: "clone"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
|
|
|
element2 = $( "#draggableSortable" ).draggable( {
|
2014-08-26 12:50:50 +00:00
|
|
|
scroll: false,
|
|
|
|
connectToSortable: "#sortable"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
|
|
|
sortable = $( "#sortable" ).sortable( { revert: false } ),
|
2014-08-26 12:50:50 +00:00
|
|
|
sortableOffset = sortable.offset();
|
|
|
|
|
|
|
|
// Move element into sortable
|
|
|
|
element.simulate( "drag", {
|
|
|
|
x: sortableOffset.left + 1,
|
|
|
|
y: sortableOffset.top + 1,
|
|
|
|
moves: 10
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
// Move element in sortable out
|
|
|
|
element2.simulate( "drag", {
|
|
|
|
dx: 200,
|
|
|
|
dy: 200,
|
|
|
|
moves: 10
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9675
|
2014-08-26 12:50:50 +00:00
|
|
|
// Animation issue with revert and connectToSortable
|
|
|
|
sortable.one( "sortstop", function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( !$.contains( document, ui.placeholder[ 0 ] ), "placeholder was removed" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
// Move the clone of the first element back out
|
|
|
|
$( "#sortable .sortable2Item" ).simulate( "drag", {
|
|
|
|
dx: 200,
|
|
|
|
dy: 200,
|
|
|
|
moves: 10
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "connectToSortable, dragging through one sortable to a second", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
var overCount = 0,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggableSortable" ).draggable( {
|
2014-08-26 12:50:50 +00:00
|
|
|
scroll: false,
|
|
|
|
connectToSortable: ".sortable"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2014-08-26 12:50:50 +00:00
|
|
|
delta = 200,
|
2015-08-24 12:59:44 +00:00
|
|
|
sortable = $( "#sortable" ).sortable( { revert: false } ),
|
|
|
|
sortable2 = $( "#sortable2" ).sortable( { revert: false } ),
|
2014-08-26 12:50:50 +00:00
|
|
|
sortable2Offset = sortable2.offset(),
|
|
|
|
dragParams = {
|
|
|
|
x: sortable2Offset.left + 25,
|
|
|
|
y: sortable2Offset.top + sortable.outerHeight() + delta,
|
|
|
|
moves: 10
|
|
|
|
};
|
|
|
|
|
|
|
|
$( sortable ).one( "sortover", function() {
|
|
|
|
overCount++;
|
|
|
|
sortable2.css( "top", "+=" + delta );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
$( sortable2 ).on( "sortupdate", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "second sortable is updated" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
$( sortable2 ).one( "sortover", function() {
|
|
|
|
overCount++;
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
$( sortable2 ).one( "sortstop", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( overCount, 2, "went over both sortables" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", dragParams );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-26 12:50:50 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "connectToSortable, dragging through a sortable", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-11-09 01:23:08 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var draggable = $( "#draggableSortable" ).draggable( {
|
2014-11-09 01:23:08 +00:00
|
|
|
scroll: false,
|
|
|
|
connectToSortable: "#sortable2"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2014-11-09 01:23:08 +00:00
|
|
|
sortable = $( "#sortable2" ).sortable(),
|
|
|
|
sortableOffset = sortable.offset();
|
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/10669
|
2014-11-09 01:23:08 +00:00
|
|
|
// Draggable: Position issue with connectToSortable
|
|
|
|
draggable.one( "dragstop", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( draggable.parent().attr( "id" ), "sortable", "restored draggable to original parent" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-11-09 01:23:08 +00:00
|
|
|
|
|
|
|
draggable.simulate( "drag", {
|
|
|
|
x: sortableOffset.left + 25,
|
|
|
|
y: sortableOffset.top + sortable.outerHeight() + 400,
|
|
|
|
moves: 20
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-11-09 01:23:08 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ containment: Element }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetAfter,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { containment: $( "#draggable1" ).parent()[ 0 ] } ),
|
2013-03-04 06:32:23 +00:00
|
|
|
p = element.parent(),
|
2012-04-19 14:27:06 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2015-04-07 14:30:07 +00:00
|
|
|
left: po.left + testHelper.border( p, "left" ) + testHelper.margin( element, "left" ),
|
|
|
|
top: po.top + testHelper.border( p, "top" ) + testHelper.margin( element, "top" )
|
2012-11-03 20:17:16 +00:00
|
|
|
};
|
2012-12-09 02:27:37 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: -100,
|
|
|
|
dy: -100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ containment: Selector }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetAfter,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { containment: $( "#qunit-fixture" ) } ),
|
2013-03-04 06:32:23 +00:00
|
|
|
p = element.parent(),
|
2012-04-19 14:27:06 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2015-04-07 14:30:07 +00:00
|
|
|
left: po.left + testHelper.border( p, "left" ) + testHelper.margin( element, "left" ),
|
|
|
|
top: po.top + testHelper.border( p, "top" ) + testHelper.margin( element, "top" )
|
2012-11-03 20:17:16 +00:00
|
|
|
};
|
2012-12-09 02:27:37 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: -100,
|
|
|
|
dy: -100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ containment: [x1, y1, x2, y2] }", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable(),
|
|
|
|
eo = element.offset();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 16:39:14 +00:00
|
|
|
element.draggable( "option", "containment", [ eo.left, eo.top, eo.left + element.width() + 5, eo.top + element.height() + 5 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, -100, -100, 0, 0, "containment: [x1, y1, x2, y2]" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ containment: 'parent' }, relative", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var offsetAfter,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { containment: "parent" } ),
|
2013-03-04 06:32:23 +00:00
|
|
|
p = element.parent(),
|
2013-01-12 05:33:45 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2015-04-07 14:30:07 +00:00
|
|
|
left: po.left + testHelper.border( p, "left" ) + testHelper.margin( element, "left" ),
|
|
|
|
top: po.top + testHelper.border( p, "top" ) + testHelper.margin( element, "top" )
|
2013-01-12 05:33:45 +00:00
|
|
|
};
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
dx: -100,
|
|
|
|
dy: -100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ containment: 'parent' }, absolute", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var offsetAfter,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( { containment: "parent" } ),
|
2013-03-04 06:32:23 +00:00
|
|
|
p = element.parent(),
|
2013-01-12 05:33:45 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2015-04-07 14:30:07 +00:00
|
|
|
left: po.left + testHelper.border( p, "left" ) + testHelper.margin( element, "left" ),
|
|
|
|
top: po.top + testHelper.border( p, "top" ) + testHelper.margin( element, "top" )
|
2013-01-12 05:33:45 +00:00
|
|
|
};
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
dx: -100,
|
|
|
|
dy: -100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "containment, account for border", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-26 20:31:27 +00:00
|
|
|
|
2013-10-23 15:04:10 +00:00
|
|
|
var el = $( "#draggable1" ).appendTo( "#scrollParent" ),
|
2015-08-24 12:59:44 +00:00
|
|
|
parent = el.parent().css( {
|
2013-01-26 20:31:27 +00:00
|
|
|
height: "100px",
|
|
|
|
width: "100px",
|
|
|
|
borderStyle: "solid",
|
|
|
|
borderWidth: "5px 10px 15px 20px"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-01-26 20:31:27 +00:00
|
|
|
parentBottom = parent.offset().top + parent.outerHeight(),
|
|
|
|
parentRight = parent.offset().left + parent.outerWidth(),
|
2015-04-07 14:30:07 +00:00
|
|
|
parentBorderBottom = testHelper.border( parent, "bottom" ),
|
|
|
|
parentBorderRight = testHelper.border( parent, "right" );
|
2013-01-26 20:31:27 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
el.css( {
|
2013-01-26 20:31:27 +00:00
|
|
|
height: "5px",
|
|
|
|
width: "5px"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ).draggable( { containment: "parent", scroll: false } );
|
2013-01-26 20:31:27 +00:00
|
|
|
|
|
|
|
el.simulate( "drag", {
|
|
|
|
dx: 100,
|
|
|
|
dy: 100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-26 20:31:27 +00:00
|
|
|
|
2015-03-31 20:52:28 +00:00
|
|
|
assert.close( el.offset().top, parentBottom - parentBorderBottom - el.height(), 1,
|
2013-01-26 20:31:27 +00:00
|
|
|
"The draggable should be on top of its parent's bottom border" );
|
2015-03-31 20:52:28 +00:00
|
|
|
assert.close( el.offset().left, parentRight - parentBorderRight - el.width(), 1,
|
2013-01-26 20:31:27 +00:00
|
|
|
"The draggable should be to the right of its parent's right border" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-26 20:31:27 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/7016
|
2014-08-17 18:38:05 +00:00
|
|
|
// draggable can be pulled out of containment in Chrome and IE8
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "containment, element cant be pulled out of container", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-08-17 18:38:05 +00:00
|
|
|
|
|
|
|
var offsetBefore,
|
2015-08-24 12:59:44 +00:00
|
|
|
parent = $( "<div>" ).css( { width: 200, height: 200 } ).appendTo( "#qunit-fixture" ),
|
2014-08-17 18:38:05 +00:00
|
|
|
element = $( "#draggable1" ).appendTo( parent );
|
|
|
|
|
|
|
|
element
|
2015-08-24 12:59:44 +00:00
|
|
|
.css( {
|
2014-08-17 18:38:05 +00:00
|
|
|
height: "5px",
|
|
|
|
width: "5px"
|
2015-08-24 12:59:44 +00:00
|
|
|
} )
|
|
|
|
.draggable( { containment: "parent" } )
|
2014-08-17 18:38:05 +00:00
|
|
|
.simulate( "drag", {
|
2014-08-26 12:50:50 +00:00
|
|
|
dx: 500,
|
|
|
|
dy: 500
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-17 18:38:05 +00:00
|
|
|
|
|
|
|
offsetBefore = element.offset();
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 200,
|
|
|
|
dy: 200
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-17 18:38:05 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( element.offset(), offsetBefore, "The draggable should not move past bottom right edge" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-17 18:38:05 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "containment, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 8 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( { containment: false, scroll: false } ),
|
2014-01-13 22:51:06 +00:00
|
|
|
po = element.parent().offset(),
|
|
|
|
containment = [ po.left - 100, po.top - 100, po.left + 500, po.top + 500 ];
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, -100, -100, -100, -100, "containment: default" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( "option", "containment", "parent" ).css( { top: 0, left: 0 } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, -100, -100, 0, 0, "containment: parent as option" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( "option", "containment", containment ).css( { top: 0, left: 0 } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, -100, -100, -100, -100, "containment: array as option" );
|
2014-01-13 22:51:06 +00:00
|
|
|
|
2013-03-23 02:12:52 +00:00
|
|
|
element.draggable( "option", "containment", false );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, -100, -100, -100, -100, "containment: false as option" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2010-07-15 17:16:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ cursor: 'auto' }, default", function( assert ) {
|
2013-03-04 06:32:23 +00:00
|
|
|
function getCursor() {
|
|
|
|
return $( "#draggable2" ).css( "cursor" );
|
|
|
|
}
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( 2 );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var actual, after,
|
2012-12-09 02:27:37 +00:00
|
|
|
expected = "auto",
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( {
|
2012-12-09 02:27:37 +00:00
|
|
|
cursor: expected,
|
|
|
|
start: function() {
|
|
|
|
actual = getCursor();
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-03-04 06:32:23 +00:00
|
|
|
before = getCursor();
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: -1,
|
|
|
|
dy: -1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
after = getCursor();
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( actual, expected, "start callback: cursor '" + expected + "'" );
|
|
|
|
assert.equal( after, before, "after drag: cursor restored" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ cursor: 'move' }", function( assert ) {
|
2013-03-04 06:32:23 +00:00
|
|
|
function getCursor() {
|
|
|
|
return $( "body" ).css( "cursor" );
|
|
|
|
}
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( 2 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var actual, after,
|
2012-12-09 02:27:37 +00:00
|
|
|
expected = "move",
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( {
|
2012-12-09 02:27:37 +00:00
|
|
|
cursor: expected,
|
|
|
|
start: function() {
|
|
|
|
actual = getCursor();
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-03-04 06:32:23 +00:00
|
|
|
before = getCursor();
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: -1,
|
|
|
|
dy: -1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
after = getCursor();
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( actual, expected, "start callback: cursor '" + expected + "'" );
|
|
|
|
assert.equal( after, before, "after drag: cursor restored" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#6889: Cursor doesn't revert to pre-dragging state after revert action when original element is removed", function( assert ) {
|
2013-03-27 20:47:57 +00:00
|
|
|
function getCursor() {
|
|
|
|
return $( "body" ).css( "cursor" );
|
|
|
|
}
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( 2 );
|
2013-03-27 20:47:57 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
|
2013-03-27 20:47:57 +00:00
|
|
|
cursor: "move",
|
|
|
|
revert: true,
|
|
|
|
revertDuration: 0,
|
|
|
|
start: function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notEqual( getCursor(), expected, "start callback: cursor '" + expected + "'" );
|
2013-03-27 20:47:57 +00:00
|
|
|
$( "#wrapper" ).remove();
|
|
|
|
},
|
|
|
|
stop: function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( getCursor(), expected, "after drag: cursor restored" );
|
2013-03-27 20:47:57 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-03-27 20:47:57 +00:00
|
|
|
expected = getCursor();
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
if ( testHelper.unreliableContains ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
|
|
|
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
2013-04-14 16:58:42 +00:00
|
|
|
} else {
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: -1,
|
|
|
|
dy: -1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-04-14 16:58:42 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-27 20:47:57 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "cursor, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.trackMouseCss( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_cursor" ), "auto" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cursor", "move" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_cursor" ), "move" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cursor", "ns-resize" );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.data( "last_dragged_cursor" ), "ns-resize" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "cursorAt", function( assert ) {
|
|
|
|
assert.expect( 24 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-12-22 22:39:36 +00:00
|
|
|
var deltaX = -3,
|
|
|
|
deltaY = -3,
|
2012-12-22 21:30:27 +00:00
|
|
|
tests = {
|
2014-02-17 21:08:41 +00:00
|
|
|
"false": { cursorAt: false },
|
|
|
|
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } },
|
|
|
|
"[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] },
|
|
|
|
"'10 20'": { x: 10, y: 20, cursorAt: "10 20" },
|
|
|
|
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } },
|
|
|
|
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } }
|
2012-10-30 23:12:17 +00:00
|
|
|
};
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-12-22 21:30:27 +00:00
|
|
|
$.each( tests, function( testName, testData ) {
|
|
|
|
$.each( [ "relative", "absolute" ], function( i, position ) {
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable" + ( i + 1 ) ).draggable( {
|
2012-12-22 21:30:27 +00:00
|
|
|
cursorAt: testData.cursorAt,
|
|
|
|
drag: function( event, ui ) {
|
2014-02-17 21:08:41 +00:00
|
|
|
if ( !testData.cursorAt ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
|
|
|
|
assert.equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
|
2014-02-17 21:08:41 +00:00
|
|
|
} else if ( testData.cursorAt.right ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - testHelper.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
assert.equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - testHelper.unreliableOffset, testName + " " + position + " top" );
|
2012-12-22 21:30:27 +00:00
|
|
|
} else {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( event.clientX - ui.offset.left, testData.x + testHelper.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
assert.equal( event.clientY - ui.offset.top, testData.y + testHelper.unreliableOffset, testName + " " + position + " top" );
|
2012-12-22 21:30:27 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-22 21:30:27 +00:00
|
|
|
moves: 1,
|
|
|
|
dx: deltaX,
|
|
|
|
dy: deltaY
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "cursorAt, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 24 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var deltaX = -3,
|
|
|
|
deltaY = -3,
|
|
|
|
tests = {
|
2014-02-17 21:08:41 +00:00
|
|
|
"false": { cursorAt: false },
|
|
|
|
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt: { left: -5, top: -5 } },
|
|
|
|
"[ 10, 20 ]": { x: 10, y: 20, cursorAt: [ 10, 20 ] },
|
|
|
|
"'10 20'": { x: 10, y: 20, cursorAt: "10 20" },
|
|
|
|
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt: { left: 20, top: 40 } },
|
|
|
|
"{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt: { right: 10, bottom: 20 } }
|
2013-01-12 05:33:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.each( tests, function( testName, testData ) {
|
|
|
|
$.each( [ "relative", "absolute" ], function( i, position ) {
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable" + ( i + 1 ) );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
drag: function( event, ui ) {
|
2014-02-17 21:08:41 +00:00
|
|
|
if ( !testData.cursorAt ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
|
|
|
|
assert.equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
|
2014-02-17 21:08:41 +00:00
|
|
|
} else if ( testData.cursorAt.right ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - testHelper.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
assert.equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - testHelper.unreliableOffset, testName + " " + position + " top" );
|
2013-01-12 05:33:45 +00:00
|
|
|
} else {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( event.clientX - ui.offset.left, testData.x + testHelper.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
assert.equal( event.clientY - ui.offset.top, testData.y + testHelper.unreliableOffset, testName + " " + position + " top" );
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cursorAt", false );
|
|
|
|
element.draggable( "option", "cursorAt", testData.cursorAt );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
moves: 1,
|
|
|
|
dx: deltaX,
|
|
|
|
dy: deltaY
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "disabled", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable();
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "disabled: default" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "disabled", true );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, "option: disabled true" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "disabled", false );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "option: disabled false" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ grid: [50, 50] }, relative", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( { grid: [ 50, 50 ] } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 24, 24, 0, 0, "grid: [50, 50] relative" );
|
|
|
|
testHelper.testDrag( assert, element, element, 26, 25, 50, 50, "grid: [50, 50] relative" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ grid: [50, 50] }, absolute", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { grid: [ 50, 50 ] } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 24, 24, 0, 0, "grid: [50, 50] absolute" );
|
|
|
|
testHelper.testDrag( assert, element, element, 26, 25, 50, 50, "grid: [50, 50] absolute" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "grid, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 8 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
// Forward
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 24, 24, 24, 24, "grid: default" );
|
|
|
|
testHelper.testDrag( assert, element, element, 0, 0, 0, 0, "grid: default" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2014-08-06 23:43:13 +00:00
|
|
|
element.draggable( "option", "grid", [ 50, 50 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDrag( assert, element, element, 24, 24, 0, 0, "grid: [50, 50] as option" );
|
|
|
|
testHelper.testDrag( assert, element, element, 26, 25, 50, 50, "grid: [50, 50] as option" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ handle: 'span' }", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( { handle: "span" } );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "handle: span", "#draggable2 span" );
|
|
|
|
testHelper.shouldMove( assert, element, "handle: span child", "#draggable2 span em" );
|
|
|
|
testHelper.shouldNotDrag( assert, element, "handle: span element" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "handle, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 12 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "handle: default, element dragged" );
|
|
|
|
testHelper.shouldMove( assert, element, "handle: default, span dragged", "#draggable2 span" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Switch
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "handle", "span" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, "handle: span as option, element dragged" );
|
|
|
|
testHelper.shouldMove( assert, element, "handle: span as option, span dragged", "#draggable2 span" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// And back
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "handle", false );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "handle: false as option, element dragged" );
|
|
|
|
testHelper.shouldMove( assert, element, "handle: false as option, span dragged", "#draggable2 span" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "helper, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable();
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "helper: default" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "helper", "clone" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "helper: clone" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "helper", "original" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "helper: original" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9446
|
2014-08-15 01:17:28 +00:00
|
|
|
// Draggable: helper function cannot emulate default behavior
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "helper, function returning original element", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-08-15 01:17:28 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).css( "position", "static" ).draggable( {
|
2014-08-15 01:17:28 +00:00
|
|
|
helper: function() {
|
|
|
|
return this;
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-15 01:17:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testDragHelperOffset( assert, element, 100, 100, 100, 100, "original element is draggable" );
|
2014-08-15 01:17:28 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 100,
|
|
|
|
dy: 100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-15 01:17:28 +00:00
|
|
|
|
2014-08-15 01:03:18 +00:00
|
|
|
function testHelperPosition( scrollPositions, position, helper, scrollElements, scrollElementsTitle ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function( assert ) {
|
|
|
|
assert.expect( scrollPositions.length * 2 );
|
2014-08-15 01:03:18 +00:00
|
|
|
|
|
|
|
var i, j,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).css( { position: position, top: 0, left: 0 } ).draggable( {
|
2014-08-15 01:03:18 +00:00
|
|
|
helper: helper,
|
|
|
|
scroll: false
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-15 01:03:18 +00:00
|
|
|
|
|
|
|
if ( scrollElements.length === 1 && scrollElements[ 0 ] === "#scrollParent" ) {
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.setScrollable( "#main", false );
|
|
|
|
testHelper.setScrollable( "#scrollParent", true );
|
2014-08-15 01:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( j = 0; j < scrollPositions.length; j++ ) {
|
|
|
|
for ( i = 0; i < scrollElements.length; i++ ) {
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.setScroll( scrollElements[ i ] );
|
2014-08-15 01:03:18 +00:00
|
|
|
}
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.testScroll( assert, element, scrollPositions[ j ] );
|
2014-08-15 01:03:18 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < scrollElements.length; i++ ) {
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.restoreScroll( scrollElements[ i ] );
|
2014-08-15 01:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) {
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.setScrollable( "#main", true );
|
|
|
|
testHelper.setScrollable( "#scrollParent", false );
|
2014-08-15 01:03:18 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-15 01:03:18 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
( function() {
|
2014-08-15 01:03:18 +00:00
|
|
|
var scrollElementsMap = {
|
2013-10-29 13:52:57 +00:00
|
|
|
"no elements": [],
|
|
|
|
"parent": [ "#main" ],
|
|
|
|
"root": [ document ],
|
|
|
|
"parent and root": [ "#main", document ],
|
|
|
|
"grandparent": [ "#scrollParent" ]
|
|
|
|
},
|
2013-11-01 01:41:45 +00:00
|
|
|
positions = [ "absolute", "fixed", "relative", "static" ],
|
2013-10-29 13:52:57 +00:00
|
|
|
helpers = [ "original", "clone" ],
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
// Static is not an option here since the fixture is in an absolute container
|
2013-12-03 00:12:21 +00:00
|
|
|
scrollPositions = [ "relative", "absolute", "fixed" ];
|
2013-10-29 13:52:57 +00:00
|
|
|
|
2014-08-15 01:03:18 +00:00
|
|
|
$.each( helpers, function() {
|
|
|
|
var helper = this;
|
|
|
|
$.each( positions, function() {
|
|
|
|
var position = this;
|
|
|
|
$.each( scrollElementsMap, function( scrollElementsTitle, scrollElements ) {
|
|
|
|
testHelperPosition( scrollPositions, position, helper, scrollElements, scrollElementsTitle );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} )();
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ opacity: 0.5 }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-12-09 02:27:37 +00:00
|
|
|
var opacity = null,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( {
|
2012-12-09 02:27:37 +00:00
|
|
|
opacity: 0.5,
|
|
|
|
start: function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
opacity = $( this ).css( "opacity" );
|
2012-12-09 02:27:37 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-12-09 02:27:37 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: -1,
|
|
|
|
dy: -1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( opacity, 0.5, "start callback: opacity is" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "opacity, default, switching after initialization", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var opacity = null,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
start: function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
opacity = $( this ).css( "opacity" );
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( opacity, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "opacity", 0.5 );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 2, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( opacity, 0.5 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "opacity", false );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 3, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( opacity, 1 );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "revert and revertDuration", function( assert ) {
|
2024-04-12 13:23:05 +00:00
|
|
|
var ready = assert.async( 2 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( 7 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
revert: true,
|
|
|
|
revertDuration: 0
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMovePositionButNotOffset( assert, element, "revert: true, revertDuration: 0 should revert immediately" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#draggable2" ).draggable( "option", "revert", "invalid" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMovePositionButNotOffset( assert, element, "revert: invalid, revertDuration: 0 should revert immediately" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#draggable2" ).draggable( "option", "revert", false );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "revert: false should allow movement" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#draggable2" ).draggable( "option", {
|
|
|
|
revert: true,
|
2024-04-12 13:23:05 +00:00
|
|
|
revertDuration: 300,
|
2013-01-12 05:33:45 +00:00
|
|
|
stop: function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
ready();
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-04 06:32:23 +00:00
|
|
|
|
2015-08-21 04:11:02 +00:00
|
|
|
// Animation are async, so test for it asynchronously
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 50, 50 );
|
2013-01-12 05:33:45 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" );
|
2024-04-12 13:23:05 +00:00
|
|
|
ready();
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "revert: valid", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
revert: "valid",
|
|
|
|
revertDuration: 0
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#droppable" ).droppable();
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMovePositionButNotOffset( assert, element, "revert: valid reverts when dropped on a droppable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "scope", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
scope: "tasks",
|
|
|
|
revert: "valid",
|
|
|
|
revertDuration: 0
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "#droppable" ).droppable( { scope: "tasks" } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMovePositionButNotOffset( assert, element, "revert: valid reverts when dropped on a droppable in scope" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "#droppable" ).droppable( "destroy" ).droppable( { scope: "nottasks" } );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "revert: valid reverts when dropped on a droppable out of scope" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "scroll, scrollSensitivity, and scrollSpeed", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.setScrollable( "#main", false );
|
2013-10-23 15:04:10 +00:00
|
|
|
|
2014-02-18 03:10:29 +00:00
|
|
|
var currentScrollTop,
|
|
|
|
viewportHeight = $( window ).height(),
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( { scroll: true } ).appendTo( "#qunit-fixture" ),
|
2013-03-04 06:32:23 +00:00
|
|
|
scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
|
|
|
|
scrollSpeed = element.draggable( "option", "scrollSpeed" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.offset( {
|
2013-01-12 05:33:45 +00:00
|
|
|
top: viewportHeight - scrollSensitivity - 1,
|
|
|
|
left: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2014-02-18 03:10:29 +00:00
|
|
|
$( element ).one( "drag", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( $( window ).scrollTop(), 0, "scroll: true doesn't scroll when the element is dragged outside of scrollSensitivity" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-02-18 03:10:29 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
dx: 1,
|
|
|
|
y: viewportHeight - scrollSensitivity - 1,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "scrollSensitivity", scrollSensitivity + 10 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.offset( {
|
2013-01-12 05:33:45 +00:00
|
|
|
top: viewportHeight - scrollSensitivity - 1,
|
|
|
|
left: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2014-02-18 03:10:29 +00:00
|
|
|
currentScrollTop = $( window ).scrollTop();
|
|
|
|
|
|
|
|
$( element ).one( "drag", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( $( window ).scrollTop() - currentScrollTop, scrollSpeed, "scroll: true scrolls when the element is dragged within scrollSensitivity" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-02-18 03:10:29 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
dx: 1,
|
|
|
|
y: viewportHeight - scrollSensitivity - 1,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.restoreScroll( document );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "scroll ignores containers that are overflow: hidden", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-08-10 03:11:16 +00:00
|
|
|
|
2014-08-14 02:26:04 +00:00
|
|
|
var scrollParent = $( "#scrollParent" ),
|
|
|
|
element = $( "#draggable1" ).draggable().appendTo( scrollParent );
|
|
|
|
|
|
|
|
element.draggable( "option", "scroll", false );
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 1300,
|
|
|
|
dy: 1300
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-14 02:26:04 +00:00
|
|
|
|
|
|
|
// IE8 natively scrolls when dragging an element inside a overflow:hidden
|
|
|
|
// container, so skip this test if native scroll occurs.
|
|
|
|
// Support: IE <9
|
|
|
|
if ( scrollParent.scrollTop() > 0 ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "overflow:hidden container natively scrolls" );
|
|
|
|
assert.ok( true, "overflow:hidden container natively scrolls" );
|
2014-08-14 02:26:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.css( { top: 0, left: 0 } ).draggable( "option", "scroll", true );
|
2014-08-10 03:11:16 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 1300,
|
|
|
|
dy: 1300
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-10 03:11:16 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( scrollParent.scrollTop(), 0, "container doesn't scroll vertically" );
|
|
|
|
assert.equal( scrollParent.scrollLeft(), 0, "container doesn't scroll horizontally" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-10 03:11:16 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#6817: auto scroll goes double distance when dragging", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-03-14 18:21:24 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.restoreScroll( document );
|
2013-10-29 22:35:42 +00:00
|
|
|
|
2013-03-14 18:21:24 +00:00
|
|
|
var offsetBefore,
|
|
|
|
distance = 10,
|
|
|
|
viewportHeight = $( window ).height(),
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( {
|
2013-03-14 18:21:24 +00:00
|
|
|
scroll: true,
|
|
|
|
stop: function( e, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.offset.top, newY, "offset of item matches pointer position after scroll" );
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2015-03-31 20:52:28 +00:00
|
|
|
// TODO: fix IE8 testswarm IFRAME positioning bug so assert.close can be turned back to equal
|
|
|
|
assert.close( ui.offset.top - offsetBefore.top, distance, 1, "offset of item only moves expected distance after scroll" );
|
2013-03-14 18:21:24 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-03-14 18:21:24 +00:00
|
|
|
scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
|
|
|
|
oldY = viewportHeight - scrollSensitivity,
|
|
|
|
newY = oldY + distance;
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.offset( {
|
2013-03-14 18:21:24 +00:00
|
|
|
top: oldY,
|
|
|
|
left: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-14 18:21:24 +00:00
|
|
|
|
|
|
|
offsetBefore = element.offset();
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
dx: 1,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-14 18:21:24 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.restoreScroll( document );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-14 18:21:24 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "snap, snapMode, and snapTolerance", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var newX, newY,
|
|
|
|
snapTolerance = 15,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
snap: true,
|
2013-10-29 22:35:42 +00:00
|
|
|
scroll: false,
|
2013-01-12 05:33:45 +00:00
|
|
|
snapMode: "both",
|
|
|
|
snapTolerance: snapTolerance
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-01-12 05:33:45 +00:00
|
|
|
element2 = $( "#draggable2" ).draggable();
|
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9724
|
2014-08-14 13:50:02 +00:00
|
|
|
// Draggable: Snapping coordinates thrown off by margin on draggable
|
|
|
|
element.css( "margin", "3px" );
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.offset( {
|
2013-01-12 05:33:45 +00:00
|
|
|
top: 1,
|
|
|
|
left: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 14:58:23 +00:00
|
|
|
newX = element2.offset().left - element.outerWidth() - snapTolerance - 2;
|
2013-01-12 05:33:45 +00:00
|
|
|
newY = element2.offset().top;
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-03-31 20:52:28 +00:00
|
|
|
// TODO: fix IE8 testswarm IFRAME positioning bug so assert.close can be turned back to equal
|
|
|
|
assert.close( element.offset().left, newX, 1, "doesn't snap outside the snapTolerance" );
|
|
|
|
assert.close( element.offset().top, newY, 1, "doesn't snap outside the snapTolerance" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 14:58:23 +00:00
|
|
|
newX += 3;
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the snapTolerance" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "snap", "#draggable2" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps based on selector" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "snap", "#draggable3" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap based on invalid selector" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "snap", true );
|
|
|
|
element.draggable( "option", "snapTolerance", snapTolerance - 2 );
|
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap outside the modified snapTolerance" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "snapTolerance", snapTolerance );
|
|
|
|
element.draggable( "option", "snapMode", "inner" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap inside the outer snapTolerance area when snapMode is inner" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
newX = element2.offset().left - snapTolerance - 1;
|
|
|
|
newY = element2.offset().top;
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap inside the outer snapTolerance area when snapMode is inner" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
newX++;
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the inner snapTolerance area when snapMode is inner" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "snapMode", "outer" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2013-01-12 05:33:45 +00:00
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap on the inner snapTolerance area when snapMode is outer" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#8459: element can snap to an element that was removed during drag", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-03-16 18:36:06 +00:00
|
|
|
|
|
|
|
var newX, newY,
|
|
|
|
snapTolerance = 15,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable1" ).draggable( {
|
2013-03-16 18:36:06 +00:00
|
|
|
snap: true,
|
2013-10-29 22:35:42 +00:00
|
|
|
scroll: false,
|
2013-03-16 18:36:06 +00:00
|
|
|
snapMode: "both",
|
|
|
|
snapTolerance: snapTolerance,
|
|
|
|
start: function() {
|
|
|
|
element2.remove();
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-03-16 18:36:06 +00:00
|
|
|
element2 = $( "#draggable2" ).draggable();
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.offset( {
|
2013-03-16 18:36:06 +00:00
|
|
|
top: 1,
|
|
|
|
left: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-16 18:36:06 +00:00
|
|
|
|
|
|
|
newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
|
|
|
|
newY = element2.offset().top;
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-16 18:36:06 +00:00
|
|
|
|
2013-04-07 16:10:59 +00:00
|
|
|
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
|
2015-04-07 14:30:07 +00:00
|
|
|
if ( testHelper.unreliableContains ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
|
|
|
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
2013-04-07 16:10:59 +00:00
|
|
|
} else {
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2015-03-31 20:52:28 +00:00
|
|
|
// TODO: fix IE8 testswarm IFRAME positioning bug so assert.close can be turned back to equal
|
|
|
|
assert.close( element.offset().left, newX, 1, "doesn't snap to a removed element" );
|
|
|
|
assert.close( element.offset().top, newY, 1, "doesn't snap to a removed element" );
|
2013-04-07 16:10:59 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-16 18:36:06 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#8165: Snapping large rectangles to small rectangles doesn't snap properly", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2012-10-29 08:55:54 +00:00
|
|
|
|
|
|
|
var snapTolerance = 20,
|
|
|
|
y = 1,
|
|
|
|
element = $( "#draggable1" )
|
2015-08-24 12:59:44 +00:00
|
|
|
.css( {
|
2012-10-29 08:55:54 +00:00
|
|
|
width: "50px",
|
|
|
|
height: "200px"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ).offset( {
|
2012-10-29 08:55:54 +00:00
|
|
|
top: y,
|
|
|
|
left: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2012-10-29 08:55:54 +00:00
|
|
|
element2 = $( "#draggable2" )
|
2015-08-24 12:59:44 +00:00
|
|
|
.css( {
|
2012-10-29 08:55:54 +00:00
|
|
|
width: "50px",
|
|
|
|
height: "50px"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ).offset( {
|
2012-10-29 08:55:54 +00:00
|
|
|
top: y + snapTolerance + 1,
|
|
|
|
left: 200
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2012-10-29 08:55:54 +00:00
|
|
|
newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "#draggable1, #draggable2" ).draggable( {
|
2012-10-29 08:55:54 +00:00
|
|
|
snap: true,
|
|
|
|
snapTolerance: snapTolerance
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-10-29 08:55:54 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-10-29 08:55:54 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notDeepEqual( element.offset(), { top: y, left: newX }, "snaps even if only a side (not a corner) is inside the snapTolerance" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-10-29 08:55:54 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "stack", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
stack: "#draggable1, #draggable2"
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
|
|
|
element2 = $( "#draggable2" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
stack: "#draggable1, #draggable2"
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element2, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element2.css( "zIndex" ), "3", "stack increments zIndex correctly" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "{ zIndex: 10 }", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-04-19 14:27:06 +00:00
|
|
|
var actual,
|
2012-12-09 02:27:37 +00:00
|
|
|
expected = 10,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( {
|
2012-12-09 02:27:37 +00:00
|
|
|
zIndex: expected,
|
|
|
|
start: function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
actual = $( this ).css( "zIndex" );
|
2012-12-09 02:27:37 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-12-09 02:27:37 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: -1,
|
|
|
|
dy: -1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( actual, expected, "start callback: zIndex is" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "zIndex, default, switching after initialization", function( assert ) {
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( 3 );
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var zindex = null,
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( {
|
2013-01-12 05:33:45 +00:00
|
|
|
start: function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
zindex = $( this ).css( "z-index" );
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.css( "z-index", 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 1, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( zindex, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "zIndex", 5 );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 2, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( zindex, 5 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "zIndex", false );
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 3, 1 );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( zindex, 1 );
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "iframeFix", function( assert ) {
|
2021-03-08 23:11:40 +00:00
|
|
|
assert.expect( 6 );
|
2014-08-24 11:19:38 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable( { iframeFix: true } ),
|
|
|
|
element2 = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable( { iframeFix: ".iframe" } ),
|
2014-08-24 11:19:38 +00:00
|
|
|
iframe = $( "<iframe>" ).appendTo( element );
|
|
|
|
|
|
|
|
element2
|
|
|
|
.append( "<iframe class='iframe'></iframe>" )
|
|
|
|
.append( "<iframe>" );
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
iframe.css( {
|
2014-08-24 11:19:38 +00:00
|
|
|
width: 1,
|
|
|
|
height: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-24 11:19:38 +00:00
|
|
|
|
|
|
|
element.one( "drag", function() {
|
2021-03-08 23:11:40 +00:00
|
|
|
var divOffset, iframeOffset,
|
|
|
|
div = $( this ).children().not( "iframe" );
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9671
|
2014-08-24 11:19:38 +00:00
|
|
|
// iframeFix doesn't handle iframes that move
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( div.length, 1, "blocking div added as sibling" );
|
|
|
|
assert.equal( div.outerWidth(), iframe.outerWidth(), "blocking div is wide enough" );
|
|
|
|
assert.equal( div.outerHeight(), iframe.outerHeight(), "blocking div is tall enough" );
|
2021-03-08 23:11:40 +00:00
|
|
|
|
|
|
|
divOffset = div.offset();
|
|
|
|
iframeOffset = iframe.offset();
|
|
|
|
|
|
|
|
// Support: Edge <79 only
|
|
|
|
// In Edge Legacy these values differ a little.
|
|
|
|
assert.ok( Math.abs( divOffset.top - iframeOffset.top ) < 0.25, "Check top within 0.25 of expected" );
|
|
|
|
assert.ok( Math.abs( divOffset.left - iframeOffset.left ) < 0.25, "Check left within 0.25 of expected" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-24 11:19:38 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-24 11:19:38 +00:00
|
|
|
|
|
|
|
element2.one( "drag", function() {
|
|
|
|
var div = $( this ).children().not( "iframe" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( div.length, 1, "blocking div added as sibling only to matching selector" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-24 11:19:38 +00:00
|
|
|
|
|
|
|
element2.simulate( "drag", {
|
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-24 11:19:38 +00:00
|
|
|
|
2015-04-06 16:42:49 +00:00
|
|
|
} );
|