|
1 | 1 | /*! angularjs-slider - v6.5.1 - |
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 | | - 2018-03-30 */ |
| 4 | + 2018-06-29 */ |
5 | 5 | /*jslint unparam: true */ |
6 | 6 | /*global angular: false, console: false, define, module */ |
7 | 7 | ;(function(root, factory) { |
|
36 | 36 | precision: 0, |
37 | 37 | minRange: null, |
38 | 38 | maxRange: null, |
| 39 | + restrictedRange: null, |
39 | 40 | pushRange: false, |
40 | 41 | minLimit: null, |
41 | 42 | maxLimit: null, |
|
371 | 372 | this.setDisabledState() |
372 | 373 | this.calcViewDimensions() |
373 | 374 | this.setMinAndMax() |
| 375 | + this.updateRestrictionBar() |
374 | 376 | this.addAccessibility() |
375 | 377 | this.updateCeilLab() |
376 | 378 | this.updateFloorLab() |
|
635 | 637 | this.manageEventsBindings() |
636 | 638 | this.setDisabledState() |
637 | 639 | this.calcViewDimensions() |
| 640 | + this.updateRestrictionBar() |
638 | 641 | this.refocusPointerIfNeeded() |
639 | 642 | }, |
640 | 643 |
|
|
676 | 679 | this.selBar = jElem |
677 | 680 | break |
678 | 681 | case 4: |
679 | | - this.minH = jElem |
| 682 | + this.restrictedBar = jElem |
680 | 683 | break |
681 | 684 | case 5: |
682 | | - this.maxH = jElem |
| 685 | + this.minH = jElem |
683 | 686 | break |
684 | 687 | case 6: |
685 | | - this.flrLab = jElem |
| 688 | + this.maxH = jElem |
686 | 689 | break |
687 | 690 | case 7: |
688 | | - this.ceilLab = jElem |
| 691 | + this.flrLab = jElem |
689 | 692 | break |
690 | 693 | case 8: |
691 | | - this.minLab = jElem |
| 694 | + this.ceilLab = jElem |
692 | 695 | break |
693 | 696 | case 9: |
694 | | - this.maxLab = jElem |
| 697 | + this.minLab = jElem |
695 | 698 | break |
696 | 699 | case 10: |
697 | | - this.cmbLab = jElem |
| 700 | + this.maxLab = jElem |
698 | 701 | break |
699 | 702 | case 11: |
| 703 | + this.cmbLab = jElem |
| 704 | + break |
| 705 | + case 12: |
700 | 706 | this.ticks = jElem |
701 | 707 | break |
702 | 708 | } |
|
753 | 759 | this.leftOutSelBar, |
754 | 760 | !this.range || !this.options.showOuterSelectionBars |
755 | 761 | ) |
| 762 | + this.alwaysHide(this.restrictedBar, !this.options.restrictedRange) |
756 | 763 | this.alwaysHide( |
757 | 764 | this.rightOutSelBar, |
758 | 765 | !this.range || !this.options.showOuterSelectionBars |
|
1305 | 1312 | return isRTL ? pos <= ceilPos + ceilDim + 2 : pos + dim >= ceilPos - 2 |
1306 | 1313 | }, |
1307 | 1314 |
|
| 1315 | + /** |
| 1316 | + * Update restricted area bar |
| 1317 | + * |
| 1318 | + * @returns {undefined} |
| 1319 | + */ |
| 1320 | + updateRestrictionBar: function() { |
| 1321 | + var position = 0, |
| 1322 | + dimension = 0 |
| 1323 | + if (this.options.restrictedRange) { |
| 1324 | + var from = this.valueToPosition(this.options.restrictedRange.from), |
| 1325 | + to = this.valueToPosition(this.options.restrictedRange.to) |
| 1326 | + dimension = Math.abs(to - from) |
| 1327 | + position = this.options.rightToLeft |
| 1328 | + ? to + this.handleHalfDim |
| 1329 | + : from + this.handleHalfDim |
| 1330 | + this.setDimension(this.restrictedBar, dimension) |
| 1331 | + this.setPosition(this.restrictedBar, position) |
| 1332 | + } |
| 1333 | + }, |
| 1334 | + |
1308 | 1335 | /** |
1309 | 1336 | * Update slider selection bar, combined label and range label |
1310 | 1337 | * |
|
1379 | 1406 | : 0, |
1380 | 1407 | reversed = (offset - position > 0) ^ isSelectionBarFromRight, |
1381 | 1408 | direction = this.options.vertical |
1382 | | - ? reversed ? 'bottom' : 'top' |
1383 | | - : reversed ? 'left' : 'right' |
| 1409 | + ? reversed |
| 1410 | + ? 'bottom' |
| 1411 | + : 'top' |
| 1412 | + : reversed |
| 1413 | + ? 'left' |
| 1414 | + : 'right' |
1384 | 1415 | this.scope.barStyle = { |
1385 | 1416 | backgroundImage: |
1386 | 1417 | 'linear-gradient(to ' + |
|
1775 | 1806 | else if (!this.options.rightToLeft) |
1776 | 1807 | //if event is at the same distance from min/max then if it's at left of minH, we return minH else maxH |
1777 | 1808 | return position < this.minH.rzsp ? this.minH : this.maxH |
1778 | | - else |
1779 | | - //reverse in rtl |
1780 | | - return position > this.minH.rzsp ? this.minH : this.maxH |
| 1809 | + //reverse in rtl |
| 1810 | + else return position > this.minH.rzsp ? this.minH : this.maxH |
1781 | 1811 | }, |
1782 | 1812 |
|
1783 | 1813 | /** |
|
2369 | 2399 | positionTrackingHandle: function(newValue) { |
2370 | 2400 | var valueChanged = false |
2371 | 2401 | newValue = this.applyMinMaxLimit(newValue) |
| 2402 | + newValue = this.applyRestrictedRange(newValue) |
2372 | 2403 | if (this.range) { |
2373 | 2404 | if (this.options.pushRange) { |
2374 | 2405 | newValue = this.applyPushRange(newValue) |
|
2456 | 2487 | return newValue |
2457 | 2488 | }, |
2458 | 2489 |
|
| 2490 | + applyRestrictedRange: function(newValue) { |
| 2491 | + if ( |
| 2492 | + this.options.restrictedRange != null && |
| 2493 | + newValue > this.options.restrictedRange.from && |
| 2494 | + newValue < this.options.restrictedRange.to |
| 2495 | + ) { |
| 2496 | + var halfWidth = |
| 2497 | + (this.options.restrictedRange.to - |
| 2498 | + this.options.restrictedRange.from) / |
| 2499 | + 2 |
| 2500 | + if (this.tracking === 'lowValue') { |
| 2501 | + return newValue > this.options.restrictedRange.from + halfWidth |
| 2502 | + ? this.options.restrictedRange.to |
| 2503 | + : this.options.restrictedRange.from |
| 2504 | + } |
| 2505 | + if (this.tracking === 'highValue') { |
| 2506 | + return newValue < this.options.restrictedRange.to - halfWidth |
| 2507 | + ? this.options.restrictedRange.from |
| 2508 | + : this.options.restrictedRange.to |
| 2509 | + } |
| 2510 | + } |
| 2511 | + return newValue |
| 2512 | + }, |
| 2513 | + |
2459 | 2514 | applyPushRange: function(newValue) { |
2460 | 2515 | var difference = |
2461 | 2516 | this.tracking === 'lowValue' |
|
2654 | 2709 | 'use strict'; |
2655 | 2710 |
|
2656 | 2711 | $templateCache.put('rzSliderTpl.html', |
2657 | | - "<div class=rzslider><span class=\"rz-bar-wrapper rz-left-out-selection\"><span class=rz-bar></span></span> <span class=\"rz-bar-wrapper rz-right-out-selection\"><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\" ng-style=barStyle></span></span> <span class=\"rz-pointer rz-pointer-min\" ng-style=minPointerStyle></span> <span class=\"rz-pointer rz-pointer-max\" ng-style=maxPointerStyle></span> <span class=\"rz-bubble rz-limit rz-floor\"></span> <span class=\"rz-bubble rz-limit rz-ceil\"></span> <span class=\"rz-bubble rz-model-value\"></span> <span class=\"rz-bubble rz-model-high\"></span> <span class=rz-bubble></span><ul ng-show=showTicks class=rz-ticks><li ng-repeat=\"t in ticks track by $index\" class=rz-tick ng-class=\"{'rz-selected': t.selected}\" ng-style=t.style ng-attr-uib-tooltip=\"{{ t.tooltip }}\" ng-attr-tooltip-placement={{t.tooltipPlacement}} ng-attr-tooltip-append-to-body=\"{{ t.tooltip ? true : undefined}}\"><span ng-if=\"t.value != null\" class=rz-tick-value ng-attr-uib-tooltip=\"{{ t.valueTooltip }}\" ng-attr-tooltip-placement={{t.valueTooltipPlacement}}>{{ t.value }}</span> <span ng-if=\"t.legend != null\" class=rz-tick-legend>{{ t.legend }}</span></li></ul></div>" |
| 2712 | + "<div class=rzslider><span class=\"rz-bar-wrapper rz-left-out-selection\"><span class=rz-bar></span></span> <span class=\"rz-bar-wrapper rz-right-out-selection\"><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\" ng-style=barStyle></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-restricted\" ng-style=restrictionStyle></span></span> <span class=\"rz-pointer rz-pointer-min\" ng-style=minPointerStyle></span> <span class=\"rz-pointer rz-pointer-max\" ng-style=maxPointerStyle></span> <span class=\"rz-bubble rz-limit rz-floor\"></span> <span class=\"rz-bubble rz-limit rz-ceil\"></span> <span class=\"rz-bubble rz-model-value\"></span> <span class=\"rz-bubble rz-model-high\"></span> <span class=rz-bubble></span><ul ng-show=showTicks class=rz-ticks><li ng-repeat=\"t in ticks track by $index\" class=rz-tick ng-class=\"{'rz-selected': t.selected}\" ng-style=t.style ng-attr-uib-tooltip=\"{{ t.tooltip }}\" ng-attr-tooltip-placement={{t.tooltipPlacement}} ng-attr-tooltip-append-to-body=\"{{ t.tooltip ? true : undefined}}\"><span ng-if=\"t.value != null\" class=rz-tick-value ng-attr-uib-tooltip=\"{{ t.valueTooltip }}\" ng-attr-tooltip-placement={{t.valueTooltipPlacement}}>{{ t.value }}</span> <span ng-if=\"t.legend != null\" class=rz-tick-legend>{{ t.legend }}</span></li></ul></div>" |
2658 | 2713 | ); |
2659 | 2714 |
|
2660 | 2715 | }]); |
|
0 commit comments