Skip to content

Commit

Permalink
Fixed slider hang when using a zero-length range (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
leongersen committed Feb 14, 2019
1 parent b89d11d commit c63ba6d
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/nouislider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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) {
Expand All @@ -215,8 +219,6 @@
return (value * (range[1] - range[0])) / 100 + range[0];
}

// Range conversion

function getJ(value, arr) {
var j = 1;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -349,7 +356,9 @@
that.xHighestCompleteStep[i] = step;
}

// Interface
//endregion

//region Spectrum

function Spectrum(entry, snap, singleStep) {
this.xPct = [];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -944,6 +957,8 @@
return parsed;
}

//endregion

function scope(target, options, originalOptions) {
var actions = getActions();
var supportsTouchActionNone = getSupportsTouchActionNone();
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c63ba6d

Please sign in to comment.