2012-11-03 20:17:16 +00:00
|
|
|
TestHelpers.draggable = {
|
|
|
|
// todo: remove the unreliable offset hacks
|
|
|
|
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
|
|
|
|
testDrag: function(el, handle, dx, dy, expectedDX, expectedDY, msg) {
|
|
|
|
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 + "." : "";
|
2012-12-26 13:08:48 +00:00
|
|
|
deepEqual(actual, expected, "dragged[" + dx + ", " + dy + "] " + msg);
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
|
|
|
shouldMove: function(el, why) {
|
|
|
|
TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 50, why);
|
|
|
|
},
|
|
|
|
shouldNotMove: function(el, why) {
|
|
|
|
TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 0, why);
|
|
|
|
},
|
|
|
|
testScroll: function(el, position ) {
|
2012-12-26 13:08:48 +00:00
|
|
|
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 ) {
|
|
|
|
$(document).scrollTop(0); $(document).scrollLeft(0);
|
|
|
|
} else {
|
|
|
|
$("#main").scrollTop(0); $("#main").scrollLeft(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setScroll: function( what ) {
|
|
|
|
if(what) {
|
|
|
|
// todo: currently, the draggable interaction doesn't properly account for scrolled pages,
|
|
|
|
// uncomment the line below to make the tests fail that should when the page is scrolled
|
|
|
|
// $(document).scrollTop(100); $(document).scrollLeft(100);
|
|
|
|
} else {
|
|
|
|
$("#main").scrollTop(100); $("#main").scrollLeft(100);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
border: function(el, side) {
|
2012-12-26 13:08:48 +00:00
|
|
|
return parseInt(el.css("border-" + side + "-width"), 10) || 0;
|
2012-11-03 20:17:16 +00:00
|
|
|
},
|
|
|
|
margin: function(el, side) {
|
2012-12-26 13:08:48 +00:00
|
|
|
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-01-12 05:33:45 +00:00
|
|
|
el.data( "last_dragged_cursor", $("body").css("cursor") );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
trackAppendedParent : function( el ) {
|
|
|
|
|
|
|
|
// appendTo ignored without being clone
|
|
|
|
el.draggable( "option", "helper", "clone" );
|
|
|
|
|
2013-03-09 13:12:31 +00:00
|
|
|
el.bind( "drag", function(e,ui) {
|
2013-01-12 05:33:45 +00:00
|
|
|
// Get what parent is at time of drag
|
|
|
|
el.data( "last_dragged_parent", ui.helper.parent()[0] );
|
|
|
|
});
|
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
|
|
|
};
|