|
1 | | -/*! angularjs-slider - v6.1.2 - |
| 1 | +/*! angularjs-slider - v6.2.0 - |
2 | 2 | (c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - |
3 | 3 | https://github.com/angular-slider/angularjs-slider - |
4 | 4 | 2017-05-25 */ |
|
158 | 158 |
|
159 | 159 | .factory('RzSlider', ['$timeout', '$document', '$window', '$compile', 'RzSliderOptions', 'rzThrottle', function($timeout, $document, $window, $compile, RzSliderOptions, rzThrottle) { |
160 | 160 | 'use strict'; |
161 | | - |
| 161 | + |
162 | 162 | /** |
163 | 163 | * Slider |
164 | 164 | * |
|
458 | 458 | } |
459 | 459 | return index; |
460 | 460 | }, |
461 | | - |
| 461 | + |
462 | 462 | syncLowValue: function() { |
463 | 463 | if (this.options.stepsArray) { |
464 | 464 | if (!this.options.bindIndexForStepsArray) |
|
1183 | 1183 | isMinLabAtCeil = this.isLabelAboveCeilLab(this.minLab), |
1184 | 1184 | isMaxLabAtCeil = this.isLabelAboveCeilLab(this.maxLab), |
1185 | 1185 | isCmbLabAtFloor = this.isLabelBelowFloorLab(this.cmbLab), |
1186 | | - isCmbLabAtCeil = this.isLabelAboveCeilLab(this.cmbLab); |
| 1186 | + isCmbLabAtCeil = this.isLabelAboveCeilLab(this.cmbLab); |
1187 | 1187 |
|
1188 | 1188 | if (isMinLabAtFloor) { |
1189 | 1189 | flHidden = true; |
|
1227 | 1227 | floorPos = this.flrLab.rzsp, |
1228 | 1228 | floorDim = this.flrLab.rzsd; |
1229 | 1229 | return isRTL ? |
1230 | | - pos + dim >= floorPos - 2 : |
1231 | | - pos <= floorPos + floorDim + 2; |
| 1230 | + pos + dim >= floorPos - 2 : |
| 1231 | + pos <= floorPos + floorDim + 2; |
1232 | 1232 | }, |
1233 | 1233 |
|
1234 | 1234 | isLabelAboveCeilLab: function(label) { |
|
1238 | 1238 | ceilPos = this.ceilLab.rzsp, |
1239 | 1239 | ceilDim = this.ceilLab.rzsd; |
1240 | 1240 | return isRTL ? |
1241 | | - pos <= ceilPos + ceilDim + 2 : |
1242 | | - pos + dim >= ceilPos - 2; |
| 1241 | + pos <= ceilPos + ceilDim + 2 : |
| 1242 | + pos + dim >= ceilPos - 2; |
1243 | 1243 | }, |
1244 | 1244 |
|
1245 | 1245 | /** |
|
1555 | 1555 | return Math.exp(value); |
1556 | 1556 | }, |
1557 | 1557 |
|
| 1558 | + getEventAttr: function(event, attr) { |
| 1559 | + return event.originalEvent === undefined ? event[attr] : event.originalEvent[attr] |
| 1560 | + }, |
| 1561 | + |
1558 | 1562 | // Events |
1559 | 1563 | /** |
1560 | 1564 | * Get the X-coordinate or Y-coordinate of an event |
1561 | 1565 | * |
1562 | 1566 | * @param {Object} event The event |
1563 | | - * @param targetTouchId The identifier of the touch for that we will get the x and y coordinates |
| 1567 | + * @param targetTouchId The identifier of the touch with the X/Y coordinates |
1564 | 1568 | * @returns {number} |
1565 | 1569 | */ |
1566 | 1570 | getEventXY: function(event, targetTouchId) { |
|
1570 | 1574 | if (event[clientXY] !== undefined) { |
1571 | 1575 | return event[clientXY]; |
1572 | 1576 | } |
1573 | | - |
1574 | | - var eventXY; |
1575 | | - var touches = event.originalEvent === undefined ? event.touches : event.originalEvent.touches; |
1576 | | - |
1577 | | - if (targetTouchId !== undefined) { |
1578 | | - for (var i = 0; i < touches.length; i++) { |
1579 | | - if (touches[i].identifier == targetTouchId) { |
1580 | | - return touches[i][clientXY]; |
1581 | | - } |
1582 | | - } |
1583 | | - } |
1584 | | - |
1585 | | - // If the target touch was not found in the event |
1586 | | - // returns the coordinates of the first touch |
1587 | | - return touches[0][clientXY]; |
| 1577 | + |
| 1578 | + var touches = this.getEventAttr(event, 'touches'); |
| 1579 | + |
| 1580 | + if (targetTouchId !== undefined) { |
| 1581 | + for (var i = 0; i < touches.length; i++) { |
| 1582 | + if (touches[i].identifier === targetTouchId) { |
| 1583 | + return touches[i][clientXY]; |
| 1584 | + } |
| 1585 | + } |
| 1586 | + } |
| 1587 | + |
| 1588 | + // If no target touch or the target touch was not found in the event |
| 1589 | + // returns the coordinates of the first touch |
| 1590 | + return touches[0][clientXY]; |
1588 | 1591 | }, |
1589 | 1592 |
|
1590 | 1593 | /** |
1591 | 1594 | * Compute the event position depending on whether the slider is horizontal or vertical |
1592 | 1595 | * @param event |
1593 | | - * @param targetTouchId If targetTouchId is provided it will be considered the position of that |
| 1596 | + * @param targetTouchId If targetTouchId is provided it will be considered the position of that |
1594 | 1597 | * @returns {number} |
1595 | 1598 | */ |
1596 | 1599 | getEventPosition: function(event, targetTouchId) { |
|
1616 | 1619 | endEvent: '' |
1617 | 1620 | }; |
1618 | 1621 |
|
1619 | | - if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) { |
| 1622 | + if (this.getEventAttr(event, 'touches')) { |
1620 | 1623 | eventNames.moveEvent = 'touchmove'; |
1621 | 1624 | eventNames.endEvent = 'touchend'; |
1622 | 1625 | } else { |
|
1777 | 1780 | ehEnd = angular.bind(this, this.onEnd, ehMove); |
1778 | 1781 |
|
1779 | 1782 | $document.on(eventNames.moveEvent, ehMove); |
1780 | | - |
| 1783 | + |
1781 | 1784 | $document.on(eventNames.endEvent, ehEnd); |
1782 | 1785 | this.ehEndToBeRemovedOnEnd = ehEnd; |
1783 | 1786 | this.callOnStart(); |
1784 | | - |
1785 | | - var changedTouches = event.originalEvent === undefined ? event.changedTouches : event.originalEvent.changedTouches; |
| 1787 | + |
| 1788 | + var changedTouches = this.getEventAttr(event, 'changedTouches'); |
1786 | 1789 | if (changedTouches) { |
1787 | | - // Store the touch identifier |
1788 | | - if (!this.touchId) { |
1789 | | - this.isDragging = true; |
1790 | | - this.touchId = changedTouches[0].identifier; |
1791 | | - } |
1792 | | - } |
| 1790 | + // Store the touch identifier |
| 1791 | + if (!this.touchId) { |
| 1792 | + this.isDragging = true; |
| 1793 | + this.touchId = changedTouches[0].identifier; |
| 1794 | + } |
| 1795 | + } |
1793 | 1796 | }, |
1794 | 1797 |
|
1795 | 1798 | /** |
|
1801 | 1804 | * @returns {undefined} |
1802 | 1805 | */ |
1803 | 1806 | onMove: function(pointer, event, fromTick) { |
1804 | | - var changedTouches = event.originalEvent === undefined ? event.changedTouches : event.originalEvent.changedTouches; |
1805 | | - var touchForThisSlider; |
1806 | | - if (changedTouches) { |
1807 | | - for (var i = 0; i < changedTouches.length; i++) { |
1808 | | - if (changedTouches[i].identifier == this.touchId) { |
1809 | | - touchForThisSlider = changedTouches[i]; |
1810 | | - break; |
1811 | | - } |
1812 | | - } |
1813 | | - } |
1814 | | - |
1815 | | - if (changedTouches && !touchForThisSlider) { |
1816 | | - return; |
1817 | | - } |
1818 | | - |
| 1807 | + var changedTouches = this.getEventAttr(event, 'changedTouches'); |
| 1808 | + var touchForThisSlider; |
| 1809 | + if (changedTouches) { |
| 1810 | + for (var i = 0; i < changedTouches.length; i++) { |
| 1811 | + if (changedTouches[i].identifier === this.touchId) { |
| 1812 | + touchForThisSlider = changedTouches[i]; |
| 1813 | + break; |
| 1814 | + } |
| 1815 | + } |
| 1816 | + } |
| 1817 | + |
| 1818 | + if (changedTouches && !touchForThisSlider) { |
| 1819 | + return; |
| 1820 | + } |
| 1821 | + |
1819 | 1822 | var newPos = this.getEventPosition(event, touchForThisSlider ? touchForThisSlider.identifier : undefined), |
1820 | 1823 | newValue, |
1821 | 1824 | ceilValue = this.options.rightToLeft ? this.minValue : this.maxValue, |
|
1834 | 1837 | } |
1835 | 1838 | this.positionTrackingHandle(newValue); |
1836 | 1839 | }, |
1837 | | - |
| 1840 | + |
1838 | 1841 | /** |
1839 | 1842 | * onEnd event handler |
1840 | 1843 | * |
|
1843 | 1846 | * @returns {undefined} |
1844 | 1847 | */ |
1845 | 1848 | onEnd: function(ehMove, event) { |
1846 | | - var changedTouches = event.originalEvent === undefined ? event.changedTouches : event.originalEvent.changedTouches; |
1847 | | - if (changedTouches && changedTouches[0].identifier != this.touchId) { |
1848 | | - return; |
1849 | | - } |
1850 | | - this.isDragging = false; |
1851 | | - this.touchId = null; |
1852 | | - |
1853 | | - // Touch event, the listener was added by us so we need to remove it |
1854 | | - $document.off("touchend", this.ehEndToBeRemovedOnEnd); |
1855 | | - |
| 1849 | + var changedTouches = this.getEventAttr(event, 'changedTouches'); |
| 1850 | + if (changedTouches && changedTouches[0].identifier !== this.touchId) { |
| 1851 | + return; |
| 1852 | + } |
| 1853 | + this.isDragging = false; |
| 1854 | + this.touchId = null; |
| 1855 | + |
| 1856 | + // Touch event, the listener was added by us so we need to remove it |
| 1857 | + $document.off("touchend", this.ehEndToBeRemovedOnEnd); |
| 1858 | + |
1856 | 1859 | var moveEventName = this.getEventNames(event).moveEvent; |
1857 | 1860 |
|
1858 | 1861 | if (!this.options.keyboardSupport) { |
|
1894 | 1897 | pointer.off('keyup'); |
1895 | 1898 | pointer.removeClass('rz-active'); |
1896 | 1899 | if (!this.isDragging) { |
1897 | | - this.tracking = ''; |
1898 | | - this.currentFocusElement = null |
| 1900 | + this.tracking = ''; |
| 1901 | + this.currentFocusElement = null |
1899 | 1902 | } |
1900 | 1903 | }, |
1901 | 1904 |
|
|
0 commit comments