|
1 |
| -/*! angularjs-slider - v5.5.1 - |
| 1 | +/*! angularjs-slider - v5.6.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 |
| - 2016-10-07 */ |
| 4 | + 2016-10-16 */ |
5 | 5 | /*jslint unparam: true */
|
6 | 6 | /*global angular: false, console: false, define, module */
|
7 | 7 | (function(root, factory) {
|
|
54 | 54 | interval: 350,
|
55 | 55 | showTicks: false,
|
56 | 56 | showTicksValues: false,
|
| 57 | + ticksArray: null, |
57 | 58 | ticksTooltip: null,
|
58 | 59 | ticksValuesTooltip: null,
|
59 | 60 | vertical: false,
|
|
543 | 544 | this.options.draggableRange = true;
|
544 | 545 | }
|
545 | 546 |
|
546 |
| - this.options.showTicks = this.options.showTicks || this.options.showTicksValues; |
| 547 | + this.options.showTicks = this.options.showTicks || this.options.showTicksValues || !!this.options.ticksArray; |
547 | 548 | this.scope.showTicks = this.options.showTicks; //scope is used in the template
|
548 |
| - if (angular.isNumber(this.options.showTicks)) |
| 549 | + if (angular.isNumber(this.options.showTicks) || this.options.ticksArray) |
549 | 550 | this.intermediateTicks = true;
|
550 | 551 |
|
551 | 552 | this.options.showSelectionBar = this.options.showSelectionBar || this.options.showSelectionBarEnd
|
|
929 | 930 | this.updateFloorLab();
|
930 | 931 | this.updateCeilLab();
|
931 | 932 | this.initHandles();
|
| 933 | + var self = this; |
| 934 | + $timeout(function() { |
| 935 | + self.updateTicksScale(); |
| 936 | + }); |
932 | 937 | }
|
933 | 938 | },
|
934 | 939 |
|
|
939 | 944 | */
|
940 | 945 | updateTicksScale: function() {
|
941 | 946 | if (!this.options.showTicks) return;
|
942 |
| - var step = this.step; |
943 |
| - if (this.intermediateTicks) |
944 |
| - step = this.options.showTicks; |
945 |
| - var ticksCount = Math.round((this.maxValue - this.minValue) / step) + 1; |
946 |
| - this.scope.ticks = []; |
947 |
| - for (var i = 0; i < ticksCount; i++) { |
948 |
| - var value = this.roundStep(this.minValue + i * step); |
| 947 | + |
| 948 | + var ticksArray = this.options.ticksArray || this.getTicksArray(), |
| 949 | + translate = this.options.vertical ? 'translateY' : 'translateX', |
| 950 | + self = this; |
| 951 | + |
| 952 | + if(this.options.rightToLeft) |
| 953 | + ticksArray.reverse(); |
| 954 | + |
| 955 | + this.scope.ticks = ticksArray.map(function(value){ |
| 956 | + var offset = self.valueToOffset(value); |
| 957 | + |
| 958 | + if (self.options.vertical) |
| 959 | + offset = self.maxPos - offset; |
| 960 | + |
949 | 961 | var tick = {
|
950 |
| - selected: this.isTickSelected(value) |
| 962 | + selected: self.isTickSelected(value), |
| 963 | + style: { |
| 964 | + transform: translate + '(' + offset + 'px)' |
| 965 | + } |
951 | 966 | };
|
952 |
| - if (tick.selected && this.options.getSelectionBarColor) { |
953 |
| - tick.style = { |
954 |
| - 'background-color': this.getSelectionBarColor() |
955 |
| - }; |
| 967 | + if (tick.selected && self.options.getSelectionBarColor) { |
| 968 | + tick.style['background-color'] = self.getSelectionBarColor(); |
956 | 969 | }
|
957 |
| - if (!tick.selected && this.options.getTickColor) { |
958 |
| - tick.style = { |
959 |
| - 'background-color': this.getTickColor(value) |
960 |
| - } |
| 970 | + if (!tick.selected && self.options.getTickColor) { |
| 971 | + tick.style['background-color'] = self.getTickColor(value); |
961 | 972 | }
|
962 |
| - if (this.options.ticksTooltip) { |
963 |
| - tick.tooltip = this.options.ticksTooltip(value); |
964 |
| - tick.tooltipPlacement = this.options.vertical ? 'right' : 'top'; |
| 973 | + if (self.options.ticksTooltip) { |
| 974 | + tick.tooltip = self.options.ticksTooltip(value); |
| 975 | + tick.tooltipPlacement = self.options.vertical ? 'right' : 'top'; |
965 | 976 | }
|
966 |
| - if (this.options.showTicksValues) { |
967 |
| - tick.value = this.getDisplayValue(value, 'tick-value'); |
968 |
| - if (this.options.ticksValuesTooltip) { |
969 |
| - tick.valueTooltip = this.options.ticksValuesTooltip(value); |
970 |
| - tick.valueTooltipPlacement = this.options.vertical ? 'right' : 'top'; |
| 977 | + if (self.options.showTicksValues) { |
| 978 | + tick.value = self.getDisplayValue(value, 'tick-value'); |
| 979 | + if (self.options.ticksValuesTooltip) { |
| 980 | + tick.valueTooltip = self.options.ticksValuesTooltip(value); |
| 981 | + tick.valueTooltipPlacement = self.options.vertical ? 'right' : 'top'; |
971 | 982 | }
|
972 | 983 | }
|
973 |
| - if (this.getLegend) { |
974 |
| - var legend = this.getLegend(value, this.options.id); |
| 984 | + if (self.getLegend) { |
| 985 | + var legend = self.getLegend(value, self.options.id); |
975 | 986 | if (legend)
|
976 | 987 | tick.legend = legend;
|
977 | 988 | }
|
978 |
| - if (!this.options.rightToLeft) { |
979 |
| - this.scope.ticks.push(tick); |
980 |
| - } else { |
981 |
| - this.scope.ticks.unshift(tick); |
982 |
| - } |
| 989 | + return tick; |
| 990 | + }); |
| 991 | + }, |
| 992 | + |
| 993 | + getTicksArray: function() { |
| 994 | + var step = this.step, |
| 995 | + ticksArray = []; |
| 996 | + if (this.intermediateTicks) |
| 997 | + step = this.options.showTicks; |
| 998 | + for (var value = this.minValue; value <= this.maxValue; value += step) { |
| 999 | + ticksArray.push(value); |
983 | 1000 | }
|
| 1001 | + return ticksArray; |
984 | 1002 | },
|
985 | 1003 |
|
986 | 1004 | isTickSelected: function(value) {
|
|
0 commit comments