|
1 | 1 | /*! angularjs-slider - v2.3.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 | | - 2015-12-24 */ |
| 4 | + 2015-12-29 */ |
5 | 5 | /*jslint unparam: true */ |
6 | 6 | /*global angular: false, console: false, define, module */ |
7 | 7 | (function(root, factory) { |
|
166 | 166 | value: 0, |
167 | 167 | difference: 0, |
168 | 168 | offset: 0, |
169 | | - lowDist: 0, |
170 | | - highDist: 0 |
| 169 | + lowLimit: 0, |
| 170 | + highLimit: 0 |
171 | 171 | }; |
172 | 172 |
|
173 | 173 | /** |
|
287 | 287 | this.applyOptions(); |
288 | 288 | this.initElemHandles(); |
289 | 289 | this.manageElementsStyle(); |
290 | | - this.addAccessibility(); |
291 | 290 | this.setDisabledState(); |
292 | 291 | this.calcViewDimensions(); |
293 | 292 | this.setMinAndMax(); |
| 293 | + this.addAccessibility(); |
294 | 294 |
|
295 | 295 | $timeout(function() { |
296 | 296 | self.updateCeilLab(); |
|
461 | 461 | break; |
462 | 462 | case 1: |
463 | 463 | this.selBar = jElem; |
464 | | - this.selBarChild = this.selBar.children('rz-selection'); |
465 | 464 | break; |
466 | 465 | case 2: |
467 | 466 | this.minH = jElem; |
|
839 | 838 | * @param {number} newOffset |
840 | 839 | */ |
841 | 840 | updateHandles: function(which, newOffset) { |
842 | | - if (which === 'rzSliderModel') { |
| 841 | + if (which === 'rzSliderModel') |
843 | 842 | this.updateLowHandle(newOffset); |
844 | | - this.updateSelectionBar(); |
845 | | - this.updateTicksScale(); |
846 | | - |
847 | | - if (this.range) { |
848 | | - this.updateCmbLabel(); |
849 | | - } |
850 | | - return; |
851 | | - } |
852 | | - |
853 | | - if (which === 'rzSliderHigh') { |
| 843 | + else if (which === 'rzSliderHigh') |
854 | 844 | this.updateHighHandle(newOffset); |
855 | | - this.updateSelectionBar(); |
856 | | - this.updateTicksScale(); |
857 | 845 |
|
858 | | - if (this.range) { |
859 | | - this.updateCmbLabel(); |
860 | | - } |
861 | | - return; |
862 | | - } |
863 | | - |
864 | | - // Update both |
865 | | - this.updateLowHandle(newOffset); |
866 | | - this.updateHighHandle(newOffset); |
867 | 846 | this.updateSelectionBar(); |
868 | 847 | this.updateTicksScale(); |
869 | | - this.updateCmbLabel(); |
| 848 | + if (this.range) |
| 849 | + this.updateCmbLabel(); |
870 | 850 | }, |
871 | 851 |
|
872 | 852 | /** |
|
1007 | 987 | * @returns {number} |
1008 | 988 | */ |
1009 | 989 | roundStep: function(value) { |
1010 | | - var steppedValue = Math.round(value / this.step) * this.step; |
| 990 | + var steppedValue = parseFloat(value / this.step).toPrecision(12) |
| 991 | + steppedValue = Math.round(steppedValue) * this.step; |
1011 | 992 | steppedValue = steppedValue.toFixed(this.precision); |
1012 | 993 | return +steppedValue; |
1013 | 994 | }, |
|
1150 | 1131 | return (eventPos - this.handleHalfDim) * this.options.scale; |
1151 | 1132 | }, |
1152 | 1133 |
|
| 1134 | + /** |
| 1135 | + * Get event names for move and event end |
| 1136 | + * |
| 1137 | + * @param {Event} event The event |
| 1138 | + * |
| 1139 | + * @return {{moveEvent: string, endEvent: string}} |
| 1140 | + */ |
| 1141 | + getEventNames: function(event) { |
| 1142 | + var eventNames = { |
| 1143 | + moveEvent: '', |
| 1144 | + endEvent: '' |
| 1145 | + }; |
| 1146 | + |
| 1147 | + if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) { |
| 1148 | + eventNames.moveEvent = 'touchmove'; |
| 1149 | + eventNames.endEvent = 'touchend'; |
| 1150 | + } else { |
| 1151 | + eventNames.moveEvent = 'mousemove'; |
| 1152 | + eventNames.endEvent = 'mouseup'; |
| 1153 | + } |
| 1154 | + |
| 1155 | + return eventNames; |
| 1156 | + }, |
| 1157 | + |
1153 | 1158 | /** |
1154 | 1159 | * Get the handle closest to an event. |
1155 | 1160 | * |
|
1180 | 1185 | * @returns {undefined} |
1181 | 1186 | */ |
1182 | 1187 | bindEvents: function() { |
1183 | | - if (this.options.readOnly || this.options.disabled) return; |
1184 | 1188 | var barTracking, barStart, barMove; |
1185 | 1189 |
|
1186 | 1190 | if (this.options.draggableRange) { |
|
1198 | 1202 |
|
1199 | 1203 | if (this.options.draggableRangeOnly) { |
1200 | 1204 | this.minH.on('mousedown', angular.bind(this, barStart, null, barTracking)); |
1201 | | - if (this.range) { |
1202 | | - this.maxH.on('mousedown', angular.bind(this, barStart, null, barTracking)); |
1203 | | - } |
| 1205 | + this.maxH.on('mousedown', angular.bind(this, barStart, null, barTracking)); |
1204 | 1206 | } else { |
1205 | 1207 | this.minH.on('mousedown', angular.bind(this, this.onStart, this.minH, 'rzSliderModel')); |
1206 | 1208 | if (this.range) { |
|
1216 | 1218 | this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar)); |
1217 | 1219 | if (this.options.draggableRangeOnly) { |
1218 | 1220 | this.minH.on('touchstart', angular.bind(this, barStart, null, barTracking)); |
1219 | | - if (this.range) { |
1220 | | - this.maxH.on('touchstart', angular.bind(this, barStart, null, barTracking)); |
1221 | | - } |
| 1221 | + this.maxH.on('touchstart', angular.bind(this, barStart, null, barTracking)); |
1222 | 1222 | } else { |
1223 | 1223 | this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel')); |
1224 | 1224 | if (this.range) { |
|
1431 | 1431 | active: true, |
1432 | 1432 | value: this.offsetToValue(offset), |
1433 | 1433 | difference: this.scope.rzSliderHigh - this.scope.rzSliderModel, |
1434 | | - offset: offset, |
1435 | | - lowDist: offset - this.minH.rzsp, |
1436 | | - highDist: this.maxH.rzsp - offset |
| 1434 | + lowLimit: offset - this.minH.rzsp, |
| 1435 | + highLimit: this.maxH.rzsp - offset |
1437 | 1436 | }; |
1438 | 1437 |
|
1439 | 1438 | this.onStart(pointer, ref, event); |
|
1453 | 1452 | newMinOffset, newMaxOffset, |
1454 | 1453 | newMinValue, newMaxValue; |
1455 | 1454 |
|
1456 | | - if (newOffset <= this.dragging.lowDist) { |
1457 | | - if (pointer.rzsp === this.dragging.lowDist) { |
| 1455 | + if (newOffset <= this.dragging.lowLimit) { |
| 1456 | + if (this.minH.rzsp === 0) |
1458 | 1457 | return; |
1459 | | - } |
1460 | 1458 | newMinValue = this.minValue; |
1461 | 1459 | newMinOffset = 0; |
1462 | 1460 | newMaxValue = this.minValue + this.dragging.difference; |
1463 | 1461 | newMaxOffset = this.valueToOffset(newMaxValue); |
1464 | | - } else if (newOffset >= this.maxPos - this.dragging.highDist) { |
1465 | | - if (pointer.rzsp === this.dragging.highDist) { |
| 1462 | + } else if (newOffset >= this.maxPos - this.dragging.highLimit) { |
| 1463 | + if (this.maxH.rzsp === this.maxPos) |
1466 | 1464 | return; |
1467 | | - } |
1468 | 1465 | newMaxValue = this.maxValue; |
1469 | 1466 | newMaxOffset = this.maxPos; |
1470 | 1467 | newMinValue = this.maxValue - this.dragging.difference; |
1471 | 1468 | newMinOffset = this.valueToOffset(newMinValue); |
1472 | 1469 | } else { |
1473 | | - newMinValue = this.offsetToValue(newOffset - this.dragging.lowDist); |
| 1470 | + newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit); |
1474 | 1471 | newMinValue = this.roundStep(newMinValue); |
1475 | 1472 | newMinOffset = this.valueToOffset(newMinValue); |
1476 | 1473 | newMaxValue = newMinValue + this.dragging.difference; |
|
1546 | 1543 | return switched; |
1547 | 1544 | }, |
1548 | 1545 |
|
1549 | | - /** |
1550 | | - * Get event names for move and event end |
1551 | | - * |
1552 | | - * @param {Event} event The event |
1553 | | - * |
1554 | | - * @return {{moveEvent: string, endEvent: string}} |
1555 | | - */ |
1556 | | - getEventNames: function(event) { |
1557 | | - var eventNames = { |
1558 | | - moveEvent: '', |
1559 | | - endEvent: '' |
1560 | | - }; |
1561 | | - |
1562 | | - if (event.touches || (event.originalEvent !== undefined && event.originalEvent.touches)) { |
1563 | | - eventNames.moveEvent = 'touchmove'; |
1564 | | - eventNames.endEvent = 'touchend'; |
1565 | | - } else { |
1566 | | - eventNames.moveEvent = 'mousemove'; |
1567 | | - eventNames.endEvent = 'mouseup'; |
1568 | | - } |
1569 | | - |
1570 | | - return eventNames; |
1571 | | - }, |
1572 | | - |
1573 | 1546 | /** |
1574 | 1547 | * Apply the model values using scope.$apply. |
1575 | 1548 | * We wrap it with the internalChange flag to avoid the watchers to be called |
|
0 commit comments