Skip to content

Commit b7a01c5

Browse files
author
Valentin Hervieu
committed
Add a rzSliderShowTicks attribute.
1 parent 6e5ffa5 commit b7a01c5

File tree

9 files changed

+148
-15
lines changed

9 files changed

+148
-15
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ $scope.priceSlider = {
127127

128128
> Function to be called when a slider update is ended.
129129
130+
**rz-slider-show-ticks**
131+
132+
> Display a tick for each value.
133+
130134
```javascript
131135
// In your controller
132136

@@ -155,7 +159,8 @@ $scope.onSliderChange = function()
155159
rz-slider-model="priceSlider.min"
156160
rz-slider-high="priceSlider.max"
157161
rz-slider-translate="translate"
158-
rz-slider-on-change="onSliderChange()"></rzslider>
162+
rz-slider-on-change="onSliderChange()"
163+
rz-slider-show-ticks="true"></rzslider>
159164
```
160165

161166
## Slider events

demo/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ <h2>Alphabet slider example</h2>
8585
rz-slider-tpl-url="rzSliderTpl.html"></rzslider>
8686
</article>
8787

88+
<article>
89+
<h2>Slider with ticks example</h2>
90+
Value: {{ priceSlider4 | json }}
91+
<rzslider rz-slider-model="priceSlider4"
92+
rz-slider-floor="0"
93+
rz-slider-ceil="10"
94+
rz-slider-show-ticks="true"></rzslider>
95+
</article>
96+
8897
<article>
8998
<h2>Draggable range example</h2>
9099
Value:
@@ -131,6 +140,7 @@ <h2>Toggle slider example</h2>
131140

132141
$scope.priceSlider2 = 150;
133142
$scope.priceSlider3 = 250;
143+
$scope.priceSlider4 = 5;
134144

135145
$scope.translate = function(value) {
136146
return '$' + value;

dist/rzslider.css

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rzslider span.rz-base {
3434

3535
rzslider span.rz-bar-wrapper {
3636
left: 0;
37+
z-index: 1;
3738
width: 100%;
3839
height: 32px;
3940
padding-top: 16px;
@@ -43,7 +44,7 @@ rzslider span.rz-bar-wrapper {
4344

4445
rzslider span.rz-bar {
4546
left: 0;
46-
z-index: 0;
47+
z-index: 1;
4748
width: 100%;
4849
height: 4px;
4950
background: #d8e0f3;
@@ -53,7 +54,7 @@ rzslider span.rz-bar {
5354
}
5455

5556
rzslider span.rz-bar.rz-selection {
56-
z-index: 1;
57+
z-index: 2;
5758
background: #0db9f0;
5859
-webkit-border-radius: 2px;
5960
-moz-border-radius: 2px;
@@ -62,7 +63,7 @@ rzslider span.rz-bar.rz-selection {
6263

6364
rzslider span.rz-pointer {
6465
top: -14px;
65-
z-index: 2;
66+
z-index: 3;
6667
width: 32px;
6768
height: 32px;
6869
cursor: pointer;
@@ -106,4 +107,23 @@ rzslider span.rz-bubble.rz-selection {
106107

107108
rzslider span.rz-bubble.rz-limit {
108109
color: #55637d;
110+
}
111+
112+
rzslider .rz-ticks {
113+
position: absolute;
114+
top: -3px;
115+
z-index: 1;
116+
display: flex;
117+
padding: 0;
118+
margin: 0;
119+
list-style: none;
120+
justify-content: space-between;
121+
}
122+
123+
rzslider .rz-ticks li {
124+
width: 10px;
125+
height: 10px;
126+
cursor: pointer;
127+
background: #666666;
128+
border-radius: 50%;
109129
}

dist/rzslider.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ function throttle(func, wait, options) {
211211
*/
212212
this.presentOnly = attributes.rzSliderPresentOnly === 'true';
213213

214+
/**
215+
* Display ticks on each possible value.
216+
*
217+
* @type {boolean}
218+
*/
219+
this.showTicks = attributes.rzSliderShowTicks === 'true';
220+
214221
/**
215222
* The delta between min and max value
216223
*
@@ -249,6 +256,7 @@ function throttle(func, wait, options) {
249256
this.minLab = null; // Label above the low value
250257
this.maxLab = null; // Label above the high value
251258
this.cmbLab = null; // Combined label
259+
this.ticks = null; // The ticks
252260

253261
// Initialize slider
254262
this.init();
@@ -281,6 +289,8 @@ function throttle(func, wait, options) {
281289
self.updateFloorLab();
282290
self.initHandles();
283291
if (!self.presentOnly) { self.bindEvents(); }
292+
if(self.showTicks)
293+
self.updateTicksScale();
284294
});
285295

286296
// Recalculate slider view dimensions
@@ -359,6 +369,7 @@ function throttle(func, wait, options) {
359369
self.maxH.off();
360370
self.fullBar.off();
361371
self.selBar.off();
372+
self.ticks.off();
362373
angular.element($window).off('resize', calcDimFn);
363374
self.deRegFuncs.map(function(unbind) { unbind(); });
364375
});
@@ -493,6 +504,7 @@ function throttle(func, wait, options) {
493504
case 6: this.minLab = jElem; break;
494505
case 7: this.maxLab = jElem; break;
495506
case 8: this.cmbLab = jElem; break;
507+
case 9: this.ticks = jElem; break;
496508
}
497509

498510
}, this);
@@ -506,6 +518,7 @@ function throttle(func, wait, options) {
506518
this.minLab.rzsl = 0;
507519
this.maxLab.rzsl = 0;
508520
this.cmbLab.rzsl = 0;
521+
this.ticks.rzsl = 0;
509522

510523
// Hide limit labels
511524
if(this.hideLimitLabels)
@@ -561,6 +574,8 @@ function throttle(func, wait, options) {
561574

562575
this.getWidth(this.sliderElem);
563576
this.sliderElem.rzsl = this.sliderElem[0].getBoundingClientRect().left;
577+
if(this.showTicks)
578+
this.updateTicksScale();
564579

565580
if(this.initHasRun)
566581
{
@@ -569,6 +584,24 @@ function throttle(func, wait, options) {
569584
}
570585
},
571586

587+
/**
588+
* Update the ticks position
589+
*
590+
* @returns {undefined}
591+
*/
592+
updateTicksScale: function() {
593+
var positions = '';
594+
for (var i = this.minValue; i < this.maxValue; i += this.step) {
595+
positions += '<li></li>';
596+
}
597+
positions += '<li></li>';
598+
this.ticks.html(positions);
599+
this.ticks.css({
600+
width: (this.barWidth - 2 * this.handleHalfWidth) + 'px',
601+
left: this.handleHalfWidth + 'px'
602+
});
603+
},
604+
572605
/**
573606
* Update position of the ceiling label
574607
*
@@ -974,13 +1007,17 @@ function throttle(func, wait, options) {
9741007
this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar));
9751008
this.selBar.on('mousedown', angular.bind(this, barStart, null, barTracking));
9761009
this.selBar.on('mousedown', angular.bind(this, barMove, this.selBar));
1010+
this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null));
1011+
this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks));
9771012

9781013
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
9791014
if(this.range) { this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')); }
9801015
this.fullBar.on('touchstart', angular.bind(this, this.onStart, null, null));
9811016
this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar));
9821017
this.selBar.on('touchstart', angular.bind(this, barStart, null, barTracking));
9831018
this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar));
1019+
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
1020+
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
9841021
},
9851022

9861023
/**
@@ -1266,7 +1303,8 @@ function throttle(func, wait, options) {
12661303
rzSliderPresentOnly: '@',
12671304
rzSliderOnStart: '&',
12681305
rzSliderOnChange: '&',
1269-
rzSliderOnEnd: '&'
1306+
rzSliderOnEnd: '&',
1307+
rzSliderShowTicks: '@'
12701308
},
12711309

12721310
/**
@@ -1325,7 +1363,7 @@ function throttle(func, wait, options) {
13251363
'use strict';
13261364

13271365
$templateCache.put('rzSliderTpl.html',
1328-
"<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>"
1366+
"<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>"
13291367
);
13301368

13311369
}]);

dist/rzslider.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)