Skip to content

Commit 38da47f

Browse files
author
Valentin Hervieu
committed
Refactor the ticks logic by using true angular power
1 parent 20ddee8 commit 38da47f

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

dist/rzslider.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
this.range = this.scope.rzSliderModel !== undefined && this.scope.rzSliderHigh !== undefined;
377377
this.options.draggableRange = this.range && this.options.draggableRange;
378378
this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
379+
this.scope.showTicks = this.options.showTicks; //scope is used in the template
379380

380381
if (this.options.stepsArray) {
381382
this.options.floor = 0;
@@ -488,9 +489,6 @@
488489
this.alwaysHide(this.cmbLab, this.options.showTicksValues || !this.range);
489490
this.alwaysHide(this.selBar, !this.range && !this.options.showSelectionBar);
490491

491-
if (!this.options.showTicks)
492-
this.ticks.html('');
493-
494492
if (this.options.draggableRange)
495493
this.selBar.addClass('rz-draggable');
496494
else
@@ -657,28 +655,25 @@
657655
*/
658656
updateTicksScale: function() {
659657
if (!this.options.showTicks) return;
660-
if (!this.step) return; //if step is 0, the following loop will be endless.
658+
if (!this.step) return; //if step is 0, we'll get a zero division
661659

662660
var positions = '',
663661
ticksCount = Math.round((this.maxValue - this.minValue) / this.step) + 1;
662+
this.scope.ticks = [];
664663
for (var i = 0; i < ticksCount; i++) {
665664
var value = this.roundStep(this.minValue + i * this.step);
666-
var selectedClass = this.isTickSelected(value) ? 'selected' : '';
667-
positions += '<li class="tick ' + selectedClass + '">';
665+
var tick = {
666+
selected: this.isTickSelected(value)
667+
};
668668
if (this.options.showTicksValues) {
669-
var tooltip = '';
669+
tick.value = this.getDisplayValue(value);
670670
if (this.options.ticksValuesTooltip) {
671-
tooltip = 'uib-tooltip="' + this.options.ticksValuesTooltip(value) + '"';
672-
if (this.options.vertical)
673-
tooltip += ' tooltip-placement="right"'
671+
tick.tooltip = this.options.ticksValuesTooltip(value);
672+
tick.tooltipPlacement = this.options.vertical ? 'right' : 'top';
674673
}
675-
positions += '<span ' + tooltip + ' class="tick-value">' + this.getDisplayValue(value) + '</span>';
676674
}
677-
positions += '</li>';
675+
this.scope.ticks.push(tick);
678676
}
679-
this.ticks.html(positions);
680-
if (this.options.ticksValuesTooltip)
681-
$compile(this.ticks.contents())(this.scope);
682677
},
683678

684679
isTickSelected: function(value) {
@@ -1433,7 +1428,7 @@
14331428
'use strict';
14341429

14351430
$templateCache.put('rzSliderTpl.html',
1436-
"<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>"
1431+
"<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>"
14371432
);
14381433

14391434
}]);

0 commit comments

Comments
 (0)