|
1 | 1 | /*! angularjs-slider - v2.12.0 -
|
2 | 2 | (c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
|
3 | 3 | https://github.com/angular-slider/angularjs-slider -
|
4 |
| - 2016-04-22 */ |
| 4 | + 2016-04-24 */ |
5 | 5 | /*jslint unparam: true */
|
6 | 6 | /*global angular: false, console: false, define, module */
|
7 | 7 | (function(root, factory) {
|
|
34 | 34 | minRange: 0,
|
35 | 35 | id: null,
|
36 | 36 | translate: null,
|
| 37 | + getLegend: null, |
37 | 38 | stepsArray: null,
|
38 | 39 | draggableRange: false,
|
39 | 40 | draggableRangeOnly: false,
|
|
424 | 425 |
|
425 | 426 | this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
|
426 | 427 | this.scope.showTicks = this.options.showTicks; //scope is used in the template
|
427 |
| - if(angular.isNumber(this.options.showTicks)) |
| 428 | + if (angular.isNumber(this.options.showTicks)) |
428 | 429 | this.intermediateTicks = true;
|
429 | 430 |
|
430 | 431 | this.options.showSelectionBar = this.options.showSelectionBar || this.options.showSelectionBarEnd
|
431 | 432 | || this.options.showSelectionBarFromValue !== null;
|
432 | 433 |
|
433 | 434 | if (this.options.stepsArray) {
|
434 |
| - this.options.floor = 0; |
435 |
| - this.options.ceil = this.options.stepsArray.length - 1; |
436 |
| - this.options.step = 1; |
437 |
| - if (this.options.translate) { |
| 435 | + this.parseStepsArray(); |
| 436 | + } else { |
| 437 | + if (this.options.translate) |
438 | 438 | this.customTrFn = this.options.translate;
|
439 |
| - } |
440 |
| - else { |
| 439 | + else |
441 | 440 | this.customTrFn = function(value) {
|
442 |
| - return this.options.stepsArray[value]; |
| 441 | + return String(value); |
443 | 442 | };
|
| 443 | + |
| 444 | + if (this.options.getLegend) { |
| 445 | + this.getLegend = this.options.getLegend; |
444 | 446 | }
|
445 |
| - } else if (this.options.translate) |
446 |
| - this.customTrFn = this.options.translate; |
447 |
| - else |
448 |
| - this.customTrFn = function(value) { |
449 |
| - return String(value); |
450 |
| - }; |
| 447 | + } |
451 | 448 |
|
452 | 449 | if (this.options.vertical) {
|
453 | 450 | this.positionProperty = 'bottom';
|
454 | 451 | this.dimensionProperty = 'height';
|
455 | 452 | }
|
456 | 453 | },
|
457 | 454 |
|
| 455 | + parseStepsArray: function() { |
| 456 | + this.options.floor = 0; |
| 457 | + this.options.ceil = this.options.stepsArray.length - 1; |
| 458 | + this.options.step = 1; |
| 459 | + |
| 460 | + if (this.options.translate) { |
| 461 | + this.customTrFn = this.options.translate; |
| 462 | + } |
| 463 | + else { |
| 464 | + this.customTrFn = function(index) { |
| 465 | + var step = this.options.stepsArray[index]; |
| 466 | + if (angular.isObject(step)) |
| 467 | + return step.value; |
| 468 | + return step; |
| 469 | + }; |
| 470 | + } |
| 471 | + |
| 472 | + this.getLegend = function(index) { |
| 473 | + var step = this.options.stepsArray[index]; |
| 474 | + if (angular.isObject(step)) |
| 475 | + return step.legend; |
| 476 | + return null; |
| 477 | + }; |
| 478 | + }, |
| 479 | + |
458 | 480 | /**
|
459 | 481 | * Resets slider
|
460 | 482 | *
|
|
558 | 580 | else
|
559 | 581 | this.selBar.removeClass('rz-draggable');
|
560 | 582 |
|
561 |
| - if(this.intermediateTicks && this.options.showTicksValues) |
| 583 | + if (this.intermediateTicks && this.options.showTicksValues) |
562 | 584 | this.ticks.addClass('rz-ticks-values-under');
|
563 | 585 | },
|
564 | 586 |
|
|
768 | 790 | updateTicksScale: function() {
|
769 | 791 | if (!this.options.showTicks) return;
|
770 | 792 | var step = this.step;
|
771 |
| - if(this.intermediateTicks) |
| 793 | + if (this.intermediateTicks) |
772 | 794 | step = this.options.showTicks;
|
773 | 795 | var ticksCount = Math.round((this.maxValue - this.minValue) / step) + 1;
|
774 | 796 | this.scope.ticks = [];
|
|
793 | 815 | tick.valueTooltipPlacement = this.options.vertical ? 'right' : 'top';
|
794 | 816 | }
|
795 | 817 | }
|
| 818 | + if (this.getLegend) { |
| 819 | + var legend = this.getLegend(value, this.options.id); |
| 820 | + if (legend) |
| 821 | + tick.legend = legend; |
| 822 | + } |
796 | 823 | if (!this.options.rightToLeft) {
|
797 | 824 | this.scope.ticks.push(tick);
|
798 | 825 | } else {
|
|
1458 | 1485 | newValue = ceilValue;
|
1459 | 1486 | } else {
|
1460 | 1487 | newValue = this.offsetToValue(newOffset);
|
1461 |
| - if(fromTick && angular.isNumber(this.options.showTicks)) |
| 1488 | + if (fromTick && angular.isNumber(this.options.showTicks)) |
1462 | 1489 | newValue = this.roundStep(newValue, this.options.showTicks);
|
1463 | 1490 | else
|
1464 | 1491 | newValue = this.roundStep(newValue);
|
|
1911 | 1938 | 'use strict';
|
1912 | 1939 |
|
1913 | 1940 | $templateCache.put('rzSliderTpl.html',
|
1914 |
| - "<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\"></span> <span class=\"rz-bubble rz-limit\"></span> <span class=rz-bubble></span> <span class=rz-bubble></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></li></ul>" |
| 1941 | + "<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\"></span> <span class=\"rz-bubble rz-limit\"></span> <span class=rz-bubble></span> <span class=rz-bubble></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>" |
1915 | 1942 | );
|
1916 | 1943 |
|
1917 | 1944 | }]);
|
|
0 commit comments