|
1 | 1 | /*! angularjs-slider - v5.0.1 -
|
2 | 2 | (c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
|
3 | 3 | https://github.com/angular-slider/angularjs-slider -
|
4 |
| - 2016-07-01 */ |
| 4 | + 2016-07-02 */ |
5 | 5 | /*jslint unparam: true */
|
6 | 6 | /*global angular: false, console: false, define, module */
|
7 | 7 | (function(root, factory) {
|
|
33 | 33 | precision: 0,
|
34 | 34 | minRange: null,
|
35 | 35 | maxRange: null,
|
| 36 | + pushRange: false, |
36 | 37 | minLimit: null,
|
37 | 38 | maxLimit: null,
|
38 | 39 | id: null,
|
|
1906 | 1907 |
|
1907 | 1908 | newValue = this.applyMinMaxLimit(newValue);
|
1908 | 1909 | if (this.range) {
|
1909 |
| - newValue = this.applyMinMaxRange(newValue); |
1910 |
| - /* This is to check if we need to switch the min and max handles */ |
1911 |
| - if (this.tracking === 'lowValue' && newValue > this.highValue) { |
1912 |
| - if (this.options.noSwitching && this.highValue !== this.minValue) { |
1913 |
| - newValue = this.applyMinMaxRange(this.highValue); |
1914 |
| - } |
1915 |
| - else { |
1916 |
| - this.lowValue = this.highValue; |
1917 |
| - this.applyLowValue(); |
1918 |
| - this.updateHandles(this.tracking, this.maxH.rzsp); |
1919 |
| - this.updateAriaAttributes(); |
1920 |
| - this.tracking = 'highValue'; |
1921 |
| - this.minH.removeClass('rz-active'); |
1922 |
| - this.maxH.addClass('rz-active'); |
1923 |
| - if (this.options.keyboardSupport) |
1924 |
| - this.focusElement(this.maxH); |
1925 |
| - } |
| 1910 | + if (this.options.pushRange) { |
| 1911 | + newValue = this.applyPushRange(newValue); |
1926 | 1912 | valueChanged = true;
|
1927 |
| - } else if (this.tracking === 'highValue' && newValue < this.lowValue) { |
1928 |
| - if (this.options.noSwitching && this.lowValue !== this.maxValue) { |
1929 |
| - newValue = this.applyMinMaxRange(this.lowValue); |
| 1913 | + } |
| 1914 | + else { |
| 1915 | + newValue = this.applyMinMaxRange(newValue); |
| 1916 | + /* This is to check if we need to switch the min and max handles */ |
| 1917 | + if (this.tracking === 'lowValue' && newValue > this.highValue) { |
| 1918 | + if (this.options.noSwitching && this.highValue !== this.minValue) { |
| 1919 | + newValue = this.applyMinMaxRange(this.highValue); |
| 1920 | + } |
| 1921 | + else { |
| 1922 | + this.lowValue = this.highValue; |
| 1923 | + this.applyLowValue(); |
| 1924 | + this.updateHandles(this.tracking, this.maxH.rzsp); |
| 1925 | + this.updateAriaAttributes(); |
| 1926 | + this.tracking = 'highValue'; |
| 1927 | + this.minH.removeClass('rz-active'); |
| 1928 | + this.maxH.addClass('rz-active'); |
| 1929 | + if (this.options.keyboardSupport) |
| 1930 | + this.focusElement(this.maxH); |
| 1931 | + } |
| 1932 | + valueChanged = true; |
1930 | 1933 | }
|
1931 |
| - else { |
1932 |
| - this.highValue = this.lowValue; |
1933 |
| - this.applyHighValue(); |
1934 |
| - this.updateHandles(this.tracking, this.minH.rzsp); |
1935 |
| - this.updateAriaAttributes(); |
1936 |
| - this.tracking = 'lowValue'; |
1937 |
| - this.maxH.removeClass('rz-active'); |
1938 |
| - this.minH.addClass('rz-active'); |
1939 |
| - if (this.options.keyboardSupport) |
1940 |
| - this.focusElement(this.minH); |
| 1934 | + else if (this.tracking === 'highValue' && newValue < this.lowValue) { |
| 1935 | + if (this.options.noSwitching && this.lowValue !== this.maxValue) { |
| 1936 | + newValue = this.applyMinMaxRange(this.lowValue); |
| 1937 | + } |
| 1938 | + else { |
| 1939 | + this.highValue = this.lowValue; |
| 1940 | + this.applyHighValue(); |
| 1941 | + this.updateHandles(this.tracking, this.minH.rzsp); |
| 1942 | + this.updateAriaAttributes(); |
| 1943 | + this.tracking = 'lowValue'; |
| 1944 | + this.maxH.removeClass('rz-active'); |
| 1945 | + this.minH.addClass('rz-active'); |
| 1946 | + if (this.options.keyboardSupport) |
| 1947 | + this.focusElement(this.minH); |
| 1948 | + } |
| 1949 | + valueChanged = true; |
1941 | 1950 | }
|
1942 |
| - valueChanged = true; |
1943 | 1951 | }
|
1944 | 1952 | }
|
1945 | 1953 |
|
|
1988 | 1996 | return newValue;
|
1989 | 1997 | },
|
1990 | 1998 |
|
| 1999 | + applyPushRange: function(newValue) { |
| 2000 | + var difference = this.tracking === 'lowValue' ? this.highValue - newValue : newValue - this.lowValue, |
| 2001 | + range = this.options.minRange !== null ? this.options.minRange : this.options.step; |
| 2002 | + if (difference < range) { |
| 2003 | + if (this.tracking === 'lowValue') { |
| 2004 | + this.highValue = Math.min(newValue + range, this.maxValue); |
| 2005 | + newValue = this.highValue - range; |
| 2006 | + this.applyHighValue(); |
| 2007 | + this.updateHandles('highValue', this.valueToOffset(this.highValue)); |
| 2008 | + } |
| 2009 | + else { |
| 2010 | + this.lowValue = Math.max(newValue - range, this.minValue); |
| 2011 | + newValue = this.lowValue + range; |
| 2012 | + this.applyLowValue(); |
| 2013 | + this.updateHandles('lowValue', this.valueToOffset(this.lowValue)); |
| 2014 | + } |
| 2015 | + this.updateAriaAttributes(); |
| 2016 | + } |
| 2017 | + return newValue; |
| 2018 | + }, |
| 2019 | + |
1991 | 2020 | /**
|
1992 | 2021 | * Apply the model values using scope.$apply.
|
1993 | 2022 | * We wrap it with the internalChange flag to avoid the watchers to be called
|
|
0 commit comments