Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 680b2a2

Browse files
Valentin HervieuValentin Hervieu
Valentin Hervieu
authored and
Valentin Hervieu
committed
add ticksValuesTooltip example
1 parent f553a62 commit 680b2a2

File tree

7 files changed

+43
-23
lines changed

7 files changed

+43
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Add a `scale` option to fix sliders displayed in an element that uses `transform: scale(0.5)`.
99
- Add a `stepsArray` option (#163)
1010
- Add an `id` option that is passed to the translate function as second arg (#161)
11+
- Add a `ticksValuesTooltip` option that is used to display a tooltip on the ticks values (requires angular-ui bootstrap).
1112

1213
# 1.1.0 (2015-11-07)
1314
## Features

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The default options are:
122122
translate: null,
123123
id: null,
124124
stepsArray: null,
125-
draggableRange: false,
125+
draggableRange: false,
126126
showSelectionBar: false,
127127
hideLimitLabels: false,
128128
readOnly: false,
@@ -186,6 +186,8 @@ $scope.slider = {
186186

187187
**showTicksValues** - _Boolean (defaults to false)_: Set to true to display a tick and the step value for each step of the slider.
188188

189+
**ticksValuesTooltip** - _Function(value) (defaults to null)_: (requires angular-ui bootstrap) Used to display a tooltip when a tick value is hovered. Set to a function that returns the tooltip content for a given value.
190+
189191
**scale** - _Number (defaults to 1)_: If you display the slider in an element that uses `transform: scale(0.5)`, set the `scale` value to 2 so that the slider is rendered properly and the events are handled correctly.
190192

191193
**onStart** - _Function()_: Function to be called when a slider update is started.
@@ -210,11 +212,11 @@ To force slider to recalculate dimensions, broadcast **reCalcViewDimensions** ev
210212

211213
You can also force redraw with **rzSliderForceRender** event.
212214

213-
At the end of each "slide" slider emits `slideEnded` event.
215+
At the end of each "slide" slider emits `slideEnded` event.
214216

215217
```javascript
216218
$scope.$on("slideEnded", function() {
217-
// user finished sliding a handle
219+
// user finished sliding a handle
218220
});
219221
```
220222

demo/demo.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
8989
options: {
9090
ceil: 10,
9191
floor: 0,
92-
showTicksValues: true
92+
showTicksValues: true,
93+
ticksValuesTooltip: function(v) {
94+
return 'Tooltip for ' + v;
95+
}
9396
}
9497
};
9598

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ <h2>Slider with ticks</h2>
9090
</article>
9191

9292
<article>
93-
<h2>Slider with ticks and values</h2>
93+
<h2>Slider with ticks and values (and tooltips)</h2>
9494
<rzslider
9595
rz-slider-model="slider_ticks_values.value"
9696
rz-slider-options="slider_ticks_values.options"
@@ -200,7 +200,7 @@ <h2>Slider with all options demo</h2>
200200

201201
</body>
202202
<script src="../bower_components/angular/angular.js"></script>
203-
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js"></script>
203+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.js"></script>
204204
<script src="../dist/rzslider.js"></script>
205205
<script src="demo.js"></script>
206206
</html>

dist/rzslider.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
interval: 350,
4949
showTicks: false,
5050
showTicksValues: false,
51+
ticksValuesTooltip: null,
5152
scale: 1,
5253
onStart: null,
5354
onChange: null,
@@ -123,7 +124,7 @@
123124
};
124125
})
125126

126-
.factory('RzSlider', ['$timeout', '$document', '$window', 'RzSliderOptions', 'rzThrottle', function($timeout, $document, $window, RzSliderOptions, rzThrottle) {
127+
.factory('RzSlider', ['$timeout', '$document', '$window', '$compile', 'RzSliderOptions', 'rzThrottle', function($timeout, $document, $window, $compile, RzSliderOptions, rzThrottle) {
127128
'use strict';
128129

129130
/**
@@ -360,9 +361,9 @@
360361
this.options.draggableRange = this.range && this.options.draggableRange;
361362
this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
362363

363-
if(this.options.stepsArray) {
364+
if (this.options.stepsArray) {
364365
this.options.floor = 0;
365-
this.options.ceil = this.options.stepsArray.length -1;
366+
this.options.ceil = this.options.stepsArray.length - 1;
366367
this.options.step = 1;
367368
this.customTrFn = function(value) {
368369
return this.options.stepsArray[value];
@@ -645,11 +646,18 @@
645646
var value = this.roundStep(this.minValue + i * this.step);
646647
var selectedClass = this.isTickSelected(value) ? 'selected' : '';
647648
positions += '<li class="tick ' + selectedClass + '">';
648-
if (this.options.showTicksValues)
649-
positions += '<span class="tick-value">' + this.getDisplayValue(value) + '</span>';
649+
if (this.options.showTicksValues) {
650+
var tooltip = '';
651+
if (this.options.ticksValuesTooltip) {
652+
tooltip = 'uib-tooltip="' + this.options.ticksValuesTooltip(value) + '"';
653+
}
654+
positions += '<span ' + tooltip + ' class="tick-value">' + this.getDisplayValue(value) + '</span>';
655+
}
650656
positions += '</li>';
651657
}
652658
this.ticks.html(positions);
659+
if (this.options.ticksValuesTooltip)
660+
$compile(this.ticks.contents())(this.scope);
653661
},
654662

655663
isTickSelected: function(value) {
@@ -963,14 +971,13 @@
963971
return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxLeft / this.valueRange || 0;
964972
},
965973

966-
/**
974+
/**
967975
* Ensure that the position rendered is within the slider bounds, even if the value is not
968976
*
969977
* @param {number} val
970978
* @returns {number}
971979
*/
972-
sanitizeOffsetValue: function(val)
973-
{
980+
sanitizeOffsetValue: function(val) {
974981
return Math.min(Math.max(val, this.minValue), this.maxValue);
975982
},
976983

0 commit comments

Comments
 (0)