imported the whole jquery-ui package, refreshed with 1.10.2
[myslice.git] / third-party / jquery-ui-1.10.2 / tests / unit / draggable / draggable_test_helpers.js
1 TestHelpers.draggable = {
2         // todo: remove the unreliable offset hacks
3         unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
4         testDrag: function(el, handle, dx, dy, expectedDX, expectedDY, msg) {
5                 var offsetAfter, actual, expected,
6                         offsetBefore = el.offset();
7
8                 $( handle ).simulate( "drag", {
9                         dx: dx,
10                         dy: dy
11                 });
12                 offsetAfter = el.offset();
13
14                 actual = { left: offsetAfter.left, top: offsetAfter.top };
15                 expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
16
17                 msg = msg ? msg + "." : "";
18                 deepEqual(actual, expected, "dragged[" + dx + ", " + dy + "] " + msg);
19         },
20         shouldMove: function(el, why) {
21                 TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 50, why);
22         },
23         shouldNotMove: function(el, why) {
24                 TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 0, why);
25         },
26         testScroll: function(el, position ) {
27                 var oldPosition = $("#main").css("position");
28                 $("#main").css("position", position);
29                 TestHelpers.draggable.shouldMove(el, position+" parent");
30                 $("#main").css("position", oldPosition);
31         },
32         restoreScroll: function( what ) {
33                 if( what ) {
34                         $(document).scrollTop(0); $(document).scrollLeft(0);
35                 } else {
36                         $("#main").scrollTop(0); $("#main").scrollLeft(0);
37                 }
38         },
39         setScroll: function( what ) {
40                 if(what) {
41                         // todo: currently, the draggable interaction doesn't properly account for scrolled pages,
42                         // uncomment the line below to make the tests fail that should when the page is scrolled
43                         // $(document).scrollTop(100); $(document).scrollLeft(100);
44                 } else {
45                         $("#main").scrollTop(100); $("#main").scrollLeft(100);
46                 }
47         },
48         border: function(el, side) {
49                 return parseInt(el.css("border-" + side + "-width"), 10) || 0;
50         },
51         margin: function(el, side) {
52                 return parseInt(el.css("margin-" + side), 10) || 0;
53         },
54         move: function( el, x, y ) {
55
56                 $( el ).simulate( "drag", {
57                         dx: x,
58                         dy: y
59                 });
60
61         },
62         trackMouseCss : function( el ) {
63                 el.bind( "drag", function() {
64                         el.data( "last_dragged_cursor", $("body").css("cursor") );
65                 });
66         },
67         trackAppendedParent : function( el ) {
68
69                 // appendTo ignored without being clone
70                 el.draggable( "option", "helper", "clone" );
71
72                 el.bind( "drag", function(e,ui) {
73                         // Get what parent is at time of drag
74                         el.data( "last_dragged_parent", ui.helper.parent()[0] );
75                 });
76
77         }
78 };