|
714 | 714 | var hover = entry.indexOf("hover") >= 0; |
715 | 715 | var unconstrained = entry.indexOf("unconstrained") >= 0; |
716 | 716 | var dragAll = entry.indexOf("drag-all") >= 0; |
| 717 | + var smoothSteps = entry.indexOf("smooth-steps") >= 0; |
717 | 718 | if (fixed) { |
718 | 719 | if (parsed.handles !== 2) { |
719 | 720 | throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles"); |
|
728 | 729 | tap: tap || snap, |
729 | 730 | drag: drag, |
730 | 731 | dragAll: dragAll, |
| 732 | + smoothSteps: smoothSteps, |
731 | 733 | fixed: fixed, |
732 | 734 | snap: snap, |
733 | 735 | hover: hover, |
|
1472 | 1474 | scope_Body.removeEventListener("selectstart", preventDefault); |
1473 | 1475 | } |
1474 | 1476 | } |
| 1477 | + if (options.events.smoothSteps) { |
| 1478 | + data.handleNumbers.forEach(function (handleNumber) { |
| 1479 | + setHandle(handleNumber, scope_Locations[handleNumber], true, true, false, false); |
| 1480 | + }); |
| 1481 | + data.handleNumbers.forEach(function (handleNumber) { |
| 1482 | + fireEvent("update", handleNumber); |
| 1483 | + }); |
| 1484 | + } |
1475 | 1485 | data.handleNumbers.forEach(function (handleNumber) { |
1476 | 1486 | fireEvent("change", handleNumber); |
1477 | 1487 | fireEvent("set", handleNumber); |
|
1771 | 1781 | }); |
1772 | 1782 | } |
1773 | 1783 | // Split out the handle positioning logic so the Move event can use it, too |
1774 | | - function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue) { |
| 1784 | + function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue, smoothSteps) { |
1775 | 1785 | var distance; |
1776 | 1786 | // For sliders with multiple handles, limit movement to the other handle. |
1777 | 1787 | // Apply the margin option by adding it to the handle positions. |
|
1810 | 1820 | to = Math.min(to, distance); |
1811 | 1821 | } |
1812 | 1822 | } |
1813 | | - to = scope_Spectrum.getStep(to); |
| 1823 | + if (!smoothSteps) { |
| 1824 | + to = scope_Spectrum.getStep(to); |
| 1825 | + } |
1814 | 1826 | // Limit percentage to the 0 - 100 range |
1815 | 1827 | to = limit(to); |
1816 | 1828 | // Return false if handle can't move |
|
1830 | 1842 | var proposals = locations.slice(); |
1831 | 1843 | // Store first handle now, so we still have it in case handleNumbers is reversed |
1832 | 1844 | var firstHandle = handleNumbers[0]; |
| 1845 | + var smoothSteps = options.events.smoothSteps; |
1833 | 1846 | var b = [!upward, upward]; |
1834 | 1847 | var f = [upward, !upward]; |
1835 | 1848 | // Copy handleNumbers so we don't change the dataset |
|
1842 | 1855 | // Step 1: get the maximum percentage that any of the handles can move |
1843 | 1856 | if (handleNumbers.length > 1) { |
1844 | 1857 | handleNumbers.forEach(function (handleNumber, o) { |
1845 | | - var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false); |
| 1858 | + var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false, smoothSteps); |
1846 | 1859 | // Stop if one of the handles can't move. |
1847 | 1860 | if (to === false) { |
1848 | 1861 | proposal = 0; |
|
1860 | 1873 | var state = false; |
1861 | 1874 | // Step 2: Try to set the handles with the found percentage |
1862 | 1875 | handleNumbers.forEach(function (handleNumber, o) { |
1863 | | - state = setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o]) || state; |
| 1876 | + state = |
| 1877 | + setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o], false, smoothSteps) || state; |
1864 | 1878 | }); |
1865 | 1879 | // Step 3: If a handle moved, fire events |
1866 | 1880 | if (state) { |
|
1905 | 1919 | } |
1906 | 1920 | // Test suggested values and apply margin, step. |
1907 | 1921 | // if exactInput is true, don't run checkHandlePosition, then the handle can be placed in between steps (#436) |
1908 | | - function setHandle(handleNumber, to, lookBackward, lookForward, exactInput) { |
| 1922 | + function setHandle(handleNumber, to, lookBackward, lookForward, exactInput, smoothSteps) { |
1909 | 1923 | if (!exactInput) { |
1910 | | - to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false); |
| 1924 | + to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false, smoothSteps); |
1911 | 1925 | } |
1912 | 1926 | if (to === false) { |
1913 | 1927 | return false; |
|
0 commit comments