Skip to content

Commit 72c7e74

Browse files
author
Valentin Hervieu
committed
Improve behavior when scope value is out of slider range
Implement the solution described in #159 .
1 parent 271b496 commit 72c7e74

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

dist/rzslider.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -568,23 +568,15 @@
568568

569569
this.step = +this.options.step;
570570
this.precision = +this.options.precision;
571+
571572
this.scope.rzSliderModel = this.roundStep(this.scope.rzSliderModel);
572573
if (this.range)
573574
this.scope.rzSliderHigh = this.roundStep(this.scope.rzSliderHigh);
574575

575576
this.minValue = this.roundStep(+this.options.floor);
576-
if (this.scope.rzSliderModel < this.minValue)
577-
this.scope.rzSliderModel = this.minValue;
578-
if (this.range && this.scope.rzSliderHigh < this.minValue)
579-
this.scope.rzSliderHigh = this.minValue;
580577

581-
if (this.options.ceil) {
578+
if (this.options.ceil)
582579
this.maxValue = this.roundStep(+this.options.ceil);
583-
if (this.scope.rzSliderModel > this.maxValue)
584-
this.scope.rzSliderModel = this.maxValue;
585-
if (this.range && this.scope.rzSliderHigh > this.maxValue)
586-
this.scope.rzSliderHigh = this.maxValue;
587-
}
588580
else
589581
this.maxValue = this.options.ceil = this.range ? this.scope.rzSliderHigh : this.scope.rzSliderModel;
590582

@@ -957,7 +949,18 @@
957949
* @returns {number}
958950
*/
959951
valueToOffset: function(val) {
960-
return (val - this.minValue) * this.maxLeft / this.valueRange || 0;
952+
return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxLeft / this.valueRange || 0;
953+
},
954+
955+
/**
956+
* Ensure that the position rendered is within the slider bounds, even if the value is not
957+
*
958+
* @param {number} val
959+
* @returns {number}
960+
*/
961+
sanitizeOffsetValue: function(val)
962+
{
963+
return Math.min(Math.max(val, this.minValue), this.maxValue);
961964
},
962965

963966
/**

0 commit comments

Comments
 (0)