1 |
/* |
2 |
* draggable_events.js |
3 |
*/ |
4 |
(function( $ ) { |
5 |
|
6 |
var element; |
7 |
|
8 |
module( "draggable: events", { |
9 |
setup: function() { |
10 |
element = $("<div>").appendTo("#qunit-fixture"); |
11 |
}, |
12 |
teardown: function() { |
13 |
element.draggable("destroy"); |
14 |
} |
15 |
}); |
16 |
|
17 |
test( "callbacks occurrence count", function() { |
18 |
expect( 3 ); |
19 |
|
20 |
var start = 0, |
21 |
stop = 0, |
22 |
dragc = 0; |
23 |
|
24 |
element.draggable({ |
25 |
start: function() { |
26 |
start++; |
27 |
}, |
28 |
drag: function() { |
29 |
dragc++; |
30 |
}, |
31 |
stop: function() { |
32 |
stop++; |
33 |
} |
34 |
}); |
35 |
|
36 |
element.simulate( "drag", { |
37 |
dx: 10, |
38 |
dy: 10 |
39 |
}); |
40 |
|
41 |
equal( start, 1, "start callback should happen exactly once" ); |
42 |
equal( dragc, 3, "drag callback should happen exactly once per mousemove" ); |
43 |
equal( stop, 1, "stop callback should happen exactly once" ); |
44 |
}); |
45 |
|
46 |
test( "stopping the start callback", function() { |
47 |
expect( 3 ); |
48 |
|
49 |
var start = 0, |
50 |
stop = 0, |
51 |
dragc = 0; |
52 |
|
53 |
element.draggable({ |
54 |
start: function() { |
55 |
start++; |
56 |
return false; |
57 |
}, |
58 |
drag: function() { |
59 |
dragc++; |
60 |
}, |
61 |
stop: function() { |
62 |
stop++; |
63 |
} |
64 |
}); |
65 |
|
66 |
element.simulate( "drag", { |
67 |
dx: 10, |
68 |
dy: 10 |
69 |
}); |
70 |
|
71 |
equal( start, 1, "start callback should happen exactly once" ); |
72 |
equal( dragc, 0, "drag callback should not happen at all" ); |
73 |
equal( stop, 0, "stop callback should not happen if there wasnt even a start" ); |
74 |
}); |
75 |
|
76 |
test( "stopping the drag callback", function() { |
77 |
expect( 2 ); |
78 |
|
79 |
var start = 0, |
80 |
stop = 0, |
81 |
dragc = 0; |
82 |
|
83 |
element.draggable({ |
84 |
start: function() { |
85 |
start++; |
86 |
}, |
87 |
drag: function() { |
88 |
dragc++; |
89 |
return false; |
90 |
}, |
91 |
stop: function() { |
92 |
stop++; |
93 |
} |
94 |
}); |
95 |
|
96 |
element.simulate( "drag", { |
97 |
dx: 10, |
98 |
dy: 10 |
99 |
}); |
100 |
|
101 |
equal( start, 1, "start callback should happen exactly once" ); |
102 |
equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" ); |
103 |
}); |
104 |
|
105 |
test( "stopping the stop callback", function() { |
106 |
expect( 1 ); |
107 |
|
108 |
element.draggable({ |
109 |
helper: "clone", |
110 |
stop: function() { |
111 |
return false; |
112 |
} |
113 |
}); |
114 |
|
115 |
element.simulate( "drag", { |
116 |
dx: 10, |
117 |
dy: 10 |
118 |
}); |
119 |
|
120 |
ok( element.data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped" ); |
121 |
|
122 |
|
123 |
}); |
124 |
|
125 |
})( jQuery ); |