2009-02-02 05:58:49 +00:00
|
|
|
/*
|
|
|
|
* slider_options.js
|
|
|
|
*/
|
2013-02-07 14:33:26 +00:00
|
|
|
(function( $ ) {
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
var element, options;
|
2009-09-15 08:25:00 +00:00
|
|
|
|
2009-02-02 05:58:49 +00:00
|
|
|
function handle() {
|
2013-02-07 14:33:26 +00:00
|
|
|
return element.find( ".ui-slider-handle" );
|
2009-02-02 05:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
module( "slider: options" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-01 02:19:52 +00:00
|
|
|
test( "disabled", function(){
|
|
|
|
expect( 8 );
|
|
|
|
var count = 0;
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "#slider1" ).slider();
|
2013-03-02 20:26:18 +00:00
|
|
|
element.bind( "slidestart", function() {
|
2013-02-01 02:19:52 +00:00
|
|
|
count++;
|
|
|
|
});
|
|
|
|
|
|
|
|
// enabled
|
2013-02-07 14:33:26 +00:00
|
|
|
ok( !element.hasClass( "ui-slider-disabled" ), "no disabled class" );
|
|
|
|
equal( element.slider( "option", "disabled" ), false , "is not disabled" );
|
2013-02-01 02:19:52 +00:00
|
|
|
|
|
|
|
handle().simulate( "drag", { dx: 10 } );
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( count, 1, "slider moved" );
|
2013-02-01 02:19:52 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
|
|
|
|
equal( count, 2, "slider moved" );
|
2013-02-01 02:19:52 +00:00
|
|
|
|
|
|
|
// disabled
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "disabled", true );
|
|
|
|
ok( element.hasClass( "ui-slider-disabled" ), "has disabled class" );
|
|
|
|
equal( element.slider( "option", "disabled" ), true, "is disabled" );
|
2013-02-01 02:19:52 +00:00
|
|
|
|
|
|
|
handle().simulate( "drag", { dx: 10 } );
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( count, 2, "slider did not move" );
|
2013-02-01 02:19:52 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
|
|
|
|
equal( count, 2, "slider did not move" );
|
2013-02-01 02:19:52 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "max", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 2 );
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-02 05:58:49 +00:00
|
|
|
options = {
|
|
|
|
max: 37,
|
|
|
|
min: 6,
|
2012-12-26 13:08:48 +00:00
|
|
|
orientation: "horizontal",
|
2009-02-02 05:58:49 +00:00
|
|
|
step: 1,
|
|
|
|
value: 50
|
|
|
|
};
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( options );
|
|
|
|
ok(element.slider( "option", "value" ) === options.value, "value option is not contained by max" );
|
|
|
|
ok(element.slider( "value" ) === options.max, "value method is contained by max" );
|
|
|
|
element.slider( "destroy" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "min", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 2 );
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-02-02 05:58:49 +00:00
|
|
|
options = {
|
|
|
|
max: 37,
|
|
|
|
min: 6,
|
2012-12-26 13:08:48 +00:00
|
|
|
orientation: "vertical",
|
2009-02-02 05:58:49 +00:00
|
|
|
step: 1,
|
|
|
|
value: 2
|
|
|
|
};
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( options );
|
|
|
|
ok( element.slider( "option", "value" ) === options.value, "value option is not contained by min" );
|
|
|
|
ok( element.slider( "value" ) === options.min, "value method is contained by min" );
|
|
|
|
element.slider( "destroy" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "orientation", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 6 );
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "#slider1" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
max: 2,
|
|
|
|
min: -2,
|
2012-12-26 13:08:48 +00:00
|
|
|
orientation: "vertical",
|
2009-02-02 05:58:49 +00:00
|
|
|
value: 1
|
|
|
|
};
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
var percentVal = ( options.value - options.min ) / ( options.max - options.min ) * 100;
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( options ).slider( "option", "orientation", "horizontal" );
|
|
|
|
ok( element.is( ".ui-slider-horizontal" ), "horizontal slider has class .ui-slider-horizontal" );
|
|
|
|
ok( !element.is( ".ui-slider-vertical" ), "horizontal slider does not have class .ui-slider-vertical" );
|
|
|
|
equal( handle()[0].style.left, percentVal + "%", "horizontal slider handle is positioned with left: %" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "destroy" ) ;
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
max: 2,
|
|
|
|
min: -2,
|
2012-12-26 13:08:48 +00:00
|
|
|
orientation: "horizontal",
|
2009-02-02 05:58:49 +00:00
|
|
|
value: -1
|
|
|
|
};
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
percentVal = ( options.value - options.min ) / ( options.max - options.min ) * 100;
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( options ).slider( "option", "orientation", "vertical" );
|
|
|
|
ok( element.is( ".ui-slider-vertical" ), "vertical slider has class .ui-slider-vertical" );
|
|
|
|
ok( !element.is( ".ui-slider-horizontal" ), "vertical slider does not have class .ui-slider-horizontal" );
|
|
|
|
equal( handle()[0].style.bottom, percentVal + "%", "vertical slider handle is positioned with bottom: %" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "destroy" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2010-04-01 19:00:45 +00:00
|
|
|
//spec: http://wiki.jqueryui.com/Slider#specs
|
|
|
|
// value option/method: the value option is not restricted by min/max/step.
|
|
|
|
// What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple)
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "step", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 9 );
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2010-04-01 19:00:45 +00:00
|
|
|
min: 0,
|
|
|
|
value: 0,
|
|
|
|
step: 10,
|
2011-07-25 15:08:03 +00:00
|
|
|
max: 100
|
2010-03-27 01:00:59 +00:00
|
|
|
});
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.slider( "value" ), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "value", 1 );
|
|
|
|
equal( element.slider( "value" ), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "value", 9 );
|
|
|
|
equal( element.slider( "value" ), 10 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "value", 11 );
|
|
|
|
equal( element.slider( "value" ), 10 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "value", 19 );
|
|
|
|
equal( element.slider( "value" ), 20 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2010-04-01 19:00:45 +00:00
|
|
|
min: 0,
|
|
|
|
value: 0,
|
|
|
|
step: 20,
|
2011-07-25 15:08:03 +00:00
|
|
|
max: 100
|
2010-04-01 19:00:45 +00:00
|
|
|
});
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "value", 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", 1 );
|
|
|
|
equal( element.slider( "value" ), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", 9 );
|
|
|
|
equal( element.slider( "value" ), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", 11 );
|
|
|
|
equal( element.slider( "value" ), 20 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", 19 );
|
|
|
|
equal( element.slider( "value" ), 20 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "destroy" );
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
//test( "value", function() {
|
|
|
|
// ok(false, "missing test - untested code is broken code." );
|
2011-07-28 12:29:29 +00:00
|
|
|
//});
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "values", function() {
|
2012-12-06 22:11:23 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
// testing multiple ranges on the same page, the object reference to the values
|
|
|
|
// property is preserved via multiple range elements, so updating options.values
|
|
|
|
// of 1 slider updates options.values of all the others
|
|
|
|
var ranges = $([
|
2013-02-07 14:33:26 +00:00
|
|
|
document.createElement( "div" ),
|
|
|
|
document.createElement( "div" )
|
2012-12-06 22:11:23 +00:00
|
|
|
]).slider({
|
2013-03-02 20:31:38 +00:00
|
|
|
range: true,
|
2012-12-06 22:11:23 +00:00
|
|
|
values: [ 25, 75 ]
|
|
|
|
});
|
|
|
|
|
|
|
|
notStrictEqual(
|
2013-03-02 20:31:38 +00:00
|
|
|
ranges.eq( 0 ).data( "ui-slider" ).options.values,
|
|
|
|
ranges.eq( 1 ).data( "ui-slider" ).options.values,
|
2012-12-06 22:11:23 +00:00
|
|
|
"multiple range sliders should not have a reference to the same options.values array"
|
|
|
|
);
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
ranges.eq( 0 ).slider( "values", 0, 10 );
|
2012-12-06 22:11:23 +00:00
|
|
|
|
|
|
|
notEqual(
|
2013-02-07 14:33:26 +00:00
|
|
|
ranges.eq( 0 ).slider( "values", 0 ),
|
|
|
|
ranges.eq( 1 ).slider( "values", 0 ),
|
2012-12-06 22:11:23 +00:00
|
|
|
"the values for multiple sliders should be different"
|
|
|
|
);
|
|
|
|
});
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
test( "range", function() {
|
|
|
|
expect( 27 );
|
2013-02-07 14:33:26 +00:00
|
|
|
var range;
|
2013-01-30 19:07:33 +00:00
|
|
|
|
|
|
|
// min
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: "min",
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 1, "range min, one handle" );
|
2013-01-30 19:07:33 +00:00
|
|
|
equal( element.find( ".ui-slider-range-min" ).length, 1, "range min" );
|
|
|
|
element.slider( "destroy" );
|
|
|
|
|
|
|
|
// max
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: "max",
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 1, "range max, one handle" );
|
2013-01-30 19:07:33 +00:00
|
|
|
equal( element.find( ".ui-slider-range-max" ).length, 1, "range max" );
|
|
|
|
element.slider( "destroy" );
|
|
|
|
|
|
|
|
// true
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: true,
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
range = element.find( ".ui-slider-range" );
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 2, "range true, two handles" );
|
|
|
|
ok( !range.is( ".ui-slider-range-min" ), "range true" );
|
|
|
|
ok( !range.is( ".ui-slider-range-max" ), "range true" );
|
2013-01-30 19:07:33 +00:00
|
|
|
element.slider( "destroy" );
|
|
|
|
|
|
|
|
// Change range from min to max
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: "min",
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
}).slider( "option", "range", "max" );
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from min to max, one handle" );
|
2013-01-30 19:07:33 +00:00
|
|
|
equal( element.find( ".ui-slider-range-min" ).length, 0, "range switch from min to max" );
|
|
|
|
equal( element.find( ".ui-slider-range-max" ).length, 1, "range switch from min to max" );
|
|
|
|
element.slider( "destroy" );
|
|
|
|
|
|
|
|
// Change range from max to min
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: "max",
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
}).slider( "option", "range", "min" );
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from max to min, one handle" );
|
2013-01-30 19:07:33 +00:00
|
|
|
equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from max to min" );
|
|
|
|
equal( element.find( ".ui-slider-range-min" ).length, 1, "range switch from max to min" );
|
|
|
|
element.slider( "destroy" );
|
|
|
|
|
|
|
|
// Change range from max to true
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: "max",
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
}).slider( "option", "range", true );
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 2, "range switch from max to true, two handles" );
|
2013-01-30 19:07:33 +00:00
|
|
|
equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from max to true" );
|
|
|
|
equal( element.find( ".ui-slider-range-min" ).length, 0, "range switch from max to true" );
|
|
|
|
equal( element.slider( "option", "value" ), 0 , "option value" );
|
|
|
|
equal( element.slider( "value" ), 1 , "value" );
|
|
|
|
deepEqual( element.slider( "option", "values" ), [1, 1], "option values" );
|
|
|
|
deepEqual( element.slider( "values" ), [1, 1], "values" );
|
|
|
|
element.slider( "destroy" );
|
|
|
|
|
|
|
|
// Change range from true to min
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({
|
2013-01-30 19:07:33 +00:00
|
|
|
range: true,
|
|
|
|
min: 1,
|
|
|
|
max: 10,
|
|
|
|
step: 1
|
|
|
|
}).slider( "option", "range", "min" );
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from true to min, one handle" );
|
2013-01-30 19:07:33 +00:00
|
|
|
equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from true to min" );
|
|
|
|
equal( element.find( ".ui-slider-range-min" ).length, 1, "range switch from true to min" );
|
|
|
|
equal( element.slider( "option", "value" ), 1, "value" );
|
|
|
|
equal( element.slider( "value" ), 1 , "value" );
|
|
|
|
equal( element.slider( "option", "values" ), null, "values" );
|
|
|
|
deepEqual( element.slider( "values" ), [] , "values" );
|
|
|
|
element.slider( "destroy" );
|
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
})( jQuery );
|