Skip to content

Commit 88cbd3b

Browse files
author
Valentin Hervieu
committed
Add the step value on the ticks
1 parent 2ad1f0e commit 88cbd3b

9 files changed

+157
-55
lines changed

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = function(grunt) {
100100
},
101101
watch: {
102102
all: {
103-
files: ['dist/*'],
103+
files: ['dist/*', 'demo/*'],
104104
options: {
105105
livereload: true
106106
}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ $scope.priceSlider = {
131131

132132
> Display a tick for each value.
133133
134+
**rz-slider-show-ticks-value**
135+
136+
> Display a tick for each value and the value of the tick.
137+
134138
```javascript
135139
// In your controller
136140

demo/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ <h2>Slider with ticks example</h2>
9494
rz-slider-show-ticks="true"></rzslider>
9595
</article>
9696

97+
<article>
98+
<h2>Slider with ticks value example</h2>
99+
Value: {{ priceSlider5 | json }}
100+
<rzslider rz-slider-model="priceSlider5"
101+
rz-slider-floor="0"
102+
rz-slider-ceil="10"
103+
rz-slider-show-ticks-value="true"></rzslider>
104+
</article>
105+
97106
<article>
98107
<h2>Draggable range example</h2>
99108
Value:
@@ -141,6 +150,7 @@ <h2>Toggle slider example</h2>
141150
$scope.priceSlider2 = 150;
142151
$scope.priceSlider3 = 250;
143152
$scope.priceSlider4 = 5;
153+
$scope.priceSlider5 = 5;
144154

145155
$scope.translate = function(value) {
146156
return '$' + value;

dist/rzslider.css

+12-2
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,28 @@ rzslider span.rz-bubble.rz-limit {
112112
rzslider .rz-ticks {
113113
position: absolute;
114114
top: -3px;
115+
left: 0;
115116
z-index: 1;
116117
display: flex;
117-
padding: 0;
118+
width: 100%;
119+
padding: 0 11px;
118120
margin: 0;
119121
list-style: none;
122+
box-sizing: border-box;
120123
justify-content: space-between;
121124
}
122125

123-
rzslider .rz-ticks li {
126+
rzslider .rz-ticks .tick {
124127
width: 10px;
125128
height: 10px;
129+
text-align: center;
126130
cursor: pointer;
127131
background: #666666;
128132
border-radius: 50%;
133+
}
134+
135+
rzslider .rz-ticks .tick .tick-value {
136+
position: absolute;
137+
top: -30px;
138+
transform: translate(-50%, 0);
129139
}

dist/rzslider.js

+53-20
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,14 @@ function throttle(func, wait, options) {
216216
*
217217
* @type {boolean}
218218
*/
219-
this.showTicks = attributes.rzSliderShowTicks === 'true';
219+
this.showTicks = attributes.rzSliderShowTicks || attributes.rzSliderShowTicksValue;
220+
221+
/**
222+
* Display the value on each tick.
223+
*
224+
* @type {boolean}
225+
*/
226+
this.showTicksValue = attributes.rzSliderShowTicksValue;
220227

221228
/**
222229
* The delta between min and max value
@@ -363,6 +370,20 @@ function throttle(func, wait, options) {
363370
});
364371
this.deRegFuncs.push(unRegFn);
365372

373+
unRegFn = this.scope.$watch('rzSliderShowTicks', function(newValue, oldValue)
374+
{
375+
if(newValue === oldValue) { return; }
376+
self.resetSlider();
377+
});
378+
this.deRegFuncs.push(unRegFn);
379+
380+
unRegFn = this.scope.$watch('rzSliderShowTicksValue', function(newValue, oldValue)
381+
{
382+
if(newValue === oldValue) { return; }
383+
self.resetSlider();
384+
});
385+
this.deRegFuncs.push(unRegFn);
386+
366387
this.scope.$on('$destroy', function()
367388
{
368389
self.minH.off();
@@ -518,7 +539,6 @@ function throttle(func, wait, options) {
518539
this.minLab.rzsl = 0;
519540
this.maxLab.rzsl = 0;
520541
this.cmbLab.rzsl = 0;
521-
this.ticks.rzsl = 0;
522542

523543
// Hide limit labels
524544
if(this.hideLimitLabels)
@@ -529,6 +549,17 @@ function throttle(func, wait, options) {
529549
this.hideEl(this.ceilLab);
530550
}
531551

552+
if(this.showTicksValue) {
553+
this.flrLab.rzAlwaysHide = true;
554+
this.ceilLab.rzAlwaysHide = true;
555+
this.minLab.rzAlwaysHide = true;
556+
this.maxLab.rzAlwaysHide = true;
557+
this.hideEl(this.flrLab);
558+
this.hideEl(this.ceilLab);
559+
this.hideEl(this.minLab);
560+
this.hideEl(this.maxLab);
561+
}
562+
532563
// Remove stuff not needed in single slider
533564
if(this.range === false)
534565
{
@@ -590,16 +621,16 @@ function throttle(func, wait, options) {
590621
* @returns {undefined}
591622
*/
592623
updateTicksScale: function() {
624+
if(!this.step) return; //if step is 0, the following loop will be endless.
625+
593626
var positions = '';
594-
for (var i = this.minValue; i < this.maxValue; i += this.step) {
595-
positions += '<li></li>';
627+
for (var i = this.minValue; i <= this.maxValue; i += this.step) {
628+
positions += '<li class="tick">';
629+
if(this.showTicksValue)
630+
positions += '<span class="tick-value">'+ this.getDisplayValue(i) +'</span>';
631+
positions += '</li>';
596632
}
597-
positions += '<li></li>';
598633
this.ticks.html(positions);
599-
this.ticks.css({
600-
width: (this.barWidth - 2 * this.handleHalfWidth) + 'px',
601-
left: this.handleHalfWidth + 'px'
602-
});
603634
},
604635

605636
/**
@@ -816,16 +847,8 @@ function throttle(func, wait, options) {
816847

817848
if(this.minLab.rzsl + this.minLab.rzsw + 10 >= this.maxLab.rzsl)
818849
{
819-
if(this.customTrFn)
820-
{
821-
lowTr = this.customTrFn(this.scope.rzSliderModel);
822-
highTr = this.customTrFn(this.scope.rzSliderHigh);
823-
}
824-
else
825-
{
826-
lowTr = this.scope.rzSliderModel;
827-
highTr = this.scope.rzSliderHigh;
828-
}
850+
lowTr = this.getDisplayValue(this.scope.rzSliderModel);
851+
highTr = this.getDisplayValue(this.scope.rzSliderHigh);
829852

830853
this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false);
831854
this.setLeft(this.cmbLab, this.selBar.rzsl + this.selBar.rzsw / 2 - this.cmbLab.rzsw / 2);
@@ -841,6 +864,15 @@ function throttle(func, wait, options) {
841864
}
842865
},
843866

867+
/**
868+
* Return the translated value if a translate function is provided else the original value
869+
* @param value
870+
* @returns {*}
871+
*/
872+
getDisplayValue: function(value) {
873+
return this.customTrFn ? this.customTrFn(value): value;
874+
},
875+
844876
/**
845877
* Round value to step and precision
846878
*
@@ -1304,7 +1336,8 @@ function throttle(func, wait, options) {
13041336
rzSliderOnStart: '&',
13051337
rzSliderOnChange: '&',
13061338
rzSliderOnEnd: '&',
1307-
rzSliderShowTicks: '@'
1339+
rzSliderShowTicks: '=?',
1340+
rzSliderShowTicksValue: '=?'
13081341
},
13091342

13101343
/**

dist/rzslider.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)