aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJyoti Deka <dekajp@gmail.com>2015-01-09 20:06:32 -0500
committerScott González <scott.gonzalez@gmail.com>2015-02-09 11:59:38 -0500
commitdfa3a9f8c983f5206d49000a170b42581fcc5478 (patch)
treefbd28e26fabfb8f6b365ea6f16d53d656644c411 /ui
parentfcb26aaded146e63ffdb9fcca46e308f9b877edd (diff)
downloadjquery-ui-dfa3a9f8c983f5206d49000a170b42581fcc5478.tar.gz
jquery-ui-dfa3a9f8c983f5206d49000a170b42581fcc5478.zip
Slider: Fix max calculation, when step is float
Fixes #10721 Closes gh-1398 (cherry picked from commit ae1d6d5f90236405023964bb3061eccd6c625e39)
Diffstat (limited to 'ui')
-rw-r--r--ui/slider.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/ui/slider.js b/ui/slider.js
index c96180dd2..edc8b4027 100644
--- a/ui/slider.js
+++ b/ui/slider.js
@@ -547,8 +547,26 @@ return $.widget( "ui.slider", $.ui.mouse, {
},
_calculateNewMax: function() {
- var remainder = ( this.options.max - this._valueMin() ) % this.options.step;
- this.max = this.options.max - remainder;
+ var max = this.options.max,
+ 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() {