From 197302427675f3004eb2adea36c8de3abe518d21 Mon Sep 17 00:00:00 2001 From: Jyoti Deka Date: Sat, 19 Oct 2013 00:56:20 -0400 Subject: [PATCH 1/2] Slider: modified , so that slider value can not be set more than max.Fixed #9376 - Slider: Changed _max to max --- tests/unit/slider/slider_options.js | 22 +++++++++++++++++++--- ui/slider.js | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tests/unit/slider/slider_options.js b/tests/unit/slider/slider_options.js index 587f847cfa3..defb6f3b0fb 100644 --- a/tests/unit/slider/slider_options.js +++ b/tests/unit/slider/slider_options.js @@ -40,7 +40,7 @@ test( "disabled", function(){ }); test( "max", function() { - expect( 2 ); + expect( 4 ); element = $( "
" ); options = { @@ -52,8 +52,24 @@ test( "max", function() { }; element.slider( options ); - ok(element.slider( "option", "value" ) === options.value, "value option is not contained by max" ); - ok(element.slider( "value" ) === options.max, "value method is contained by max" ); + ok( element.slider( "option", "value" ) === options.value, "value option is not contained by max" ); + ok( element.slider( "value" ) === options.max, "value method is contained by max" ); + + options = { + max: 9, + min: 1, + orientation: "horizontal", + step: 3, + value: 8.75 + }; + + element.slider( options ); + ok( element.slider( "value" ) === 7, "value method is within max, edge Case" ); + + options.step = 2; + + element.slider( options ); + ok( element.slider( "value" ) === options.max, "value method will max, step is changed" ); element.slider( "destroy" ); }); diff --git a/ui/slider.js b/ui/slider.js index 74cbcc7596e..48406ae8249 100644 --- a/ui/slider.js +++ b/ui/slider.js @@ -58,6 +58,7 @@ return $.widget( "ui.slider", $.ui.mouse, { this._handleIndex = null; this._detectOrientation(); this._mouseInit(); + this._calculateNewMax(); this.element .addClass( "ui-slider" + @@ -472,9 +473,11 @@ return $.widget( "ui.slider", $.ui.mouse, { } this._animateOff = false; break; + case "step": case "min": case "max": this._animateOff = true; + this._calculateNewMax(); this._refreshValue(); this._animateOff = false; break; @@ -543,12 +546,22 @@ return $.widget( "ui.slider", $.ui.mouse, { return parseFloat( alignValue.toFixed(5) ); }, + _calculateNewMax: function() { + var max = this._valueMin(), + step = this.options.step; + + while ( max + step <= this.options.max ) { + max = max + step; + } + this.max = max; + }, + _valueMin: function() { return this.options.min; }, _valueMax: function() { - return this.options.max; + return this.max; }, _refreshValue: function() { From 8932df74a70ea2e91cd7a6eb2f3c546f7f8c7597 Mon Sep 17 00:00:00 2001 From: Jyoti Deka Date: Sat, 25 Jan 2014 16:41:22 -0500 Subject: [PATCH 2/2] ui.slider: modified , avoid loop for CalculateNewMax. Fixed #9376 - ui.slider: On mouse move slider sets value more than max --- ui/slider.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ui/slider.js b/ui/slider.js index 48406ae8249..6d97f3c6939 100644 --- a/ui/slider.js +++ b/ui/slider.js @@ -547,13 +547,8 @@ return $.widget( "ui.slider", $.ui.mouse, { }, _calculateNewMax: function() { - var max = this._valueMin(), - step = this.options.step; - - while ( max + step <= this.options.max ) { - max = max + step; - } - this.max = max; + var remainder = ( this.options.max - this._valueMin() ) % this.options.step; + this.max = this.options.max - remainder; }, _valueMin: function() {