2012-11-03 20:17:16 +00:00
|
|
|
TestHelpers.draggable = {
|
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
|
2013-04-08 18:45:09 +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-04-07 16:31:21 +00:00
|
|
|
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetAfter, actual, expected,
|
|
|
|
offsetBefore = el.offset();
|
|
|
|
|
2012-12-09 02:27:37 +00:00
|
|
|
$( handle ).simulate( "drag", {
|
|
|
|
dx: dx,
|
|
|
|
dy: dy
|
|
|
|
});
|
2012-11-03 20:17:16 +00:00
|
|
|
offsetAfter = el.offset();
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
actual = { left: offsetAfter.left, top: offsetAfter.top };
|
2012-11-03 20:17:16 +00:00
|
|
|
expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
|
|
|
|
|
|
|
msg = msg ? msg + "." : "";
|
2013-04-07 16:31:21 +00:00
|
|
|
deepEqual( actual, expected, "dragged[" + dx + ", " + dy + "] " + msg );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2013-04-07 16:31:21 +00:00
|
|
|
shouldMove: function( el, why ) {
|
|
|
|
TestHelpers.draggable.testDrag( el, el, 50, 50, 50, 50, why );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2013-04-07 16:31:21 +00:00
|
|
|
shouldNotMove: function( el, why ) {
|
|
|
|
TestHelpers.draggable.testDrag( el, el, 50, 50, 0, 0, why );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
2013-04-07 16:31:21 +00:00
|
|
|
testScroll: function( el, position ) {
|
|
|
|
var oldPosition = $( "#main" ).css( "position" );
|
|
|
|
$( "#main" ).css( "position", position);
|
|
|
|
TestHelpers.draggable.shouldMove( el, position + " parent" );
|
|
|
|
$( "#main" ).css( "position", oldPosition );
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
|
|
|
restoreScroll: function( what ) {
|
|
|
|
if( what ) {
|
2013-04-07 16:31:21 +00:00
|
|
|
$( document ).scrollTop( 0 ).scrollLeft( 0 );
|
2012-11-03 20:17:16 +00:00
|
|
|
} else {
|
2013-04-07 16:31:21 +00:00
|
|
|
$( "#main" ).scrollTop( 0 ).scrollLeft( 0 );
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setScroll: function( what ) {
|
2013-04-07 16:31:21 +00:00
|
|
|
if( what ) {
|
|
|
|
// TODO: currently, the draggable interaction doesn't properly account for scrolled pages,
|
2012-11-03 20:17:16 +00:00
|
|
|
// uncomment the line below to make the tests fail that should when the page is scrolled
|
2013-04-07 16:31:21 +00:00
|
|
|
// $( document ).scrollTop( 100 ).scrollLeft( 100 );
|
2012-11-03 20:17:16 +00:00
|
|
|
} else {
|
2013-04-07 16:31:21 +00:00
|
|
|
$( "#main" ).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
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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
|
|
|
});
|
|
|
|
},
|
|
|
|
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
|
2013-03-09 13:12:31 +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
|
|
|
}
|
|
|
|
};
|