2015-04-06 16:42:49 +00:00
|
|
|
define( function() {
|
|
|
|
|
|
|
|
var draggableTestHelpers = {
|
|
|
|
|
2013-04-07 16:31:21 +00:00
|
|
|
// TODO: remove the unreliable offset hacks
|
2012-11-03 20:17:16 +00:00
|
|
|
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
|
2013-04-07 16:10:59 +00:00
|
|
|
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
|
2014-02-17 21:08:41 +00:00
|
|
|
unreliableContains: (function() {
|
2013-04-07 16:10:59 +00:00
|
|
|
var element = $( "<div>" );
|
|
|
|
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
|
2013-04-08 18:45:09 +00:00
|
|
|
})(),
|
2013-10-21 14:59:54 +00:00
|
|
|
testDragPosition: function( el, dx, dy, expectedDX, expectedDY, msg ) {
|
|
|
|
msg = msg ? msg + "." : "";
|
|
|
|
|
|
|
|
$( el ).one( "dragstop", function( event, ui ) {
|
|
|
|
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
|
|
|
|
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
|
2014-02-17 21:08:41 +00:00
|
|
|
});
|
2013-10-21 14:59:54 +00:00
|
|
|
},
|
|
|
|
testDragOffset: function( 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 ) {
|
|
|
|
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
|
|
|
|
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 ) {
|
|
|
|
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
2014-02-17 21:08:41 +00:00
|
|
|
});
|
2013-10-21 14:59:54 +00:00
|
|
|
},
|
|
|
|
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
|
|
|
|
draggableTestHelpers.testDragOffset( 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
|
2012-12-09 02:27:37 +00:00
|
|
|
});
|
2013-10-21 14:59:54 +00:00
|
|
|
},
|
|
|
|
shouldMovePositionButNotOffset: function( el, msg, handle ) {
|
|
|
|
handle = handle || el;
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.testDragPosition( el, 100, 100, 100, 100, msg );
|
|
|
|
draggableTestHelpers.testDragHelperOffset( 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
|
2013-10-21 14:59:54 +00:00
|
|
|
});
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2013-10-21 14:59:54 +00:00
|
|
|
shouldMove: function( el, msg, handle ) {
|
2013-10-20 13:35:12 +00:00
|
|
|
handle = handle || el;
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.testDrag( el, handle, 100, 100, 100, 100, msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2013-10-21 14:59:54 +00:00
|
|
|
shouldNotMove: function( el, msg, handle ) {
|
2013-10-20 13:35:12 +00:00
|
|
|
handle = handle || el;
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.testDrag( el, handle, 100, 100, 0, 0, msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2013-10-21 14:59:54 +00:00
|
|
|
shouldNotDrag: function( el, msg, handle ) {
|
|
|
|
handle = handle || el;
|
2014-08-22 15:51:15 +00:00
|
|
|
|
|
|
|
var newOffset,
|
|
|
|
element = $( el ),
|
|
|
|
beginOffset = element.offset();
|
|
|
|
|
|
|
|
element.bind( "dragstop", function() {
|
2013-10-21 14:59:54 +00:00
|
|
|
ok( false, "should not drag " + msg );
|
2014-02-17 21:08:41 +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
|
|
|
|
});
|
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
|
|
|
|
equal( newOffset.left, beginOffset.left, "Offset left should not be different" );
|
|
|
|
equal( newOffset.top, beginOffset.top, "Offset top should not be different" );
|
|
|
|
|
|
|
|
element.unbind( "dragstop" );
|
2013-10-20 12:55:02 +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";
|
|
|
|
$( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow });
|
|
|
|
},
|
2013-04-07 16:31:21 +00:00
|
|
|
testScroll: function( el, position ) {
|
|
|
|
var oldPosition = $( "#main" ).css( "position" );
|
2013-10-23 15:04:10 +00:00
|
|
|
$( "#main" ).css({ position: position, top: "0px", left: "0px" });
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldMove( el, position + " parent" );
|
2013-04-07 16:31:21 +00:00
|
|
|
$( "#main" ).css( "position", oldPosition );
|
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
|
|
|
},
|
|
|
|
setScroll: function( what ) {
|
2013-10-20 12:37:34 +00:00
|
|
|
$( what ).scrollTop( 100 ).scrollLeft( 100 );
|
2012-11-03 20:17:16 +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
|
|
|
},
|
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
|
|
|
},
|
|
|
|
move: function( el, x, y ) {
|
|
|
|
$( el ).simulate( "drag", {
|
|
|
|
dx: x,
|
|
|
|
dy: y
|
|
|
|
});
|
|
|
|
},
|
2014-02-17 21:08:41 +00:00
|
|
|
trackMouseCss: function( el ) {
|
2013-03-09 13:12:31 +00:00
|
|
|
el.bind( "drag", function() {
|
2013-04-07 16:31:21 +00:00
|
|
|
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
|
|
|
},
|
2014-02-17 21:08:41 +00:00
|
|
|
trackAppendedParent: function( el ) {
|
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
|
2014-08-07 12:19:30 +00:00
|
|
|
el.bind( "drag", function(e, ui) {
|
2013-04-07 16:31:21 +00:00
|
|
|
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
|
2013-01-12 05:33:45 +00:00
|
|
|
});
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
2014-02-17 21:08:41 +00:00
|
|
|
};
|
2015-04-06 16:42:49 +00:00
|
|
|
|
|
|
|
return draggableTestHelpers;
|
|
|
|
|
|
|
|
} );
|