Skip to content

Commit 0266527

Browse files
committed
Slider: Fix max calculation, when step is float
Fixes #10721 new _calculateNewMax method avoid loop for better performance.
1 parent c7b468f commit 0266527

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ui/slider.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
552552
},
553553

554554
_calculateNewMax: function() {
555-
var max = this._valueMin(),
556-
step = this.options.step,
557-
precisiondigits = this._precision();
558-
while ( parseFloat( ( max + step ).toFixed( precisiondigits ) ) <= this.options.max ) {
559-
max = parseFloat( ( max + step ).toFixed( precisiondigits ) );
560-
}
561-
this.max = max;
555+
var precision = this._precision();
556+
var multiplier = Math.pow( 10 , precision );
557+
var max = this.options.max * multiplier ;
558+
var min = this._valueMin() * multiplier ;
559+
var step = this.options.step * multiplier ;
560+
var remainder = ( max - min ) % step;
561+
this.max = parseFloat( ( ( max - remainder ) / multiplier ).toFixed( precision ) );
562562
},
563563

564564
_precision: function() {

0 commit comments

Comments
 (0)