aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMukul Hase <mukulhase@gmail.com>2016-02-12 00:59:54 +0530
committerScott González <scott.gonzalez@gmail.com>2016-03-30 13:28:04 -0400
commita1905e2c5ed6e61e6a7206e005de9dda4f7135d0 (patch)
tree71d0cf18a05a9da9417a055d95df170d38b74980
parentbff8277fbc885bf2dc0461ac706d2f2bb7035ad6 (diff)
downloadjquery-ui-a1905e2c5ed6e61e6a7206e005de9dda4f7135d0.tar.gz
jquery-ui-a1905e2c5ed6e61e6a7206e005de9dda4f7135d0.zip
Slider: Fixed max value miscalculation
Fixes #12852 Closes gh-1664
-rw-r--r--tests/unit/slider/options.js19
-rw-r--r--ui/widgets/slider.js7
2 files changed, 24 insertions, 2 deletions
diff --git a/tests/unit/slider/options.js b/tests/unit/slider/options.js
index 031031cdc..5f3ea1111 100644
--- a/tests/unit/slider/options.js
+++ b/tests/unit/slider/options.js
@@ -43,7 +43,7 @@ test( "disabled", function( assert ) {
} );
test( "max", function() {
- expect( 5 );
+ expect( 7 );
element = $( "<div></div>" );
options = {
@@ -87,6 +87,23 @@ test( "max", function() {
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
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() {
diff --git a/ui/widgets/slider.js b/ui/widgets/slider.js
index a2da892c4..8af032dcf 100644
--- a/ui/widgets/slider.js
+++ b/ui/widgets/slider.js
@@ -544,8 +544,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
var max = this.options.max,
min = this._valueMin(),
step = this.options.step,
- aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
+ aboveMin = Math.round( ( max - min ) / step ) * step;
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() ) );
},