2009-02-01 00:25:58 +00:00
|
|
|
/*
|
|
|
|
* draggable_events.js
|
|
|
|
*/
|
2013-01-12 05:33:45 +00:00
|
|
|
(function( $ ) {
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var element;
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
module( "draggable: events", {
|
|
|
|
setup: function() {
|
|
|
|
element = $("<div>").appendTo("#qunit-fixture");
|
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
element.draggable("destroy");
|
|
|
|
}
|
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "callbacks occurrence count", function() {
|
|
|
|
expect( 3 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var start = 0,
|
|
|
|
stop = 0,
|
2013-01-12 05:33:45 +00:00
|
|
|
dragc = 0;
|
|
|
|
|
|
|
|
element.draggable({
|
|
|
|
start: function() {
|
|
|
|
start++;
|
|
|
|
},
|
|
|
|
drag: function() {
|
|
|
|
dragc++;
|
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
stop++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 10,
|
|
|
|
dy: 10
|
|
|
|
});
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( start, 1, "start callback should happen exactly once" );
|
|
|
|
equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
|
|
|
|
equal( stop, 1, "stop callback should happen exactly once" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "stopping the start callback", function() {
|
|
|
|
expect( 3 );
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var start = 0,
|
|
|
|
stop = 0,
|
2013-01-12 05:33:45 +00:00
|
|
|
dragc = 0;
|
|
|
|
|
|
|
|
element.draggable({
|
|
|
|
start: function() {
|
|
|
|
start++;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
drag: function() {
|
|
|
|
dragc++;
|
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
stop++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 10,
|
|
|
|
dy: 10
|
|
|
|
});
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( start, 1, "start callback should happen exactly once" );
|
|
|
|
equal( dragc, 0, "drag callback should not happen at all" );
|
|
|
|
equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
|
2010-01-28 16:35:59 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "stopping the drag callback", function() {
|
|
|
|
expect( 2 );
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var start = 0,
|
|
|
|
stop = 0,
|
2013-01-12 05:33:45 +00:00
|
|
|
dragc = 0;
|
|
|
|
|
|
|
|
element.draggable({
|
|
|
|
start: function() {
|
|
|
|
start++;
|
|
|
|
},
|
|
|
|
drag: function() {
|
|
|
|
dragc++;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
stop++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 10,
|
|
|
|
dy: 10
|
|
|
|
});
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( start, 1, "start callback should happen exactly once" );
|
|
|
|
equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
|
2010-01-28 16:35:59 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "stopping the stop callback", function() {
|
|
|
|
expect( 1 );
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable({
|
2012-12-26 13:08:48 +00:00
|
|
|
helper: "clone",
|
2013-01-12 05:33:45 +00:00
|
|
|
stop: function() {
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-28 16:35:59 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
dx: 10,
|
|
|
|
dy: 10
|
|
|
|
});
|
2010-01-28 16:35:59 +00:00
|
|
|
|
2013-03-19 15:53:35 +00:00
|
|
|
ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
|
2010-01-28 16:35:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
})( jQuery );
|