mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Slider: Don't allow a slider's value to exceed its max
Fixes #9376 Closes gh-1016
This commit is contained in:
parent
d85016abf0
commit
6833a31697
@ -40,7 +40,7 @@ test( "disabled", function(){
|
||||
});
|
||||
|
||||
test( "max", function() {
|
||||
expect( 2 );
|
||||
expect( 4 );
|
||||
element = $( "<div></div>" );
|
||||
|
||||
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" );
|
||||
|
||||
});
|
||||
|
10
ui/slider.js
10
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,17 @@ return $.widget( "ui.slider", $.ui.mouse, {
|
||||
return parseFloat( alignValue.toFixed(5) );
|
||||
},
|
||||
|
||||
_calculateNewMax: function() {
|
||||
var remainder = ( this.options.max - this._valueMin() ) % this.options.step;
|
||||
this.max = this.options.max - remainder;
|
||||
},
|
||||
|
||||
_valueMin: function() {
|
||||
return this.options.min;
|
||||
},
|
||||
|
||||
_valueMax: function() {
|
||||
return this.options.max;
|
||||
return this.max;
|
||||
},
|
||||
|
||||
_refreshValue: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user