mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Slider: Fixed max value miscalculation
Fixes #12852
Closes gh-1664
(cherry picked from commit a1905e2c5e
)
This commit is contained in:
parent
eb6d623589
commit
622959b011
@ -40,7 +40,7 @@ test( "disabled", function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test( "max", function() {
|
test( "max", function() {
|
||||||
expect( 5 );
|
expect( 7 );
|
||||||
element = $( "<div></div>" );
|
element = $( "<div></div>" );
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@ -84,7 +84,24 @@ test( "max", function() {
|
|||||||
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
|
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
|
||||||
element.slider( "destroy" );
|
element.slider( "destroy" );
|
||||||
|
|
||||||
});
|
options = {
|
||||||
|
max: 10.75,
|
||||||
|
min: 1.22,
|
||||||
|
orientation: "horizontal",
|
||||||
|
step: 0.01,
|
||||||
|
value: 10.75
|
||||||
|
};
|
||||||
|
|
||||||
|
element.slider( options );
|
||||||
|
ok( element.slider( "value" ) === options.max, "value method will max, step is changed, step is float and max is float" );
|
||||||
|
element.slider( "destroy" );
|
||||||
|
|
||||||
|
options.max = 10.749999999;
|
||||||
|
|
||||||
|
element.slider( options );
|
||||||
|
ok( element.slider( "value" ) === 10.74, "value method will max, step is changed, step is float, max is float and not divisible" );
|
||||||
|
element.slider( "destroy" );
|
||||||
|
} );
|
||||||
|
|
||||||
test( "min", function() {
|
test( "min", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
|
@ -552,8 +552,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
|
|||||||
var max = this.options.max,
|
var max = this.options.max,
|
||||||
min = this._valueMin(),
|
min = this._valueMin(),
|
||||||
step = this.options.step,
|
step = this.options.step,
|
||||||
aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
|
aboveMin = Math.round( ( max - min ) / step ) * step;
|
||||||
max = aboveMin + min;
|
max = aboveMin + min;
|
||||||
|
if ( max > this.options.max ) {
|
||||||
|
|
||||||
|
//If max is not divisible by step, rounding off may increase its value
|
||||||
|
max -= step;
|
||||||
|
}
|
||||||
this.max = parseFloat( max.toFixed( this._precision() ) );
|
this.max = parseFloat( max.toFixed( this._precision() ) );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user