2013-03-04 06:32:23 +00:00
|
|
|
(function( $ ) {
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
module( "draggable: options" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
// TODO: This doesn't actually test whether append happened, possibly remove
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: 'parent' }, default, no clone", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ appendTo: "parent" });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ appendTo: "parent" });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
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
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: Element }, no clone", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
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
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: Selector }, no clone", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ appendTo: "#main" });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ appendTo: "#main" });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: 'parent' }, default", function() {
|
|
|
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
equal( element.draggable( "option", "appendTo" ), "parent" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: Element }", function() {
|
|
|
|
expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var appendTo = $( "#draggable2" ).parent()[ 0 ],
|
|
|
|
element = $( "#draggable1" ).draggable({ appendTo: appendTo });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.data( "last_dragged_parent" ), appendTo );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: jQuery }", function() {
|
|
|
|
expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var appendTo = $( "#draggable2" ).parent(),
|
|
|
|
element = $( "#draggable1" ).draggable({ appendTo: appendTo });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.data( "last_dragged_parent" ), appendTo[ 0 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ appendTo: Selector }", function() {
|
|
|
|
expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var appendTo = "#main",
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ appendTo: appendTo });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.trackAppendedParent( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.data( "last_dragged_parent" ), $(appendTo)[ 0 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "appendTo, default, switching after initialization", function() {
|
|
|
|
expect( 2 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ helper : "clone" });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.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
|
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 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
|
|
|
|
element.draggable( "option", "appendTo", $( "#main" ) );
|
|
|
|
TestHelpers.draggable.move( element, 2, 2 );
|
|
|
|
equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ axis: false }, default", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ axis: false });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ axis: 'x' }", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ axis: "x" });
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0 );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ axis: 'y' }", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ axis: "y" });
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50 );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ axis: ? }, unexpected", function() {
|
|
|
|
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
|
|
|
|
|
|
|
expect( 6 );
|
|
|
|
|
2009-02-01 00:25:58 +00:00
|
|
|
$.each(unexpected, function(key, val) {
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({ axis: val });
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50, "axis: " + key );
|
|
|
|
element.draggable( "destroy" );
|
2012-04-19 14:27:06 +00:00
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "axis, default, switching after initialization", function() {
|
|
|
|
expect( 3 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +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
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Only horizontal
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "axis", "x" );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Vertical only
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "axis", "y" );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ cancel: 'input,textarea,button,select,option' }, default", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
|
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable-option-cancel-default input", 50, 50, 0, 0 );
|
|
|
|
element.draggable( "destroy" );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ cancel: 'span' }", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable();
|
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50 );
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({ cancel: "span" });
|
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 0, 0 );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "{ cancel: ? }, unexpected", function() {
|
|
|
|
expect( 6 );
|
|
|
|
|
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 ) {
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({ cancel: val });
|
|
|
|
TestHelpers.draggable.shouldMove( element, "cancel: " + key );
|
|
|
|
element.draggable( "destroy" );
|
2012-04-19 14:27:06 +00:00
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
/**
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ cancel: Selectors }, matching parent selector", function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
expect( 5 );
|
|
|
|
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span child" );
|
|
|
|
TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ) );
|
|
|
|
TestHelpers.draggable.shouldNotMove( $( "#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
|
|
|
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, $( "#draggable2 span a" ).last(), 50, 50, 50, 50, "drag span child" );
|
|
|
|
TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ).first() );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
2013-01-12 05:33:45 +00:00
|
|
|
*/
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "cancelement, default, switching after initialization", function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" );
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, input, 50, 50, 0, 0 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cancel", "textarea" );
|
|
|
|
TestHelpers.draggable.testDrag( element, input, 50, 50, 50, 50 );
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "cancel", "input" );
|
|
|
|
TestHelpers.draggable.testDrag( element, input, 50, 50, 0, 0 );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ connectToSortable: selector }, default", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
ok(false, "missing test - untested code is broken code" );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
2012-10-30 23:12:17 +00:00
|
|
|
*/
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "{ containment: Element }", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetAfter,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ containment: $( "#draggable1" ).parent()[ 0 ] }),
|
|
|
|
p = element.parent(),
|
2012-04-19 14:27:06 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2013-03-04 06:32:23 +00:00
|
|
|
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
|
|
|
|
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.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
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
|
|
|
deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "{ containment: Selector }", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetAfter,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ containment: $( "#qunit-fixture" ) }),
|
|
|
|
p = element.parent(),
|
2012-04-19 14:27:06 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2013-03-04 06:32:23 +00:00
|
|
|
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
|
|
|
|
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.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
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
|
|
|
deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "{ containment: [x1, y1, x2, y2] }", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0 );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ containment: 'parent' }, relative", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var offsetAfter,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ containment: "parent" }),
|
|
|
|
p = element.parent(),
|
2013-01-12 05:33:45 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2013-03-04 06:32:23 +00:00
|
|
|
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
|
|
|
|
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.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
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
|
|
|
deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ containment: 'parent' }, absolute", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var offsetAfter,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({ containment: "parent" }),
|
|
|
|
p = element.parent(),
|
2013-01-12 05:33:45 +00:00
|
|
|
po = p.offset(),
|
|
|
|
expected = {
|
2013-03-04 06:32:23 +00:00
|
|
|
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
|
|
|
|
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.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
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
offsetAfter = element.offset();
|
|
|
|
deepEqual( offsetAfter, expected, "compare offset to parent" );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
|
|
|
|
2013-01-26 20:31:27 +00:00
|
|
|
test( "containment, account for border", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var el = $("#draggable1").appendTo("#main"),
|
|
|
|
parent = el.parent().css({
|
|
|
|
height: "100px",
|
|
|
|
width: "100px",
|
|
|
|
borderStyle: "solid",
|
|
|
|
borderWidth: "5px 10px 15px 20px"
|
|
|
|
}),
|
|
|
|
parentBottom = parent.offset().top + parent.outerHeight(),
|
|
|
|
parentRight = parent.offset().left + parent.outerWidth(),
|
|
|
|
parentBorderBottom = TestHelpers.draggable.border( parent, "bottom" ),
|
|
|
|
parentBorderRight = TestHelpers.draggable.border( parent, "right" );
|
|
|
|
|
|
|
|
el.css({
|
|
|
|
height: "5px",
|
|
|
|
width: "5px"
|
|
|
|
}).draggable({ containment: "parent" });
|
|
|
|
|
|
|
|
el.simulate( "drag", {
|
|
|
|
dx: 100,
|
|
|
|
dy: 100
|
|
|
|
});
|
|
|
|
|
|
|
|
equal( el.offset().top, parentBottom - parentBorderBottom - el.height(),
|
|
|
|
"The draggable should be on top of its parent's bottom border" );
|
|
|
|
equal( el.offset().left, parentRight - parentBorderRight - el.width(),
|
|
|
|
"The draggable should be to the right of its parent's right border" );
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "containment, default, switching after initialization", function() {
|
2013-03-23 02:12:52 +00:00
|
|
|
expect( 3 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ containment: false });
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "containment", "parent" )
|
|
|
|
.css({
|
|
|
|
top: 0,
|
|
|
|
left: 0
|
|
|
|
})
|
|
|
|
.appendTo( $( "#main" ) );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-23 02:12:52 +00:00
|
|
|
element.draggable( "option", "containment", false );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100 );
|
2010-07-15 17:16:07 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ cursor: 'auto' }, default", function() {
|
|
|
|
function getCursor() {
|
|
|
|
return $( "#draggable2" ).css( "cursor" );
|
|
|
|
}
|
2009-02-01 01:54:28 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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",
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({
|
2012-12-09 02:27:37 +00:00
|
|
|
cursor: expected,
|
|
|
|
start: function() {
|
|
|
|
actual = getCursor();
|
|
|
|
}
|
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
|
|
|
|
});
|
2009-02-01 01:54:28 +00:00
|
|
|
after = getCursor();
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
equal( actual, expected, "start callback: cursor '" + expected + "'" );
|
|
|
|
equal( after, before, "after drag: cursor restored" );
|
2009-02-01 01:54:28 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ cursor: 'move' }", function() {
|
|
|
|
function getCursor() {
|
|
|
|
return $( "body" ).css( "cursor" );
|
|
|
|
}
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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",
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({
|
2012-12-09 02:27:37 +00:00
|
|
|
cursor: expected,
|
|
|
|
start: function() {
|
|
|
|
actual = getCursor();
|
|
|
|
}
|
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
|
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
after = getCursor();
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
equal( actual, expected, "start callback: cursor '" + expected + "'" );
|
|
|
|
equal( after, before, "after drag: cursor restored" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-27 20:47:57 +00:00
|
|
|
test( "#6889: Cursor doesn't revert to pre-dragging state after revert action when original element is removed", function() {
|
|
|
|
function getCursor() {
|
|
|
|
return $( "body" ).css( "cursor" );
|
|
|
|
}
|
|
|
|
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
|
|
|
|
cursor: "move",
|
|
|
|
revert: true,
|
|
|
|
revertDuration: 0,
|
|
|
|
start: function() {
|
|
|
|
notEqual( getCursor(), expected, "start callback: cursor '" + expected + "'" );
|
|
|
|
$( "#wrapper" ).remove();
|
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
equal( getCursor(), expected, "after drag: cursor restored" );
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
expected = getCursor();
|
|
|
|
|
2013-04-14 16:58:42 +00:00
|
|
|
if ( TestHelpers.draggable.unreliableContains ) {
|
|
|
|
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
|
|
|
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
|
|
|
} else {
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: -1,
|
|
|
|
dy: -1
|
|
|
|
});
|
|
|
|
}
|
2013-03-27 20:47:57 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "cursor, default, switching after initialization", function() {
|
|
|
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.trackMouseCss( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
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" );
|
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
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" );
|
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.data( "last_dragged_cursor" ), "ns-resize" );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-01-02 04:16:12 +00:00
|
|
|
test( "cursorAt", function() {
|
|
|
|
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 = {
|
2013-01-02 04:16:12 +00:00
|
|
|
"false": { cursorAt : false },
|
2012-12-22 21:30:27 +00:00
|
|
|
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } },
|
|
|
|
"[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] },
|
2013-01-02 04:16:12 +00:00
|
|
|
"'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
|
2012-12-22 21:30:27 +00:00
|
|
|
"{ 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 ) {
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable" + ( i + 1 ) ).draggable({
|
2012-12-22 21:30:27 +00:00
|
|
|
cursorAt: testData.cursorAt,
|
|
|
|
drag: function( event, ui ) {
|
2013-01-02 04:16:12 +00:00
|
|
|
if( !testData.cursorAt ) {
|
|
|
|
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
|
|
|
|
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
|
|
|
|
} else if( testData.cursorAt.right ) {
|
2012-12-27 15:39:14 +00:00
|
|
|
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
|
2013-01-02 04:16:12 +00:00
|
|
|
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
|
2012-12-22 21:30:27 +00:00
|
|
|
} else {
|
2012-12-22 22:39:36 +00:00
|
|
|
equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" );
|
2012-12-22 21:30:27 +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
|
2012-11-03 20:17:16 +00:00
|
|
|
});
|
2012-12-22 21:30:27 +00:00
|
|
|
});
|
2009-08-03 13:13:13 +00:00
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "cursorAt, switching after initialization", function() {
|
|
|
|
expect( 24 );
|
|
|
|
|
|
|
|
var deltaX = -3,
|
|
|
|
deltaY = -3,
|
|
|
|
tests = {
|
|
|
|
"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 } }
|
|
|
|
};
|
|
|
|
|
|
|
|
$.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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
drag: function( event, ui ) {
|
|
|
|
if( !testData.cursorAt ) {
|
|
|
|
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
|
|
|
|
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
|
|
|
|
} else if( testData.cursorAt.right ) {
|
|
|
|
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
|
|
|
|
} else {
|
|
|
|
equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
|
|
|
|
equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "disabled", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 3 );
|
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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "disabled", true );
|
|
|
|
TestHelpers.draggable.shouldNotMove( element );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "disabled", false );
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ grid: [50, 50] }, relative", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] });
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ grid: [50, 50] }, absolute", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] });
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "grid, switching after initialization", function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
expect( 4 );
|
|
|
|
|
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
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 24, 24, 24, 24 );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 0, 0, 0, 0 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "grid", [ 50,50 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ handle: 'span' }", function() {
|
2013-03-08 15:08:46 +00:00
|
|
|
expect( 3 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ handle: "span" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span" );
|
2013-03-08 15:08:46 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span em", 50, 50, 50, 50, "drag span child" );
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.shouldNotMove( element, "drag element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "handle, default, switching after initialization", function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
expect( 6 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 );
|
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Switch
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "handle", "span" );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 0 );
|
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// And back
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "handle", false );
|
|
|
|
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 );
|
|
|
|
TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "helper, default, switching after initialization", function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable();
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "helper", "clone" );
|
|
|
|
TestHelpers.draggable.shouldNotMove( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "helper", "original" );
|
|
|
|
TestHelpers.draggable.shouldMove( element );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'clone' }, relative", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ helper: "clone" });
|
|
|
|
TestHelpers.draggable.shouldNotMove( element );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'clone' }, absolute", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({ helper: "clone" });
|
|
|
|
TestHelpers.draggable.shouldNotMove( element );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, relative, with scroll offset on parent", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ helper: "original" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, relative, with scroll offset on root", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ helper: "original" });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).draggable({ helper: "original" });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, absolute, with scroll offset on parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, absolute, with scroll offset on root", function() {
|
|
|
|
expect( 3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, fixed, with scroll offset on root", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "relative" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "static" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
|
|
|
TestHelpers.draggable.testScroll( element, "absolute" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'clone' }, absolute", function() {
|
|
|
|
expect( 1 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2012-04-19 14:27:06 +00:00
|
|
|
var helperOffset = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
origOffset = $( "#draggable1" ).offset(),
|
|
|
|
element = $( "#draggable1" ).draggable({ helper: "clone", drag: function( event, ui) {
|
2012-11-03 20:17:16 +00:00
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
} });
|
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
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'clone' }, absolute with scroll offset on parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
|
|
|
TestHelpers.draggable.setScroll();
|
2012-04-19 14:27:06 +00:00
|
|
|
var helperOffset = null,
|
2012-11-03 20:17:16 +00:00
|
|
|
origOffset = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({
|
|
|
|
helper: "clone",
|
|
|
|
drag: function( event, ui) {
|
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
}
|
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "relative" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "static" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "absolute" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'clone' }, absolute with scroll offset on root", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
2012-04-19 14:27:06 +00:00
|
|
|
var helperOffset = null,
|
2012-11-03 20:17:16 +00:00
|
|
|
origOffset = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({
|
|
|
|
helper: "clone",
|
|
|
|
drag: function( event, ui) {
|
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
}
|
|
|
|
});
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "relative" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "static" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "absolute" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {
|
|
|
|
expect( 3 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.setScroll( "root" );
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.setScroll();
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var helperOffset = null,
|
|
|
|
origOffset = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({
|
|
|
|
helper: "clone",
|
|
|
|
drag: function( event, ui) {
|
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
}
|
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "relative" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "static" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#main" ).css( "position", "absolute" );
|
|
|
|
origOffset = $( "#draggable1" ).offset();
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 1,
|
|
|
|
dy: 1
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.restoreScroll( "root" );
|
2012-10-30 23:12:17 +00:00
|
|
|
TestHelpers.draggable.restoreScroll();
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ opacity: 0.5 }", function() {
|
|
|
|
expect( 1 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-12-09 02:27:37 +00:00
|
|
|
var opacity = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({
|
2012-12-09 02:27:37 +00:00
|
|
|
opacity: 0.5,
|
|
|
|
start: function() {
|
2013-03-04 06:32:23 +00:00
|
|
|
opacity = $(this).css( "opacity" );
|
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
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
equal( opacity, 0.5, "start callback: opacity is" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "opacity, default, switching after initialization", function() {
|
|
|
|
expect( 3 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var opacity = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
start: function() {
|
2013-03-04 06:32:23 +00:00
|
|
|
opacity = $(this).css( "opacity" );
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( opacity, 1 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "opacity", 0.5 );
|
|
|
|
TestHelpers.draggable.move( element, 2, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( opacity, 0.5 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "opacity", false );
|
|
|
|
TestHelpers.draggable.move( element, 3, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( opacity, 1 );
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest( "revert and revertDuration", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
revert: true,
|
|
|
|
revertDuration: 0
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.shouldNotMove( element, "revert: true, revertDuration: 0 should revert immediately" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#draggable2" ).draggable( "option", "revert", "invalid" );
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.shouldNotMove( element, "revert: invalid, revertDuration: 0 should revert immediately" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#draggable2" ).draggable( "option", "revert", false );
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.shouldMove( element, "revert: false should allow movement" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
$( "#draggable2" ).draggable( "option", {
|
|
|
|
revert: true,
|
|
|
|
revertDuration: 200,
|
|
|
|
stop: function() {
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
});
|
2013-03-04 06:32:23 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
// animation are async, so test for it asynchronously
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 50, 50 );
|
2013-01-12 05:33:45 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "revert: valid", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
revert: "valid",
|
|
|
|
revertDuration: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#droppable" ).droppable();
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, 100, 100, 0, 0, "revert: valid reverts when dropped on a droppable" );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "scope", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
var element = $( "#draggable2" ).draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
scope: "tasks",
|
|
|
|
revert: "valid",
|
|
|
|
revertDuration: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#droppable" ).droppable({ scope: "tasks" });
|
|
|
|
|
2013-03-26 13:18:58 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, 100, 100, 0, 0, "revert: valid reverts when dropped on a droppable in scope" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
$( "#droppable" ).droppable( "destroy" ).droppable({ scope: "nottasks" });
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-26 13:18:58 +00:00
|
|
|
TestHelpers.draggable.testDrag( element, element, 100, 100, 100, 100, "revert: valid reverts when dropped on a droppable out of scope" );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "scroll, scrollSensitivity, and scrollSpeed", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var viewportHeight = $( window ).height(),
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({ scroll: true }),
|
|
|
|
scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
|
|
|
|
scrollSpeed = element.draggable( "option", "scrollSpeed" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.offset({
|
2013-01-12 05:33:45 +00:00
|
|
|
top: viewportHeight - scrollSensitivity - 1,
|
|
|
|
left: 1
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
ok( $( window ).scrollTop() === 0, "scroll: true doesn't scroll when the element is dragged outside of scrollSensitivity" );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "scrollSensitivity", scrollSensitivity + 10 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.offset({
|
2013-01-12 05:33:45 +00:00
|
|
|
top: viewportHeight - scrollSensitivity - 1,
|
|
|
|
left: 1
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
ok( $( window ).scrollTop() === scrollSpeed, "scroll: true scrolls when the element is dragged within scrollSensitivity" );
|
|
|
|
|
|
|
|
TestHelpers.draggable.restoreScroll( document );
|
|
|
|
});
|
|
|
|
|
2013-03-14 18:21:24 +00:00
|
|
|
test( "#6817: auto scroll goes double distance when dragging", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var offsetBefore,
|
|
|
|
distance = 10,
|
|
|
|
viewportHeight = $( window ).height(),
|
|
|
|
element = $( "#draggable1" ).draggable({
|
|
|
|
scroll: true,
|
|
|
|
stop: function( e, ui ) {
|
|
|
|
equal( ui.offset.top, newY, "offset of item matches pointer position after scroll" );
|
2013-03-31 16:19:43 +00:00
|
|
|
// TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal
|
|
|
|
closeEnough( ui.offset.top - offsetBefore.top, distance, 1, "offset of item only moves expected distance after scroll" );
|
2013-03-14 18:21:24 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
|
|
|
|
oldY = viewportHeight - scrollSensitivity,
|
|
|
|
newY = oldY + distance;
|
|
|
|
|
|
|
|
element.offset({
|
|
|
|
top: oldY,
|
|
|
|
left: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
offsetBefore = element.offset();
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
dx: 1,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
TestHelpers.draggable.restoreScroll( document );
|
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "snap, snapMode, and snapTolerance", function() {
|
2013-03-31 16:19:43 +00:00
|
|
|
expect( 10 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
var newX, newY,
|
|
|
|
snapTolerance = 15,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable1" ).draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
snap: true,
|
|
|
|
snapMode: "both",
|
|
|
|
snapTolerance: snapTolerance
|
|
|
|
}),
|
|
|
|
element2 = $( "#draggable2" ).draggable();
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.offset({
|
2013-01-12 05:33:45 +00:00
|
|
|
top: 1,
|
|
|
|
left: 1
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-31 16:19:43 +00:00
|
|
|
// TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal
|
|
|
|
closeEnough( element.offset().left, newX, 1, "doesn't snap outside the snapTolerance" );
|
|
|
|
closeEnough( 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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap on the inner snapTolerance area when snapMode is outer" );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
|
2013-03-16 18:36:06 +00:00
|
|
|
test( "#8459: element can snap to an element that was removed during drag", function() {
|
2013-03-31 16:19:43 +00:00
|
|
|
expect( 2 );
|
2013-03-16 18:36:06 +00:00
|
|
|
|
|
|
|
var newX, newY,
|
|
|
|
snapTolerance = 15,
|
|
|
|
element = $( "#draggable1" ).draggable({
|
|
|
|
snap: true,
|
|
|
|
snapMode: "both",
|
|
|
|
snapTolerance: snapTolerance,
|
|
|
|
start: function() {
|
|
|
|
element2.remove();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
element2 = $( "#draggable2" ).draggable();
|
|
|
|
|
|
|
|
element.offset({
|
|
|
|
top: 1,
|
|
|
|
left: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
|
|
|
|
newY = element2.offset().top;
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
y: newY,
|
|
|
|
moves: 1
|
|
|
|
});
|
|
|
|
|
2013-04-07 16:10:59 +00:00
|
|
|
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
|
|
|
|
if ( TestHelpers.draggable.unreliableContains ) {
|
|
|
|
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
|
|
|
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
|
|
|
} else {
|
|
|
|
// TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal
|
|
|
|
closeEnough( element.offset().left, newX, 1, "doesn't snap to a removed element" );
|
|
|
|
closeEnough( element.offset().top, newY, 1, "doesn't snap to a removed element" );
|
|
|
|
}
|
2013-03-16 18:36:06 +00:00
|
|
|
});
|
|
|
|
|
2012-10-29 08:55:54 +00:00
|
|
|
test( "#8165: Snapping large rectangles to small rectangles doesn't snap properly", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var snapTolerance = 20,
|
|
|
|
y = 1,
|
|
|
|
element = $( "#draggable1" )
|
|
|
|
.css({
|
|
|
|
width: "50px",
|
|
|
|
height: "200px"
|
|
|
|
}).offset({
|
|
|
|
top: y,
|
|
|
|
left: 1
|
|
|
|
}),
|
|
|
|
element2 = $( "#draggable2" )
|
|
|
|
.css({
|
|
|
|
width: "50px",
|
|
|
|
height: "50px"
|
|
|
|
}).offset({
|
|
|
|
top: y + snapTolerance + 1,
|
|
|
|
left: 200
|
|
|
|
}),
|
|
|
|
newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
|
|
|
|
|
|
|
|
$( "#draggable1, #draggable2" ).draggable({
|
|
|
|
snap: true,
|
|
|
|
snapTolerance: snapTolerance
|
|
|
|
});
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
x: newX,
|
|
|
|
moves: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
notDeepEqual( element.offset(), { top: y, left: newX }, "snaps even if only a side (not a corner) is inside the snapTolerance" );
|
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "stack", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var element = $( "#draggable1" ).draggable({
|
|
|
|
stack: "#draggable1, #draggable2"
|
|
|
|
}),
|
|
|
|
element2 = $( "#draggable2" ).draggable({
|
|
|
|
stack: "#draggable1, #draggable2"
|
|
|
|
});
|
|
|
|
|
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
|
|
|
equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" );
|
|
|
|
|
|
|
|
TestHelpers.draggable.move( element2, 1, 1 );
|
|
|
|
equal( element2.css( "zIndex" ), "3", "stack increments zIndex correctly" );
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "{ zIndex: 10 }", function() {
|
|
|
|
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,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({
|
2012-12-09 02:27:37 +00:00
|
|
|
zIndex: expected,
|
|
|
|
start: function() {
|
2013-03-04 06:32:23 +00:00
|
|
|
actual = $(this).css( "zIndex" );
|
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
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
equal( actual, expected, "start callback: zIndex is" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
test( "zIndex, default, switching after initialization", function() {
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
expect( 3 );
|
2013-02-12 04:29:48 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var zindex = null,
|
2013-03-04 06:32:23 +00:00
|
|
|
element = $( "#draggable2" ).draggable({
|
2013-01-12 05:33:45 +00:00
|
|
|
start: function() {
|
2013-03-04 06:32:23 +00:00
|
|
|
zindex = $(this).css( "z-index" );
|
2013-01-12 05:33:45 +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
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
TestHelpers.draggable.move( element, 1, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( zindex, 1 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "zIndex", 5 );
|
|
|
|
TestHelpers.draggable.move( element, 2, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( zindex, 5 );
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
element.draggable( "option", "zIndex", false );
|
|
|
|
TestHelpers.draggable.move( element, 3, 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( zindex, 1 );
|
2013-02-12 04:29:48 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-03-04 06:32:23 +00:00
|
|
|
})( jQuery );
|