Skip to content

Commit 82f406b

Browse files
committed
Merge pull request #264 from angular-slider/feature/show-ticks-at
feat(ticks): Accept numbers for showTicks/showTicksValues
2 parents 80ae07c + 76f1ef5 commit 82f406b

12 files changed

+279
-34
lines changed

demo/demo.js

+20
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,26 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
237237
}
238238
};
239239

240+
//Slider with ticks at intermediate positions
241+
$scope.slider_ticks_at = {
242+
value: 500,
243+
options: {
244+
ceil: 1000,
245+
floor: 0,
246+
showTicks: 100
247+
}
248+
};
249+
250+
//Slider with ticks and values at intermediate positions
251+
$scope.slider_ticks_values_at = {
252+
value: 500,
253+
options: {
254+
ceil: 1000,
255+
floor: 0,
256+
showTicksValues: 100
257+
}
258+
};
259+
240260
//Slider with draggable range
241261
$scope.slider_draggable_range = {
242262
minValue: 1,

demo/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,22 @@ <h2>Range slider with ticks and values</h2>
181181
></rzslider>
182182
</article>
183183

184+
<article>
185+
<h2>Slider with ticks at intermediate positions</h2>
186+
<rzslider
187+
rz-slider-model="slider_ticks_at.value"
188+
rz-slider-options="slider_ticks_at.options"
189+
></rzslider>
190+
</article>
191+
192+
<article>
193+
<h2>Slider with ticks and values at intermediate positions</h2>
194+
<rzslider
195+
rz-slider-model="slider_ticks_values_at.value"
196+
rz-slider-options="slider_ticks_values_at.options"
197+
></rzslider>
198+
</article>
199+
184200
<article>
185201
<h2>Slider with draggable range</h2>
186202
<rzslider

dist/rzslider.css

+12-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ rzslider .rz-ticks .rz-tick .rz-tick-value {
159159
transform: translate(-50%, 0);
160160
}
161161

162+
rzslider .rz-ticks.rz-ticks-values-under .rz-tick-value {
163+
top: initial;
164+
bottom: -40px;
165+
}
166+
162167
rzslider.rz-vertical {
163168
position: relative;
164169
width: 4px;
@@ -224,7 +229,13 @@ rzslider.rz-vertical .rz-ticks .rz-tick {
224229
}
225230

226231
rzslider.rz-vertical .rz-ticks .rz-tick .rz-tick-value {
227-
top: auto;
232+
top: initial;
228233
left: 22px;
229234
transform: translate(0, -28%);
235+
}
236+
237+
rzslider.rz-vertical .rz-ticks.rz-ticks-values-under .rz-tick-value {
238+
right: 12px;
239+
bottom: initial;
240+
left: initial;
230241
}

dist/rzslider.js

+43-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.11.0 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-04-01 */
4+
2016-04-22 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -247,6 +247,14 @@
247247
*/
248248
this.valueRange = 0;
249249

250+
251+
/**
252+
* If showTicks/showTicksValues options are number.
253+
* In this case, ticks values should be displayed below the slider.
254+
* @type {boolean}
255+
*/
256+
this.intermediateTicks = false;
257+
250258
/**
251259
* Set to true if init method already executed
252260
*
@@ -416,6 +424,8 @@
416424

417425
this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
418426
this.scope.showTicks = this.options.showTicks; //scope is used in the template
427+
if(angular.isNumber(this.options.showTicks))
428+
this.intermediateTicks = true;
419429

420430
this.options.showSelectionBar = this.options.showSelectionBar || this.options.showSelectionBarEnd
421431
|| this.options.showSelectionBarFromValue !== null;
@@ -530,11 +540,14 @@
530540
else
531541
this.maxH.css('display', '');
532542

543+
533544
this.alwaysHide(this.flrLab, this.options.showTicksValues || this.options.hideLimitLabels);
534545
this.alwaysHide(this.ceilLab, this.options.showTicksValues || this.options.hideLimitLabels);
535-
this.alwaysHide(this.minLab, this.options.showTicksValues || this.options.hidePointerLabels);
536-
this.alwaysHide(this.maxLab, this.options.showTicksValues || !this.range || this.options.hidePointerLabels);
537-
this.alwaysHide(this.cmbLab, this.options.showTicksValues || !this.range || this.options.hidePointerLabels);
546+
547+
var hideLabelsForTicks = this.options.showTicksValues && !this.intermediateTicks;
548+
this.alwaysHide(this.minLab, hideLabelsForTicks || this.options.hidePointerLabels);
549+
this.alwaysHide(this.maxLab, hideLabelsForTicks || !this.range || this.options.hidePointerLabels);
550+
this.alwaysHide(this.cmbLab, hideLabelsForTicks || !this.range || this.options.hidePointerLabels);
538551
this.alwaysHide(this.selBar, !this.range && !this.options.showSelectionBar);
539552

540553
if (this.options.vertical)
@@ -544,6 +557,9 @@
544557
this.selBar.addClass('rz-draggable');
545558
else
546559
this.selBar.removeClass('rz-draggable');
560+
561+
if(this.intermediateTicks && this.options.showTicksValues)
562+
this.ticks.addClass('rz-ticks-values-under');
547563
},
548564

549565
alwaysHide: function(el, hide) {
@@ -751,12 +767,13 @@
751767
*/
752768
updateTicksScale: function() {
753769
if (!this.options.showTicks) return;
754-
755-
var positions = '',
756-
ticksCount = Math.round((this.maxValue - this.minValue) / this.step) + 1;
770+
var step = this.step;
771+
if(this.intermediateTicks)
772+
step = this.options.showTicks;
773+
var ticksCount = Math.round((this.maxValue - this.minValue) / step) + 1;
757774
this.scope.ticks = [];
758775
for (var i = 0; i < ticksCount; i++) {
759-
var value = this.roundStep(this.minValue + i * this.step);
776+
var value = this.roundStep(this.minValue + i * step);
760777
var tick = {
761778
selected: this.isTickSelected(value)
762779
};
@@ -1077,6 +1094,7 @@
10771094
/**
10781095
* Return the translated value if a translate function is provided else the original value
10791096
* @param value
1097+
* @param which if it's min or max handle
10801098
* @returns {*}
10811099
*/
10821100
getDisplayValue: function(value, which) {
@@ -1087,11 +1105,13 @@
10871105
* Round value to step and precision based on minValue
10881106
*
10891107
* @param {number} value
1108+
* @param {number} customStep a custom step to override the defined step
10901109
* @returns {number}
10911110
*/
1092-
roundStep: function(value) {
1093-
var steppedDifference = parseFloat((value - this.minValue) / this.step).toPrecision(12);
1094-
steppedDifference = Math.round(steppedDifference) * this.step;
1111+
roundStep: function(value, customStep) {
1112+
var step = customStep ? customStep : this.step,
1113+
steppedDifference = parseFloat((value - this.minValue) / step).toPrecision(12);
1114+
steppedDifference = Math.round(+steppedDifference) * step;
10951115
var newValue = (this.minValue + steppedDifference).toFixed(this.precision);
10961116
return +newValue;
10971117
},
@@ -1334,7 +1354,7 @@
13341354
this.fullBar.on('mousedown', angular.bind(this, this.onStart, null, null));
13351355
this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar));
13361356
this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null));
1337-
this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks));
1357+
this.ticks.on('mousedown', angular.bind(this, this.onTickClick, this.ticks));
13381358
}
13391359
}
13401360

@@ -1354,7 +1374,7 @@
13541374
this.fullBar.on('touchstart', angular.bind(this, this.onStart, null, null));
13551375
this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar));
13561376
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
1357-
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
1377+
this.ticks.on('touchstart', angular.bind(this, this.onTickClick, this.ticks));
13581378
}
13591379
}
13601380

@@ -1423,9 +1443,10 @@
14231443
*
14241444
* @param {jqLite} pointer
14251445
* @param {Event} event The event
1446+
* @param {boolean} fromTick if the event occured on a tick or not
14261447
* @returns {undefined}
14271448
*/
1428-
onMove: function(pointer, event) {
1449+
onMove: function(pointer, event, fromTick) {
14291450
var newOffset = this.getEventPosition(event),
14301451
newValue,
14311452
ceilValue = this.options.rightToLeft ? this.minValue : this.maxValue,
@@ -1437,7 +1458,10 @@
14371458
newValue = ceilValue;
14381459
} else {
14391460
newValue = this.offsetToValue(newOffset);
1440-
newValue = this.roundStep(newValue);
1461+
if(fromTick && angular.isNumber(this.options.showTicks))
1462+
newValue = this.roundStep(newValue, this.options.showTicks);
1463+
else
1464+
newValue = this.roundStep(newValue);
14411465
}
14421466
this.positionTrackingHandle(newValue);
14431467
},
@@ -1464,6 +1488,10 @@
14641488
this.callOnEnd();
14651489
},
14661490

1491+
onTickClick: function(pointer, event) {
1492+
this.onMove(pointer, event, true);
1493+
},
1494+
14671495
onPointerFocus: function(pointer, ref) {
14681496
this.tracking = ref;
14691497
pointer.one('blur', angular.bind(this, this.onPointerBlur, pointer));

dist/rzslider.min.css

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

dist/rzslider.min.js

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

0 commit comments

Comments
 (0)