Skip to content

Commit

Permalink
noUiSlider 15.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leongersen committed May 1, 2022
1 parent 8f1a169 commit ab25fad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
26 changes: 20 additions & 6 deletions dist/nouislider.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@
var hover = entry.indexOf("hover") >= 0;
var unconstrained = entry.indexOf("unconstrained") >= 0;
var dragAll = entry.indexOf("drag-all") >= 0;
var smoothSteps = entry.indexOf("smooth-steps") >= 0;
if (fixed) {
if (parsed.handles !== 2) {
throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles");
Expand All @@ -728,6 +729,7 @@
tap: tap || snap,
drag: drag,
dragAll: dragAll,
smoothSteps: smoothSteps,
fixed: fixed,
snap: snap,
hover: hover,
Expand Down Expand Up @@ -1472,6 +1474,14 @@
scope_Body.removeEventListener("selectstart", preventDefault);
}
}
if (options.events.smoothSteps) {
data.handleNumbers.forEach(function (handleNumber) {
setHandle(handleNumber, scope_Locations[handleNumber], true, true, false, false);
});
data.handleNumbers.forEach(function (handleNumber) {
fireEvent("update", handleNumber);
});
}
data.handleNumbers.forEach(function (handleNumber) {
fireEvent("change", handleNumber);
fireEvent("set", handleNumber);
Expand Down Expand Up @@ -1771,7 +1781,7 @@
});
}
// Split out the handle positioning logic so the Move event can use it, too
function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue) {
function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue, smoothSteps) {
var distance;
// For sliders with multiple handles, limit movement to the other handle.
// Apply the margin option by adding it to the handle positions.
Expand Down Expand Up @@ -1810,7 +1820,9 @@
to = Math.min(to, distance);
}
}
to = scope_Spectrum.getStep(to);
if (!smoothSteps) {
to = scope_Spectrum.getStep(to);
}
// Limit percentage to the 0 - 100 range
to = limit(to);
// Return false if handle can't move
Expand All @@ -1830,6 +1842,7 @@
var proposals = locations.slice();
// Store first handle now, so we still have it in case handleNumbers is reversed
var firstHandle = handleNumbers[0];
var smoothSteps = options.events.smoothSteps;
var b = [!upward, upward];
var f = [upward, !upward];
// Copy handleNumbers so we don't change the dataset
Expand All @@ -1842,7 +1855,7 @@
// Step 1: get the maximum percentage that any of the handles can move
if (handleNumbers.length > 1) {
handleNumbers.forEach(function (handleNumber, o) {
var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false);
var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false, smoothSteps);
// Stop if one of the handles can't move.
if (to === false) {
proposal = 0;
Expand All @@ -1860,7 +1873,8 @@
var state = false;
// Step 2: Try to set the handles with the found percentage
handleNumbers.forEach(function (handleNumber, o) {
state = setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o]) || state;
state =
setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o], false, smoothSteps) || state;
});
// Step 3: If a handle moved, fire events
if (state) {
Expand Down Expand Up @@ -1905,9 +1919,9 @@
}
// Test suggested values and apply margin, step.
// if exactInput is true, don't run checkHandlePosition, then the handle can be placed in between steps (#436)
function setHandle(handleNumber, to, lookBackward, lookForward, exactInput) {
function setHandle(handleNumber, to, lookBackward, lookForward, exactInput, smoothSteps) {
if (!exactInput) {
to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false);
to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false, smoothSteps);
}
if (to === false) {
return false;
Expand Down
Loading

0 comments on commit ab25fad

Please sign in to comment.