2009-02-02 05:58:49 +00:00
|
|
|
/*
|
|
|
|
* slider_events.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-03-17 15:04:14 +00:00
|
|
|
module( "slider: events" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
//Specs from http://wiki.jqueryui.com/Slider#specs
|
|
|
|
//"change callback: triggers when the slider has stopped moving and has a new
|
|
|
|
// value (even if same as previous value), via mouse(mouseup) or keyboard(keyup)
|
|
|
|
// or value method/option"
|
2010-03-27 00:44:14 +00:00
|
|
|
test( "mouse based interaction", function() {
|
|
|
|
expect(4);
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-07-17 19:04:16 +00:00
|
|
|
var el = $( "#slider1" )
|
2010-03-17 15:31:17 +00:00
|
|
|
.slider({
|
2012-10-23 14:36:42 +00:00
|
|
|
start: function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "mousedown", "start triggered by mousedown" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
slide: function( event) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "mousemove", "slider triggered by mousemove" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
stop: function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "mouseup", "stop triggered by mouseup" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "mouseup", "change triggered by mouseup" );
|
2010-03-17 15:31:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
el.find( ".ui-slider-handle" ).eq( 0 )
|
|
|
|
.simulate( "drag", { dx: 10, dy: 10 } );
|
|
|
|
|
2010-03-27 00:44:14 +00:00
|
|
|
});
|
|
|
|
test( "keyboard based interaction", function() {
|
|
|
|
expect(3);
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
// Test keyup at end of handle slide (keyboard)
|
2012-07-17 19:04:16 +00:00
|
|
|
var el = $( "#slider1" )
|
2010-03-17 15:31:17 +00:00
|
|
|
.slider({
|
2012-10-23 14:36:42 +00:00
|
|
|
start: function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "keydown", "start triggered by keydown" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
slide: function() {
|
2010-03-27 00:44:14 +00:00
|
|
|
ok( false, "Slider never triggered by keys" );
|
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
stop: function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "keyup", "stop triggered by keyup" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( event.originalEvent.type, "keyup", "change triggered by keyup" );
|
2010-03-17 15:31:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
el.find( ".ui-slider-handle" ).eq( 0 )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } )
|
|
|
|
.simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } )
|
2010-03-17 17:39:29 +00:00
|
|
|
.simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } );
|
2010-03-17 15:31:17 +00:00
|
|
|
|
2010-03-27 00:44:14 +00:00
|
|
|
});
|
|
|
|
test( "programmatic event triggers", function() {
|
|
|
|
expect(6);
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
// Test value method
|
2010-03-27 00:44:14 +00:00
|
|
|
var el = $( "<div></div>" )
|
2010-03-17 15:31:17 +00:00
|
|
|
.slider({
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2010-03-17 15:31:17 +00:00
|
|
|
ok( true, "change triggered by value method" );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.slider( "value", 0 );
|
|
|
|
|
2010-03-17 15:58:22 +00:00
|
|
|
// Test values method
|
|
|
|
el = $( "<div></div>" )
|
|
|
|
.slider({
|
|
|
|
values: [ 10, 20 ],
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2010-03-17 15:58:22 +00:00
|
|
|
ok( true, "change triggered by values method" );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.slider( "values", [80, 90] );
|
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
// Test value option
|
|
|
|
el = $( "<div></div>" )
|
|
|
|
.slider({
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2010-03-17 15:31:17 +00:00
|
|
|
ok( true, "change triggered by value option" );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.slider( "option", "value", 0 );
|
|
|
|
|
2010-03-17 15:58:22 +00:00
|
|
|
// Test values option
|
|
|
|
el = $( "<div></div>" )
|
|
|
|
.slider({
|
|
|
|
values: [ 10, 20 ],
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2010-03-17 15:58:22 +00:00
|
|
|
ok( true, "change triggered by values option" );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.slider( "option", "values", [80, 90] );
|
|
|
|
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2012-11-14 01:05:59 +00:00
|
|
|
test( "mouse based interaction part two: when handles overlap", function() {
|
|
|
|
expect(4);
|
|
|
|
|
|
|
|
var el = $( "#slider1" )
|
|
|
|
.slider({
|
|
|
|
values: [ 0, 0, 0 ],
|
|
|
|
start: function( event, ui ) {
|
|
|
|
equal(handles.index(ui.handle), 2, "rightmost handle activated when overlapping at minimum (#3736)");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
handles = el.find( ".ui-slider-handle" );
|
|
|
|
handles.eq(0).simulate( "drag", { dx: 10 } );
|
2012-11-16 16:20:58 +00:00
|
|
|
el.slider( "destroy" );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
|
|
|
el = $( "#slider1" )
|
|
|
|
.slider({
|
|
|
|
values: [ 10, 10, 10 ],
|
|
|
|
max: 10,
|
|
|
|
start: function( event, ui ) {
|
|
|
|
equal(handles.index(ui.handle), 0, "leftmost handle activated when overlapping at maximum");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
handles = el.find( ".ui-slider-handle" );
|
|
|
|
handles.eq(0).simulate( "drag", { dx: -10 } );
|
2012-11-16 16:20:58 +00:00
|
|
|
el.slider( "destroy" );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
|
|
|
el = $( "#slider1" )
|
|
|
|
.slider({
|
|
|
|
values: [ 19, 20 ]
|
|
|
|
}),
|
|
|
|
handles = el.find( ".ui-slider-handle" );
|
|
|
|
handles.eq(0).simulate( "drag", { dx: 10 } );
|
2012-11-16 16:20:58 +00:00
|
|
|
el.one("slidestart", function(event, ui) {
|
2012-11-14 01:05:59 +00:00
|
|
|
equal(handles.index(ui.handle), 0, "left handle activated if left was moved last");
|
|
|
|
});
|
|
|
|
handles.eq(0).simulate( "drag", { dx: 10 } );
|
2012-11-16 16:20:58 +00:00
|
|
|
el.slider( "destroy" );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
|
|
|
el = $( "#slider1" )
|
|
|
|
.slider({
|
|
|
|
values: [ 19, 20 ]
|
|
|
|
}),
|
|
|
|
handles = el.find( ".ui-slider-handle" );
|
|
|
|
handles.eq(1).simulate( "drag", { dx: -10 } );
|
2012-11-16 16:20:58 +00:00
|
|
|
el.one("slidestart", function(event, ui) {
|
2012-11-14 01:05:59 +00:00
|
|
|
equal(handles.index(ui.handle), 1, "right handle activated if right was moved last (#3467)");
|
|
|
|
});
|
|
|
|
handles.eq(0).simulate( "drag", { dx: 10 } );
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2010-03-17 15:04:14 +00:00
|
|
|
}( jQuery ) );
|