2015-04-07 14:30:07 +00:00
|
|
|
define( [
|
2016-04-03 16:21:57 +00:00
|
|
|
"qunit",
|
2015-04-07 14:30:07 +00:00
|
|
|
"jquery",
|
|
|
|
"lib/helper",
|
2015-07-15 01:59:40 +00:00
|
|
|
"ui/widgets/draggable"
|
2016-04-03 16:21:57 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2015-04-06 16:42:49 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
return $.extend( helper, {
|
2015-04-06 16:42:49 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testDragPosition: function( assert, el, dx, dy, expectedDX, expectedDY, msg ) {
|
2013-10-21 14:59:54 +00:00
|
|
|
msg = msg ? msg + "." : "";
|
|
|
|
|
|
|
|
$( el ).one( "dragstop", function( event, ui ) {
|
|
|
|
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-10-21 14:59:54 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testDragOffset: function( assert, el, dx, dy, expectedDX, expectedDY, msg ) {
|
2013-10-20 12:55:02 +00:00
|
|
|
msg = msg ? msg + "." : "";
|
|
|
|
|
2014-02-17 21:08:41 +00:00
|
|
|
var offsetBefore = el.offset(),
|
|
|
|
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
|
|
|
|
|
|
|
$( el ).one( "dragstop", function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-02-17 21:08:41 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testDragHelperOffset: function( assert, el, dx, dy, expectedDX, expectedDY, msg ) {
|
2014-02-17 21:08:41 +00:00
|
|
|
msg = msg ? msg + "." : "";
|
|
|
|
|
2013-10-21 14:59:54 +00:00
|
|
|
var offsetBefore = el.offset(),
|
2013-10-20 12:55:02 +00:00
|
|
|
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
|
|
|
|
2013-10-23 15:04:10 +00:00
|
|
|
$( el ).one( "dragstop", function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-10-21 14:59:54 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testDrag: function( assert, el, handle, dx, dy, expectedDX, expectedDY, msg ) {
|
|
|
|
this.testDragPosition( assert, el, dx, dy, expectedDX, expectedDY, msg );
|
|
|
|
this.testDragOffset( assert, el, dx, dy, expectedDX, expectedDY, msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2012-12-09 02:27:37 +00:00
|
|
|
$( handle ).simulate( "drag", {
|
|
|
|
dx: dx,
|
2013-11-01 01:41:45 +00:00
|
|
|
dy: dy
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-10-21 14:59:54 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
shouldMovePositionButNotOffset: function( assert, el, msg, handle ) {
|
2013-10-21 14:59:54 +00:00
|
|
|
handle = handle || el;
|
2016-04-03 16:21:57 +00:00
|
|
|
this.testDragPosition( assert, el, 100, 100, 100, 100, msg );
|
|
|
|
this.testDragHelperOffset( assert, el, 100, 100, 0, 0, msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-10-21 14:59:54 +00:00
|
|
|
$( handle ).simulate( "drag", {
|
|
|
|
dx: 100,
|
2013-11-01 01:41:45 +00:00
|
|
|
dy: 100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
shouldMove: function( assert, el, msg, handle ) {
|
2013-10-20 13:35:12 +00:00
|
|
|
handle = handle || el;
|
2016-04-03 16:21:57 +00:00
|
|
|
this.testDrag( assert, el, handle, 100, 100, 100, 100, msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
shouldNotMove: function( assert, el, msg, handle ) {
|
2013-10-20 13:35:12 +00:00
|
|
|
handle = handle || el;
|
2016-04-03 16:21:57 +00:00
|
|
|
this.testDrag( assert, el, handle, 100, 100, 0, 0, msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
shouldNotDrag: function( assert, el, msg, handle ) {
|
2013-10-21 14:59:54 +00:00
|
|
|
handle = handle || el;
|
2014-08-22 15:51:15 +00:00
|
|
|
|
|
|
|
var newOffset,
|
|
|
|
element = $( el ),
|
|
|
|
beginOffset = element.offset();
|
|
|
|
|
2015-05-14 01:57:47 +00:00
|
|
|
element.on( "dragstop", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( false, "should not drag " + msg );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 15:51:15 +00:00
|
|
|
|
2013-10-21 14:59:54 +00:00
|
|
|
$( handle ).simulate( "drag", {
|
|
|
|
dx: 100,
|
|
|
|
dy: 100
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-22 15:51:15 +00:00
|
|
|
|
|
|
|
newOffset = element.offset();
|
|
|
|
|
|
|
|
// Also assert that draggable did not move, to ensure it isn't just
|
|
|
|
// that drag did not fire and draggable still somehow moved
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( newOffset.left, beginOffset.left, "Offset left should not be different" );
|
|
|
|
assert.equal( newOffset.top, beginOffset.top, "Offset top should not be different" );
|
2014-08-22 15:51:15 +00:00
|
|
|
|
2015-05-14 01:57:47 +00:00
|
|
|
element.off( "dragstop" );
|
2013-10-20 12:55:02 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2014-02-17 21:08:41 +00:00
|
|
|
setScrollable: function( what, isScrollable ) {
|
2013-10-23 15:04:10 +00:00
|
|
|
var overflow = isScrollable ? "scroll" : "hidden";
|
2015-08-24 12:59:44 +00:00
|
|
|
$( what ).css( { overflow: overflow, overflowX: overflow, overflowY: overflow } );
|
2013-10-23 15:04:10 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testScroll: function( assert, el, position ) {
|
2013-04-07 16:31:21 +00:00
|
|
|
var oldPosition = $( "#main" ).css( "position" );
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "#main" ).css( { position: position, top: "0px", left: "0px" } );
|
2016-04-03 16:21:57 +00:00
|
|
|
this.shouldMove( assert, el, position + " parent" );
|
2013-04-07 16:31:21 +00:00
|
|
|
$( "#main" ).css( "position", oldPosition );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
restoreScroll: function( what ) {
|
2013-10-20 12:37:34 +00:00
|
|
|
$( what ).scrollTop( 0 ).scrollLeft( 0 );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
setScroll: function( what ) {
|
2013-10-20 12:37:34 +00:00
|
|
|
$( what ).scrollTop( 100 ).scrollLeft( 100 );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2013-04-07 16:31:21 +00:00
|
|
|
border: function( el, side ) {
|
|
|
|
return parseInt( el.css( "border-" + side + "-width" ), 10 ) || 0;
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2013-04-07 16:31:21 +00:00
|
|
|
margin: function( el, side ) {
|
|
|
|
return parseInt( el.css( "margin-" + side ), 10 ) || 0;
|
2013-01-12 05:33:45 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
move: function( el, x, y ) {
|
|
|
|
$( el ).simulate( "drag", {
|
|
|
|
dx: x,
|
|
|
|
dy: y
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2014-02-17 21:08:41 +00:00
|
|
|
trackMouseCss: function( el ) {
|
2015-05-14 01:57:47 +00:00
|
|
|
el.on( "drag", function() {
|
2013-04-07 16:31:21 +00:00
|
|
|
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
},
|
2015-04-07 14:30:07 +00:00
|
|
|
|
2014-02-17 21:08:41 +00:00
|
|
|
trackAppendedParent: function( el ) {
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2013-04-07 16:31:21 +00:00
|
|
|
// TODO: appendTo is currently ignored if helper is original (see #7044)
|
2013-01-12 05:33:45 +00:00
|
|
|
el.draggable( "option", "helper", "clone" );
|
|
|
|
|
2013-04-07 16:31:21 +00:00
|
|
|
// Get what parent is at time of drag
|
2015-08-24 12:59:44 +00:00
|
|
|
el.on( "drag", function( e, ui ) {
|
2013-04-07 16:31:21 +00:00
|
|
|
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
2015-04-07 14:30:07 +00:00
|
|
|
} );
|
2015-04-06 16:42:49 +00:00
|
|
|
|
|
|
|
} );
|