Skip to content

Commit 24c6bf0

Browse files
author
Valentin Hervieu
committed
Support getSelectionBarColor for ticks.
1 parent e5f3ab8 commit 24c6bf0

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed

demo/demo.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
2525
}
2626
};
2727

28-
2928
//Slider with selection bar
3029
$scope.color_slider_bar = {
3130
value: 12,

dist/rzslider.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@
377377
this.range = this.scope.rzSliderModel !== undefined && this.scope.rzSliderHigh !== undefined;
378378
this.options.draggableRange = this.range && this.options.draggableRange;
379379
this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
380-
this.scope.showTicks = this.options.showTicks; //scope is used in the template
381380

382381
if (this.options.stepsArray) {
383382
this.options.floor = 0;
@@ -491,6 +490,9 @@
491490
this.alwaysHide(this.cmbLab, this.options.showTicksValues || !this.range);
492491
this.alwaysHide(this.selBar, !this.range && !this.options.showSelectionBar);
493492

493+
if (!this.options.showTicks)
494+
this.ticks.html('');
495+
494496
if (this.options.draggableRange)
495497
this.selBar.addClass('rz-draggable');
496498
else
@@ -657,25 +659,34 @@
657659
*/
658660
updateTicksScale: function() {
659661
if (!this.options.showTicks) return;
660-
if (!this.step) return; //if step is 0, we'll get a zero division
662+
if (!this.step) return; //if step is 0, the following loop will be endless.
661663

662664
var positions = '',
663665
ticksCount = Math.round((this.maxValue - this.minValue) / this.step) + 1;
664-
this.scope.ticks = [];
665666
for (var i = 0; i < ticksCount; i++) {
666-
var value = this.roundStep(this.minValue + i * this.step);
667-
var tick = {
668-
selected: this.isTickSelected(value)
669-
};
667+
var value = this.roundStep(this.minValue + i * this.step),
668+
selected = this.isTickSelected(value),
669+
selectedClass = selected ? 'selected' : '',
670+
customStyle = '';
671+
if (selected && this.options.getSelectionBarColor) {
672+
var color = this.options.getSelectionBarColor();
673+
customStyle = 'style="background-color: ' + color + '"';
674+
}
675+
positions += '<li class="tick ' + selectedClass + '" ' + customStyle + '>';
670676
if (this.options.showTicksValues) {
671-
tick.value = this.getDisplayValue(value);
677+
var tooltip = '';
672678
if (this.options.ticksValuesTooltip) {
673-
tick.tooltip = this.options.ticksValuesTooltip(value);
674-
tick.tooltipPlacement = this.options.vertical ? 'right' : 'top';
679+
tooltip = 'uib-tooltip="' + this.options.ticksValuesTooltip(value) + '"';
680+
if (this.options.vertical)
681+
tooltip += ' tooltip-placement="right"'
675682
}
683+
positions += '<span ' + tooltip + ' class="tick-value">' + this.getDisplayValue(value) + '</span>';
676684
}
677-
this.scope.ticks.push(tick);
685+
positions += '</li>';
678686
}
687+
this.ticks.html(positions);
688+
if (this.options.ticksValuesTooltip)
689+
$compile(this.ticks.contents())(this.scope);
679690
},
680691

681692
isTickSelected: function(value) {
@@ -865,7 +876,7 @@
865876
updateSelectionBar: function() {
866877
this.setDimension(this.selBar, Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim);
867878
this.setPosition(this.selBar, this.range ? this.minH.rzsp + this.handleHalfDim : 0);
868-
if(this.options.getSelectionBarColor) {
879+
if (this.options.getSelectionBarColor) {
869880
var color = this.options.getSelectionBarColor();
870881
this.selBarChild.css({backgroundColor: color});
871882
}
@@ -1434,7 +1445,7 @@
14341445
'use strict';
14351446

14361447
$templateCache.put('rzSliderTpl.html',
1437-
"<span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\"></span></span> <span class=rz-pointer></span> <span class=rz-pointer></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\" class=tick ng-class=\"{selected: t.selected}\"><span ng-if=\"t.value != null && t.tooltip == null\" class=tick-value>{{ t.value }}</span> <span ng-if=\"t.value != null && t.tooltip != null\" class=tick-value uib-tooltip=\"{{ t.tooltip }}\" tooltip-placement={{t.tooltipPlacement}}>{{ t.value }}</span></li></ul>"
1448+
"<span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\"></span></span> <span class=rz-pointer></span> <span class=rz-pointer></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 class=rz-ticks></ul>"
14381449
);
14391450

14401451
}]);

0 commit comments

Comments
 (0)