From c63ba6d11a80d7c22ebc2783776b9adbfdd1fa33 Mon Sep 17 00:00:00 2001 From: "l.gersen@visymo.com" Date: Thu, 14 Feb 2019 11:14:19 +0100 Subject: [PATCH] Fixed slider hang when using a zero-length range (#948) --- src/nouislider.js | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/nouislider.js b/src/nouislider.js index 271ed8c7..d3018233 100644 --- a/src/nouislider.js +++ b/src/nouislider.js @@ -14,6 +14,8 @@ var VERSION = "%%REPLACE_THIS_WITH_VERSION%%"; + //region Helper Methods + function isValidFormatter(entry) { return typeof entry === "object" && typeof entry.to === "function" && typeof entry.from === "function"; } @@ -193,7 +195,9 @@ return window.CSS && CSS.supports && CSS.supports("touch-action", "none"); } - // Value calculation + //endregion + + //region Range Calculation // Determine the size of a sub-range in relation to a full range. function subRangeRatio(pa, pb) { @@ -215,8 +219,6 @@ return (value * (range[1] - range[0])) / 100 + range[0]; } - // Range conversion - function getJ(value, arr) { var j = 1; @@ -285,8 +287,6 @@ return xPct[j - 1] + closest(value - xPct[j - 1], xSteps[j - 1]); } - // Entry parsing - function handleEntryPoint(index, value, that) { var percentage; @@ -335,7 +335,14 @@ function handleStepPoint(i, n, that) { // Ignore 'false' stepping. if (!n) { - return true; + return; + } + + // Step over zero-length ranges (#948); + if (that.xVal[i] === that.xVal[i + 1]) { + that.xSteps[i] = that.xHighestCompleteStep[i] = that.xVal[i]; + + return; } // Factor to range ratio @@ -349,7 +356,9 @@ that.xHighestCompleteStep[i] = step; } - // Interface + //endregion + + //region Spectrum function Spectrum(entry, snap, singleStep) { this.xPct = []; @@ -465,6 +474,10 @@ return this.getStep(this.toStepping(value)); }; + //endregion + + //region Options + /* Every input option is tested and parsed. This'll prevent endless validation in internal methods. These tests are structured with an item for every option available. An @@ -944,6 +957,8 @@ return parsed; } + //endregion + function scope(target, options, originalOptions) { var actions = getActions(); var supportsTouchActionNone = getSupportsTouchActionNone(); @@ -1807,6 +1822,9 @@ step = scope_Spectrum.getDefaultStep(scope_Locations[handleNumber], isDown, 10); } + // Step over zero-length ranges (#948); + step = Math.max(step, 0.0000001); + // Decrement for down steps step = (isDown ? -1 : 1) * step;