mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Slider: Fix max calculation, when step is float
Fixes #10721
Closes gh-1398
(cherry picked from commit ae1d6d5f90
)
This commit is contained in:
parent
fcb26aaded
commit
dfa3a9f8c9
@ -40,7 +40,7 @@ test( "disabled", function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test( "max", function() {
|
test( "max", function() {
|
||||||
expect( 4 );
|
expect( 5 );
|
||||||
element = $( "<div></div>" );
|
element = $( "<div></div>" );
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@ -72,6 +72,18 @@ test( "max", function() {
|
|||||||
ok( element.slider( "value" ) === options.max, "value method will max, step is changed" );
|
ok( element.slider( "value" ) === options.max, "value method will max, step is changed" );
|
||||||
element.slider( "destroy" );
|
element.slider( "destroy" );
|
||||||
|
|
||||||
|
options = {
|
||||||
|
max: 60,
|
||||||
|
min: 50,
|
||||||
|
orientation: "horizontal",
|
||||||
|
step: 0.1,
|
||||||
|
value: 60
|
||||||
|
};
|
||||||
|
|
||||||
|
element.slider( options );
|
||||||
|
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
|
||||||
|
element.slider( "destroy" );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "min", function() {
|
test( "min", function() {
|
||||||
|
22
ui/slider.js
22
ui/slider.js
@ -547,8 +547,26 @@ return $.widget( "ui.slider", $.ui.mouse, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_calculateNewMax: function() {
|
_calculateNewMax: function() {
|
||||||
var remainder = ( this.options.max - this._valueMin() ) % this.options.step;
|
var max = this.options.max,
|
||||||
this.max = this.options.max - remainder;
|
min = this._valueMin(),
|
||||||
|
step = this.options.step,
|
||||||
|
aboveMin = Math.floor( ( max - min ) / step ) * step;
|
||||||
|
max = aboveMin + min;
|
||||||
|
this.max = parseFloat( max.toFixed( this._precision() ) );
|
||||||
|
},
|
||||||
|
|
||||||
|
_precision: function() {
|
||||||
|
var precision = this._precisionOf( this.options.step );
|
||||||
|
if ( this.options.min !== null ) {
|
||||||
|
precision = Math.max( precision, this._precisionOf( this.options.min ) );
|
||||||
|
}
|
||||||
|
return precision;
|
||||||
|
},
|
||||||
|
|
||||||
|
_precisionOf: function( num ) {
|
||||||
|
var str = num.toString(),
|
||||||
|
decimal = str.indexOf( "." );
|
||||||
|
return decimal === -1 ? 0 : str.length - decimal - 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
_valueMin: function() {
|
_valueMin: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user