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-01-12 12:20:57 -0500
commitae1d6d5f90236405023964bb3061eccd6c625e39 (patch)
treefdc626c82a6531046ad2257e39fc3141c8977784 /ui
parenta3b43eeb58a290f9447ac4127d145ef121ca255c (diff)
downloadjquery-ui-ae1d6d5f90236405023964bb3061eccd6c625e39.tar.gz
jquery-ui-ae1d6d5f90236405023964bb3061eccd6c625e39.zip
Slider: Fix max calculation, when step is float
Fixes #10721 Closes gh-1398
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 9cb088c88..33eb55b3e 100644
--- a/ui/slider.js
+++ b/ui/slider.js
@@ -552,8 +552,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() {