Commit 680b2a27 authored by Valentin Hervieu's avatar Valentin Hervieu Committed by Valentin Hervieu

add ticksValuesTooltip example

parent f553a623
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
- Add a `scale` option to fix sliders displayed in an element that uses `transform: scale(0.5)`. - Add a `scale` option to fix sliders displayed in an element that uses `transform: scale(0.5)`.
- Add a `stepsArray` option (#163) - Add a `stepsArray` option (#163)
- Add an `id` option that is passed to the translate function as second arg (#161) - Add an `id` option that is passed to the translate function as second arg (#161)
- Add a `ticksValuesTooltip` option that is used to display a tooltip on the ticks values (requires angular-ui bootstrap).
# 1.1.0 (2015-11-07) # 1.1.0 (2015-11-07)
## Features ## Features
......
...@@ -122,7 +122,7 @@ The default options are: ...@@ -122,7 +122,7 @@ The default options are:
translate: null, translate: null,
id: null, id: null,
stepsArray: null, stepsArray: null,
draggableRange: false, draggableRange: false,
showSelectionBar: false, showSelectionBar: false,
hideLimitLabels: false, hideLimitLabels: false,
readOnly: false, readOnly: false,
...@@ -186,6 +186,8 @@ $scope.slider = { ...@@ -186,6 +186,8 @@ $scope.slider = {
**showTicksValues** - _Boolean (defaults to false)_: Set to true to display a tick and the step value for each step of the slider. **showTicksValues** - _Boolean (defaults to false)_: Set to true to display a tick and the step value for each step of the slider.
**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.
**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. **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.
**onStart** - _Function()_: Function to be called when a slider update is started. **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 ...@@ -210,11 +212,11 @@ To force slider to recalculate dimensions, broadcast **reCalcViewDimensions** ev
You can also force redraw with **rzSliderForceRender** event. You can also force redraw with **rzSliderForceRender** event.
At the end of each "slide" slider emits `slideEnded` event. At the end of each "slide" slider emits `slideEnded` event.
```javascript ```javascript
$scope.$on("slideEnded", function() { $scope.$on("slideEnded", function() {
// user finished sliding a handle // user finished sliding a handle
}); });
``` ```
......
...@@ -89,7 +89,10 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { ...@@ -89,7 +89,10 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
options: { options: {
ceil: 10, ceil: 10,
floor: 0, floor: 0,
showTicksValues: true showTicksValues: true,
ticksValuesTooltip: function(v) {
return 'Tooltip for ' + v;
}
} }
}; };
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
</article> </article>
<article> <article>
<h2>Slider with ticks and values</h2> <h2>Slider with ticks and values (and tooltips)</h2>
<rzslider <rzslider
rz-slider-model="slider_ticks_values.value" rz-slider-model="slider_ticks_values.value"
rz-slider-options="slider_ticks_values.options" rz-slider-options="slider_ticks_values.options"
...@@ -200,7 +200,7 @@ ...@@ -200,7 +200,7 @@
</body> </body>
<script src="../bower_components/angular/angular.js"></script> <script src="../bower_components/angular/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.js"></script>
<script src="../dist/rzslider.js"></script> <script src="../dist/rzslider.js"></script>
<script src="demo.js"></script> <script src="demo.js"></script>
</html> </html>
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
interval: 350, interval: 350,
showTicks: false, showTicks: false,
showTicksValues: false, showTicksValues: false,
ticksValuesTooltip: null,
scale: 1, scale: 1,
onStart: null, onStart: null,
onChange: null, onChange: null,
...@@ -123,7 +124,7 @@ ...@@ -123,7 +124,7 @@
}; };
}) })
.factory('RzSlider', ['$timeout', '$document', '$window', 'RzSliderOptions', 'rzThrottle', function($timeout, $document, $window, RzSliderOptions, rzThrottle) { .factory('RzSlider', ['$timeout', '$document', '$window', '$compile', 'RzSliderOptions', 'rzThrottle', function($timeout, $document, $window, $compile, RzSliderOptions, rzThrottle) {
'use strict'; 'use strict';
/** /**
...@@ -360,9 +361,9 @@ ...@@ -360,9 +361,9 @@
this.options.draggableRange = this.range && this.options.draggableRange; this.options.draggableRange = this.range && this.options.draggableRange;
this.options.showTicks = this.options.showTicks || this.options.showTicksValues; this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
if(this.options.stepsArray) { if (this.options.stepsArray) {
this.options.floor = 0; this.options.floor = 0;
this.options.ceil = this.options.stepsArray.length -1; this.options.ceil = this.options.stepsArray.length - 1;
this.options.step = 1; this.options.step = 1;
this.customTrFn = function(value) { this.customTrFn = function(value) {
return this.options.stepsArray[value]; return this.options.stepsArray[value];
...@@ -645,11 +646,18 @@ ...@@ -645,11 +646,18 @@
var value = this.roundStep(this.minValue + i * this.step); var value = this.roundStep(this.minValue + i * this.step);
var selectedClass = this.isTickSelected(value) ? 'selected' : ''; var selectedClass = this.isTickSelected(value) ? 'selected' : '';
positions += '<li class="tick ' + selectedClass + '">'; positions += '<li class="tick ' + selectedClass + '">';
if (this.options.showTicksValues) if (this.options.showTicksValues) {
positions += '<span class="tick-value">' + this.getDisplayValue(value) + '</span>'; var tooltip = '';
if (this.options.ticksValuesTooltip) {
tooltip = 'uib-tooltip="' + this.options.ticksValuesTooltip(value) + '"';
}
positions += '<span ' + tooltip + ' class="tick-value">' + this.getDisplayValue(value) + '</span>';
}
positions += '</li>'; positions += '</li>';
} }
this.ticks.html(positions); this.ticks.html(positions);
if (this.options.ticksValuesTooltip)
$compile(this.ticks.contents())(this.scope);
}, },
isTickSelected: function(value) { isTickSelected: function(value) {
...@@ -963,14 +971,13 @@ ...@@ -963,14 +971,13 @@
return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxLeft / this.valueRange || 0; return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxLeft / this.valueRange || 0;
}, },
/** /**
* Ensure that the position rendered is within the slider bounds, even if the value is not * Ensure that the position rendered is within the slider bounds, even if the value is not
* *
* @param {number} val * @param {number} val
* @returns {number} * @returns {number}
*/ */
sanitizeOffsetValue: function(val) sanitizeOffsetValue: function(val) {
{
return Math.min(Math.max(val, this.minValue), this.maxValue); return Math.min(Math.max(val, this.minValue), this.maxValue);
}, },
......
This diff is collapsed.
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
interval: 350, interval: 350,
showTicks: false, showTicks: false,
showTicksValues: false, showTicksValues: false,
ticksValuesTooltip: null,
scale: 1, scale: 1,
onStart: null, onStart: null,
onChange: null, onChange: null,
...@@ -123,7 +124,7 @@ ...@@ -123,7 +124,7 @@
}; };
}) })
.factory('RzSlider', function($timeout, $document, $window, RzSliderOptions, rzThrottle) { .factory('RzSlider', function($timeout, $document, $window, $compile, RzSliderOptions, rzThrottle) {
'use strict'; 'use strict';
/** /**
...@@ -360,9 +361,9 @@ ...@@ -360,9 +361,9 @@
this.options.draggableRange = this.range && this.options.draggableRange; this.options.draggableRange = this.range && this.options.draggableRange;
this.options.showTicks = this.options.showTicks || this.options.showTicksValues; this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
if(this.options.stepsArray) { if (this.options.stepsArray) {
this.options.floor = 0; this.options.floor = 0;
this.options.ceil = this.options.stepsArray.length -1; this.options.ceil = this.options.stepsArray.length - 1;
this.options.step = 1; this.options.step = 1;
this.customTrFn = function(value) { this.customTrFn = function(value) {
return this.options.stepsArray[value]; return this.options.stepsArray[value];
...@@ -645,11 +646,18 @@ ...@@ -645,11 +646,18 @@
var value = this.roundStep(this.minValue + i * this.step); var value = this.roundStep(this.minValue + i * this.step);
var selectedClass = this.isTickSelected(value) ? 'selected' : ''; var selectedClass = this.isTickSelected(value) ? 'selected' : '';
positions += '<li class="tick ' + selectedClass + '">'; positions += '<li class="tick ' + selectedClass + '">';
if (this.options.showTicksValues) if (this.options.showTicksValues) {
positions += '<span class="tick-value">' + this.getDisplayValue(value) + '</span>'; var tooltip = '';
if (this.options.ticksValuesTooltip) {
tooltip = 'uib-tooltip="' + this.options.ticksValuesTooltip(value) + '"';
}
positions += '<span ' + tooltip + ' class="tick-value">' + this.getDisplayValue(value) + '</span>';
}
positions += '</li>'; positions += '</li>';
} }
this.ticks.html(positions); this.ticks.html(positions);
if (this.options.ticksValuesTooltip)
$compile(this.ticks.contents())(this.scope);
}, },
isTickSelected: function(value) { isTickSelected: function(value) {
...@@ -963,14 +971,13 @@ ...@@ -963,14 +971,13 @@
return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxLeft / this.valueRange || 0; return (this.sanitizeOffsetValue(val) - this.minValue) * this.maxLeft / this.valueRange || 0;
}, },
/** /**
* Ensure that the position rendered is within the slider bounds, even if the value is not * Ensure that the position rendered is within the slider bounds, even if the value is not
* *
* @param {number} val * @param {number} val
* @returns {number} * @returns {number}
*/ */
sanitizeOffsetValue: function(val) sanitizeOffsetValue: function(val) {
{
return Math.min(Math.max(val, this.minValue), this.maxValue); return Math.min(Math.max(val, this.minValue), this.maxValue);
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment