2009-02-02 05:58:49 +00:00
|
|
|
/*
|
|
|
|
* slider_options.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2009-09-15 08:25:00 +00:00
|
|
|
var el, options;
|
|
|
|
|
2009-02-02 05:58:49 +00:00
|
|
|
function handle() {
|
|
|
|
return el.find(".ui-slider-handle");
|
|
|
|
}
|
|
|
|
|
|
|
|
module("slider: options");
|
|
|
|
|
|
|
|
test("max", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 2 );
|
2012-12-26 13:08:48 +00:00
|
|
|
el = $("<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
|
|
|
|
};
|
|
|
|
|
|
|
|
el.slider(options);
|
2012-04-19 02:46:39 +00:00
|
|
|
ok(el.slider("option", "value") === options.value, "value option is not contained by max");
|
|
|
|
ok(el.slider("value") === options.max, "value method is contained by max");
|
2012-12-26 13:08:48 +00:00
|
|
|
el.slider("destroy");
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("min", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 2 );
|
2012-12-26 13:08:48 +00:00
|
|
|
el = $("<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
|
|
|
|
};
|
|
|
|
|
|
|
|
el.slider(options);
|
2012-04-19 02:46:39 +00:00
|
|
|
ok(el.slider("option", "value") === options.value, "value option is not contained by min");
|
|
|
|
ok(el.slider("value") === options.min, "value method is contained by min");
|
2012-12-26 13:08:48 +00:00
|
|
|
el.slider("destroy");
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("orientation", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 6 );
|
2012-12-26 13:08:48 +00:00
|
|
|
el = $("#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
|
|
|
|
};
|
|
|
|
|
|
|
|
var percentVal = (options.value - options.min) / (options.max - options.min) * 100;
|
|
|
|
|
|
|
|
el.slider(options).slider("option", "orientation", "horizontal");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(el.is(".ui-slider-horizontal"), "horizontal slider has class .ui-slider-horizontal");
|
|
|
|
ok(!el.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
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
el.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
|
|
|
|
};
|
|
|
|
|
2012-04-19 02:46:39 +00:00
|
|
|
percentVal = (options.value - options.min) / (options.max - options.min) * 100;
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
el.slider(options).slider("option", "orientation", "vertical");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(el.is(".ui-slider-vertical"), "vertical slider has class .ui-slider-vertical");
|
|
|
|
ok(!el.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
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
el.slider("destroy");
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-07-28 12:29:29 +00:00
|
|
|
//test("range", function() {
|
|
|
|
// ok(false, "missing test - untested code is broken code.");
|
|
|
|
//});
|
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)
|
2009-02-02 05:58:49 +00:00
|
|
|
test("step", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 9 );
|
2012-12-26 13:08:48 +00:00
|
|
|
var el = $("<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
|
|
|
});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2010-03-27 01:00:59 +00:00
|
|
|
el.slider("value", 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
|
|
|
el.slider("value", 9);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 10 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2010-03-27 01:00:59 +00:00
|
|
|
el.slider("value", 11);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 10 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
|
|
|
el.slider("value", 19);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 20 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
el = $("<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
|
|
|
});
|
|
|
|
el.slider("value", 0);
|
|
|
|
|
|
|
|
el.slider("option", "value", 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
|
|
|
el.slider("option", "value", 9);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 0 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
|
|
|
el.slider("option", "value", 11);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 20 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
|
|
|
el.slider("option", "value", 19);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.slider("value"), 20 );
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
el.slider("destroy");
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2011-07-28 12:29:29 +00:00
|
|
|
//test("value", function() {
|
|
|
|
// ok(false, "missing test - untested code is broken code.");
|
|
|
|
//});
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2012-12-06 22:11:23 +00:00
|
|
|
test("values", function() {
|
|
|
|
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 = $([
|
|
|
|
document.createElement("div"),
|
|
|
|
document.createElement("div")
|
|
|
|
]).slider({
|
|
|
|
range: true,
|
|
|
|
values: [ 25, 75 ]
|
|
|
|
});
|
|
|
|
|
|
|
|
notStrictEqual(
|
|
|
|
ranges.eq(0).data("uiSlider").options.values,
|
|
|
|
ranges.eq(1).data("uiSlider").options.values,
|
|
|
|
"multiple range sliders should not have a reference to the same options.values array"
|
|
|
|
);
|
|
|
|
|
|
|
|
ranges.eq(0).slider("values", 0, 10);
|
|
|
|
|
|
|
|
notEqual(
|
|
|
|
ranges.eq(0).slider("values", 0),
|
|
|
|
ranges.eq(1).slider("values", 0),
|
|
|
|
"the values for multiple sliders should be different"
|
|
|
|
);
|
|
|
|
});
|
2009-02-02 05:58:49 +00:00
|
|
|
|
|
|
|
})(jQuery);
|