|
1 | 1 | /*! angularjs-slider - v2.4.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 | | - 2016-01-15 */ |
| 4 | + 2016-01-22 */ |
5 | 5 | /*jslint unparam: true */ |
6 | 6 | /*global angular: false, console: false, define, module */ |
7 | 7 | (function(root, factory) { |
|
31 | 31 | ceil: null, //defaults to rz-slider-model |
32 | 32 | step: 1, |
33 | 33 | precision: 0, |
| 34 | + minRange: 0, |
34 | 35 | id: null, |
35 | 36 | translate: null, |
36 | 37 | stepsArray: null, |
|
736 | 737 | this.scope.ticks = []; |
737 | 738 | for (var i = 0; i < ticksCount; i++) { |
738 | 739 | var value = this.roundStep(this.minValue + i * this.step); |
739 | | - var tick = { |
| 740 | + var tick = { |
740 | 741 | selected: this.isTickSelected(value) |
741 | 742 | }; |
742 | 743 | if (tick.selected && this.options.getSelectionBarColor) { |
|
1514 | 1515 | var switched = false; |
1515 | 1516 |
|
1516 | 1517 | if (this.range) { |
1517 | | - /* This is to check if we need to switch the min and max handles*/ |
| 1518 | + newValue = this.applyMinRange(newValue); |
| 1519 | + newOffset = this.valueToOffset(newValue); |
| 1520 | + /* This is to check if we need to switch the min and max handles */ |
1518 | 1521 | if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) { |
1519 | 1522 | switched = true; |
1520 | 1523 | this.scope[this.tracking] = this.scope.rzSliderHigh; |
|
1553 | 1556 | return switched; |
1554 | 1557 | }, |
1555 | 1558 |
|
| 1559 | + applyMinRange: function(newValue) { |
| 1560 | + if (this.options.minRange !== 0) { |
| 1561 | + var oppositeValue = this.tracking === 'rzSliderModel' ? this.scope.rzSliderHigh : this.scope.rzSliderModel, |
| 1562 | + difference = Math.abs(newValue - oppositeValue); |
| 1563 | + |
| 1564 | + if (difference < this.options.minRange) { |
| 1565 | + if (this.tracking === 'rzSliderModel') |
| 1566 | + return this.scope.rzSliderHigh - this.options.minRange; |
| 1567 | + else |
| 1568 | + return this.scope.rzSliderModel + this.options.minRange; |
| 1569 | + } |
| 1570 | + } |
| 1571 | + return newValue; |
| 1572 | + }, |
| 1573 | + |
1556 | 1574 | /** |
1557 | 1575 | * Apply the model values using scope.$apply. |
1558 | 1576 | * We wrap it with the internalChange flag to avoid the watchers to be called |
|
0 commit comments