Skip to content

Commit 5d130f0

Browse files
author
Valentin Hervieu
committed
fix(roundStep): Fix the roundStep internal function that was too strict.
I was not accepting sliders with floor=7, ceil=7 and step=10 that are actually valid.
1 parent 56a1763 commit 5d130f0

File tree

4 files changed

+86
-27
lines changed

4 files changed

+86
-27
lines changed

dist/rzslider.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.5.0 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-01-24 */
4+
2016-01-31 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -631,14 +631,14 @@
631631
this.step = +this.options.step;
632632
this.precision = +this.options.precision;
633633

634+
this.minValue = this.options.floor;
635+
634636
this.scope.rzSliderModel = this.roundStep(this.scope.rzSliderModel);
635637
if (this.range)
636638
this.scope.rzSliderHigh = this.roundStep(this.scope.rzSliderHigh);
637639

638-
this.minValue = this.roundStep(+this.options.floor);
639-
640640
if (this.options.ceil != null)
641-
this.maxValue = this.roundStep(+this.options.ceil);
641+
this.maxValue = this.options.ceil;
642642
else
643643
this.maxValue = this.options.ceil = this.range ? this.scope.rzSliderHigh : this.scope.rzSliderModel;
644644

@@ -798,7 +798,7 @@
798798
callOnStart: function() {
799799
if (this.options.onStart) {
800800
var self = this;
801-
this.scope.$evalAsync(function () {
801+
this.scope.$evalAsync(function() {
802802
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
803803
});
804804
}
@@ -813,7 +813,7 @@
813813
callOnChange: function() {
814814
if (this.options.onChange) {
815815
var self = this;
816-
this.scope.$evalAsync(function () {
816+
this.scope.$evalAsync(function() {
817817
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
818818
});
819819
}
@@ -828,7 +828,7 @@
828828
callOnEnd: function() {
829829
if (this.options.onEnd) {
830830
var self = this;
831-
this.scope.$evalAsync(function () {
831+
this.scope.$evalAsync(function() {
832832
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
833833
});
834834
}
@@ -993,16 +993,16 @@
993993
},
994994

995995
/**
996-
* Round value to step and precision
996+
* Round value to step and precision based on minValue
997997
*
998998
* @param {number} value
999999
* @returns {number}
10001000
*/
10011001
roundStep: function(value) {
1002-
var steppedValue = parseFloat(value / this.step).toPrecision(12)
1003-
steppedValue = Math.round(steppedValue) * this.step;
1004-
steppedValue = steppedValue.toFixed(this.precision);
1005-
return +steppedValue;
1002+
var steppedDifference = parseFloat((value - this.minValue) / this.step).toPrecision(12);
1003+
steppedDifference = Math.round(+steppedDifference) * this.step;
1004+
var newValue = (this.minValue + (+steppedDifference)).toFixed(this.precision);
1005+
return +newValue;
10061006
},
10071007

10081008
/**

0 commit comments

Comments
 (0)