Commit 00b6b294 authored by Valentin Hervieu's avatar Valentin Hervieu

Merge pull request #68 from ValentinH/add-ticks

Add a rzSliderShowTicks and rzSliderShowTicksValue
parents 6e5ffa50 88cbd3ba
module.exports = function (grunt) module.exports = function(grunt) {
{
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
...@@ -62,7 +61,7 @@ module.exports = function (grunt) ...@@ -62,7 +61,7 @@ module.exports = function (grunt)
url: function(url) { url: function(url) {
return url.replace('src/', ''); return url.replace('src/', '');
}, },
bootstrap: function (module, script) { bootstrap: function(module, script) {
return 'module.run(function($templateCache) {\n' + script + '\n});'; return 'module.run(function($templateCache) {\n' + script + '\n});';
} }
} }
...@@ -98,6 +97,27 @@ module.exports = function (grunt) ...@@ -98,6 +97,27 @@ module.exports = function (grunt)
} }
] ]
} }
},
watch: {
all: {
files: ['dist/*', 'demo/*'],
options: {
livereload: true
}
},
js: {
files: ['src/*js', 'src/*.html'],
tasks: ['js']
},
less: {
files: ['src/*.less'],
tasks: ['css']
}
},
serve: {
options: {
port: 9000
}
} }
}); });
...@@ -107,9 +127,11 @@ module.exports = function (grunt) ...@@ -107,9 +127,11 @@ module.exports = function (grunt)
grunt.loadNpmTasks('grunt-angular-templates'); grunt.loadNpmTasks('grunt-angular-templates');
grunt.loadNpmTasks('grunt-replace'); grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-ng-annotate'); grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-serve');
grunt.registerTask('default', ['css', 'js']); grunt.registerTask('default', ['css', 'js']);
grunt.registerTask('css', ['recess']); grunt.registerTask('css', ['recess']);
grunt.registerTask('js', ['ngtemplates','replace', 'ngAnnotate', 'uglify']); grunt.registerTask('js', ['ngtemplates', 'replace', 'ngAnnotate', 'uglify']);
}; };
...@@ -127,6 +127,14 @@ $scope.priceSlider = { ...@@ -127,6 +127,14 @@ $scope.priceSlider = {
> Function to be called when a slider update is ended. > Function to be called when a slider update is ended.
**rz-slider-show-ticks**
> Display a tick for each value.
**rz-slider-show-ticks-value**
> Display a tick for each value and the value of the tick.
```javascript ```javascript
// In your controller // In your controller
...@@ -155,7 +163,8 @@ $scope.onSliderChange = function() ...@@ -155,7 +163,8 @@ $scope.onSliderChange = function()
rz-slider-model="priceSlider.min" rz-slider-model="priceSlider.min"
rz-slider-high="priceSlider.max" rz-slider-high="priceSlider.max"
rz-slider-translate="translate" rz-slider-translate="translate"
rz-slider-on-change="onSliderChange()"></rzslider> rz-slider-on-change="onSliderChange()"
rz-slider-show-ticks="true"></rzslider>
``` ```
## Slider events ## Slider events
......
...@@ -85,6 +85,24 @@ ...@@ -85,6 +85,24 @@
rz-slider-tpl-url="rzSliderTpl.html"></rzslider> rz-slider-tpl-url="rzSliderTpl.html"></rzslider>
</article> </article>
<article>
<h2>Slider with ticks example</h2>
Value: {{ priceSlider4 | json }}
<rzslider rz-slider-model="priceSlider4"
rz-slider-floor="0"
rz-slider-ceil="10"
rz-slider-show-ticks="true"></rzslider>
</article>
<article>
<h2>Slider with ticks value example</h2>
Value: {{ priceSlider5 | json }}
<rzslider rz-slider-model="priceSlider5"
rz-slider-floor="0"
rz-slider-ceil="10"
rz-slider-show-ticks-value="true"></rzslider>
</article>
<article> <article>
<h2>Draggable range example</h2> <h2>Draggable range example</h2>
Value: Value:
...@@ -131,6 +149,8 @@ ...@@ -131,6 +149,8 @@
$scope.priceSlider2 = 150; $scope.priceSlider2 = 150;
$scope.priceSlider3 = 250; $scope.priceSlider3 = 250;
$scope.priceSlider4 = 5;
$scope.priceSlider5 = 5;
$scope.translate = function(value) { $scope.translate = function(value) {
return '$' + value; return '$' + value;
......
...@@ -34,6 +34,7 @@ rzslider span.rz-base { ...@@ -34,6 +34,7 @@ rzslider span.rz-base {
rzslider span.rz-bar-wrapper { rzslider span.rz-bar-wrapper {
left: 0; left: 0;
z-index: 1;
width: 100%; width: 100%;
height: 32px; height: 32px;
padding-top: 16px; padding-top: 16px;
...@@ -43,7 +44,7 @@ rzslider span.rz-bar-wrapper { ...@@ -43,7 +44,7 @@ rzslider span.rz-bar-wrapper {
rzslider span.rz-bar { rzslider span.rz-bar {
left: 0; left: 0;
z-index: 0; z-index: 1;
width: 100%; width: 100%;
height: 4px; height: 4px;
background: #d8e0f3; background: #d8e0f3;
...@@ -53,7 +54,7 @@ rzslider span.rz-bar { ...@@ -53,7 +54,7 @@ rzslider span.rz-bar {
} }
rzslider span.rz-bar.rz-selection { rzslider span.rz-bar.rz-selection {
z-index: 1; z-index: 2;
background: #0db9f0; background: #0db9f0;
-webkit-border-radius: 2px; -webkit-border-radius: 2px;
-moz-border-radius: 2px; -moz-border-radius: 2px;
...@@ -62,7 +63,7 @@ rzslider span.rz-bar.rz-selection { ...@@ -62,7 +63,7 @@ rzslider span.rz-bar.rz-selection {
rzslider span.rz-pointer { rzslider span.rz-pointer {
top: -14px; top: -14px;
z-index: 2; z-index: 3;
width: 32px; width: 32px;
height: 32px; height: 32px;
cursor: pointer; cursor: pointer;
...@@ -107,3 +108,32 @@ rzslider span.rz-bubble.rz-selection { ...@@ -107,3 +108,32 @@ rzslider span.rz-bubble.rz-selection {
rzslider span.rz-bubble.rz-limit { rzslider span.rz-bubble.rz-limit {
color: #55637d; color: #55637d;
} }
rzslider .rz-ticks {
position: absolute;
top: -3px;
left: 0;
z-index: 1;
display: flex;
width: 100%;
padding: 0 11px;
margin: 0;
list-style: none;
box-sizing: border-box;
justify-content: space-between;
}
rzslider .rz-ticks .tick {
width: 10px;
height: 10px;
text-align: center;
cursor: pointer;
background: #666666;
border-radius: 50%;
}
rzslider .rz-ticks .tick .tick-value {
position: absolute;
top: -30px;
transform: translate(-50%, 0);
}
\ No newline at end of file
...@@ -211,6 +211,20 @@ function throttle(func, wait, options) { ...@@ -211,6 +211,20 @@ function throttle(func, wait, options) {
*/ */
this.presentOnly = attributes.rzSliderPresentOnly === 'true'; this.presentOnly = attributes.rzSliderPresentOnly === 'true';
/**
* Display ticks on each possible value.
*
* @type {boolean}
*/
this.showTicks = attributes.rzSliderShowTicks || attributes.rzSliderShowTicksValue;
/**
* Display the value on each tick.
*
* @type {boolean}
*/
this.showTicksValue = attributes.rzSliderShowTicksValue;
/** /**
* The delta between min and max value * The delta between min and max value
* *
...@@ -249,6 +263,7 @@ function throttle(func, wait, options) { ...@@ -249,6 +263,7 @@ function throttle(func, wait, options) {
this.minLab = null; // Label above the low value this.minLab = null; // Label above the low value
this.maxLab = null; // Label above the high value this.maxLab = null; // Label above the high value
this.cmbLab = null; // Combined label this.cmbLab = null; // Combined label
this.ticks = null; // The ticks
// Initialize slider // Initialize slider
this.init(); this.init();
...@@ -281,6 +296,8 @@ function throttle(func, wait, options) { ...@@ -281,6 +296,8 @@ function throttle(func, wait, options) {
self.updateFloorLab(); self.updateFloorLab();
self.initHandles(); self.initHandles();
if (!self.presentOnly) { self.bindEvents(); } if (!self.presentOnly) { self.bindEvents(); }
if(self.showTicks)
self.updateTicksScale();
}); });
// Recalculate slider view dimensions // Recalculate slider view dimensions
...@@ -353,12 +370,27 @@ function throttle(func, wait, options) { ...@@ -353,12 +370,27 @@ function throttle(func, wait, options) {
}); });
this.deRegFuncs.push(unRegFn); this.deRegFuncs.push(unRegFn);
unRegFn = this.scope.$watch('rzSliderShowTicks', function(newValue, oldValue)
{
if(newValue === oldValue) { return; }
self.resetSlider();
});
this.deRegFuncs.push(unRegFn);
unRegFn = this.scope.$watch('rzSliderShowTicksValue', function(newValue, oldValue)
{
if(newValue === oldValue) { return; }
self.resetSlider();
});
this.deRegFuncs.push(unRegFn);
this.scope.$on('$destroy', function() this.scope.$on('$destroy', function()
{ {
self.minH.off(); self.minH.off();
self.maxH.off(); self.maxH.off();
self.fullBar.off(); self.fullBar.off();
self.selBar.off(); self.selBar.off();
self.ticks.off();
angular.element($window).off('resize', calcDimFn); angular.element($window).off('resize', calcDimFn);
self.deRegFuncs.map(function(unbind) { unbind(); }); self.deRegFuncs.map(function(unbind) { unbind(); });
}); });
...@@ -493,6 +525,7 @@ function throttle(func, wait, options) { ...@@ -493,6 +525,7 @@ function throttle(func, wait, options) {
case 6: this.minLab = jElem; break; case 6: this.minLab = jElem; break;
case 7: this.maxLab = jElem; break; case 7: this.maxLab = jElem; break;
case 8: this.cmbLab = jElem; break; case 8: this.cmbLab = jElem; break;
case 9: this.ticks = jElem; break;
} }
}, this); }, this);
...@@ -516,6 +549,17 @@ function throttle(func, wait, options) { ...@@ -516,6 +549,17 @@ function throttle(func, wait, options) {
this.hideEl(this.ceilLab); this.hideEl(this.ceilLab);
} }
if(this.showTicksValue) {
this.flrLab.rzAlwaysHide = true;
this.ceilLab.rzAlwaysHide = true;
this.minLab.rzAlwaysHide = true;
this.maxLab.rzAlwaysHide = true;
this.hideEl(this.flrLab);
this.hideEl(this.ceilLab);
this.hideEl(this.minLab);
this.hideEl(this.maxLab);
}
// Remove stuff not needed in single slider // Remove stuff not needed in single slider
if(this.range === false) if(this.range === false)
{ {
...@@ -561,6 +605,8 @@ function throttle(func, wait, options) { ...@@ -561,6 +605,8 @@ function throttle(func, wait, options) {
this.getWidth(this.sliderElem); this.getWidth(this.sliderElem);
this.sliderElem.rzsl = this.sliderElem[0].getBoundingClientRect().left; this.sliderElem.rzsl = this.sliderElem[0].getBoundingClientRect().left;
if(this.showTicks)
this.updateTicksScale();
if(this.initHasRun) if(this.initHasRun)
{ {
...@@ -569,6 +615,24 @@ function throttle(func, wait, options) { ...@@ -569,6 +615,24 @@ function throttle(func, wait, options) {
} }
}, },
/**
* Update the ticks position
*
* @returns {undefined}
*/
updateTicksScale: function() {
if(!this.step) return; //if step is 0, the following loop will be endless.
var positions = '';
for (var i = this.minValue; i <= this.maxValue; i += this.step) {
positions += '<li class="tick">';
if(this.showTicksValue)
positions += '<span class="tick-value">'+ this.getDisplayValue(i) +'</span>';
positions += '</li>';
}
this.ticks.html(positions);
},
/** /**
* Update position of the ceiling label * Update position of the ceiling label
* *
...@@ -783,16 +847,8 @@ function throttle(func, wait, options) { ...@@ -783,16 +847,8 @@ function throttle(func, wait, options) {
if(this.minLab.rzsl + this.minLab.rzsw + 10 >= this.maxLab.rzsl) if(this.minLab.rzsl + this.minLab.rzsw + 10 >= this.maxLab.rzsl)
{ {
if(this.customTrFn) lowTr = this.getDisplayValue(this.scope.rzSliderModel);
{ highTr = this.getDisplayValue(this.scope.rzSliderHigh);
lowTr = this.customTrFn(this.scope.rzSliderModel);
highTr = this.customTrFn(this.scope.rzSliderHigh);
}
else
{
lowTr = this.scope.rzSliderModel;
highTr = this.scope.rzSliderHigh;
}
this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false); this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false);
this.setLeft(this.cmbLab, this.selBar.rzsl + this.selBar.rzsw / 2 - this.cmbLab.rzsw / 2); this.setLeft(this.cmbLab, this.selBar.rzsl + this.selBar.rzsw / 2 - this.cmbLab.rzsw / 2);
...@@ -808,6 +864,15 @@ function throttle(func, wait, options) { ...@@ -808,6 +864,15 @@ function throttle(func, wait, options) {
} }
}, },
/**
* Return the translated value if a translate function is provided else the original value
* @param value
* @returns {*}
*/
getDisplayValue: function(value) {
return this.customTrFn ? this.customTrFn(value): value;
},
/** /**
* Round value to step and precision * Round value to step and precision
* *
...@@ -974,6 +1039,8 @@ function throttle(func, wait, options) { ...@@ -974,6 +1039,8 @@ function throttle(func, wait, options) {
this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar)); this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar));
this.selBar.on('mousedown', angular.bind(this, barStart, null, barTracking)); this.selBar.on('mousedown', angular.bind(this, barStart, null, barTracking));
this.selBar.on('mousedown', angular.bind(this, barMove, this.selBar)); this.selBar.on('mousedown', angular.bind(this, barMove, this.selBar));
this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null));
this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks));
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel')); this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
if(this.range) { this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')); } if(this.range) { this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')); }
...@@ -981,6 +1048,8 @@ function throttle(func, wait, options) { ...@@ -981,6 +1048,8 @@ function throttle(func, wait, options) {
this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar)); this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar));
this.selBar.on('touchstart', angular.bind(this, barStart, null, barTracking)); this.selBar.on('touchstart', angular.bind(this, barStart, null, barTracking));
this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar)); this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar));
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
}, },
/** /**
...@@ -1266,7 +1335,9 @@ function throttle(func, wait, options) { ...@@ -1266,7 +1335,9 @@ function throttle(func, wait, options) {
rzSliderPresentOnly: '@', rzSliderPresentOnly: '@',
rzSliderOnStart: '&', rzSliderOnStart: '&',
rzSliderOnChange: '&', rzSliderOnChange: '&',
rzSliderOnEnd: '&' rzSliderOnEnd: '&',
rzSliderShowTicks: '=?',
rzSliderShowTicksValue: '=?'
}, },
/** /**
...@@ -1325,7 +1396,7 @@ function throttle(func, wait, options) { ...@@ -1325,7 +1396,7 @@ function throttle(func, wait, options) {
'use strict'; 'use strict';
$templateCache.put('rzSliderTpl.html', $templateCache.put('rzSliderTpl.html',
"<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>" "<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>"
); );
}]); }]);
......
/*! jusas-angularjs-slider - v0.1.32 - (c) Rafal Zajac <rzajac@gmail.com>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com>, https://github.com/rzajac/angularjs-slider.git - 2015-09-24 */ /*! jusas-angularjs-slider - v0.1.32 - (c) Rafal Zajac <rzajac@gmail.com>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com>, https://github.com/rzajac/angularjs-slider.git - 2015-10-02 */
rzslider{position:relative;display:inline-block;width:100%;height:4px;margin:30px 0 15px 0;vertical-align:middle}rzslider span{position:absolute;display:inline-block;white-space:nowrap}rzslider span.rz-base{width:100%;height:100%;padding:0}rzslider span.rz-bar-wrapper{left:0;width:100%;height:32px;padding-top:16px;margin-top:-16px;box-sizing:border-box}rzslider span.rz-bar{left:0;z-index:0;width:100%;height:4px;background:#d8e0f3;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider span.rz-bar.rz-selection{z-index:1;background:#0db9f0;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider span.rz-pointer{top:-14px;z-index:2;width:32px;height:32px;cursor:pointer;background-color:#0db9f0;-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px}rzslider span.rz-pointer:after{position:absolute;top:12px;left:12px;width:8px;height:8px;background:#fff;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;content:''}rzslider span.rz-pointer:hover:after{background-color:#fff}rzslider span.rz-pointer.rz-active:after{background-color:#451aff}rzslider span.rz-bubble{top:-32px;padding:1px 3px;color:#55637d;cursor:default}rzslider span.rz-bubble.rz-selection{top:16px}rzslider span.rz-bubble.rz-limit{color:#55637d} rzslider{position:relative;display:inline-block;width:100%;height:4px;margin:30px 0 15px 0;vertical-align:middle}rzslider span{position:absolute;display:inline-block;white-space:nowrap}rzslider span.rz-base{width:100%;height:100%;padding:0}rzslider span.rz-bar-wrapper{left:0;z-index:1;width:100%;height:32px;padding-top:16px;margin-top:-16px;box-sizing:border-box}rzslider span.rz-bar{left:0;z-index:1;width:100%;height:4px;background:#d8e0f3;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider span.rz-bar.rz-selection{z-index:2;background:#0db9f0;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider span.rz-pointer{top:-14px;z-index:3;width:32px;height:32px;cursor:pointer;background-color:#0db9f0;-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px}rzslider span.rz-pointer:after{position:absolute;top:12px;left:12px;width:8px;height:8px;background:#fff;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;content:''}rzslider span.rz-pointer:hover:after{background-color:#fff}rzslider span.rz-pointer.rz-active:after{background-color:#451aff}rzslider span.rz-bubble{top:-32px;padding:1px 3px;color:#55637d;cursor:default}rzslider span.rz-bubble.rz-selection{top:16px}rzslider span.rz-bubble.rz-limit{color:#55637d}rzslider .rz-ticks{position:absolute;top:-3px;left:0;z-index:1;display:flex;width:100%;padding:0 11px;margin:0;list-style:none;box-sizing:border-box;justify-content:space-between}rzslider .rz-ticks .tick{width:10px;height:10px;text-align:center;cursor:pointer;background:#666;border-radius:50%}rzslider .rz-ticks .tick .tick-value{position:absolute;top:-30px;transform:translate(-50%,0)}
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
"grunt-ng-annotate": "^1.0.1", "grunt-ng-annotate": "^1.0.1",
"grunt-recess": "~0.4.0", "grunt-recess": "~0.4.0",
"grunt-replace": "^0.11.0", "grunt-replace": "^0.11.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-serve": "^0.1.6",
"recess": "~1.1.9" "recess": "~1.1.9"
}, },
"author": "Rafal Zajac <rzajac@gmail.com>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com>", "author": "Rafal Zajac <rzajac@gmail.com>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com>",
......
...@@ -7,3 +7,4 @@ ...@@ -7,3 +7,4 @@
<span class="rz-bubble"></span> <!-- // 6 Label above left slider handle --> <span class="rz-bubble"></span> <!-- // 6 Label above left slider handle -->
<span class="rz-bubble"></span> <!-- // 7 Label above right slider handle --> <span class="rz-bubble"></span> <!-- // 7 Label above right slider handle -->
<span class="rz-bubble"></span> <!-- // 8 Range label when the slider handles are close ex. 15 - 17 --> <span class="rz-bubble"></span> <!-- // 8 Range label when the slider handles are close ex. 15 - 17 -->
<ul class="rz-ticks"></ul> <!-- // 9 The ticks -->
\ No newline at end of file
...@@ -211,6 +211,20 @@ function throttle(func, wait, options) { ...@@ -211,6 +211,20 @@ function throttle(func, wait, options) {
*/ */
this.presentOnly = attributes.rzSliderPresentOnly === 'true'; this.presentOnly = attributes.rzSliderPresentOnly === 'true';
/**
* Display ticks on each possible value.
*
* @type {boolean}
*/
this.showTicks = attributes.rzSliderShowTicks || attributes.rzSliderShowTicksValue;
/**
* Display the value on each tick.
*
* @type {boolean}
*/
this.showTicksValue = attributes.rzSliderShowTicksValue;
/** /**
* The delta between min and max value * The delta between min and max value
* *
...@@ -249,6 +263,7 @@ function throttle(func, wait, options) { ...@@ -249,6 +263,7 @@ function throttle(func, wait, options) {
this.minLab = null; // Label above the low value this.minLab = null; // Label above the low value
this.maxLab = null; // Label above the high value this.maxLab = null; // Label above the high value
this.cmbLab = null; // Combined label this.cmbLab = null; // Combined label
this.ticks = null; // The ticks
// Initialize slider // Initialize slider
this.init(); this.init();
...@@ -281,6 +296,8 @@ function throttle(func, wait, options) { ...@@ -281,6 +296,8 @@ function throttle(func, wait, options) {
self.updateFloorLab(); self.updateFloorLab();
self.initHandles(); self.initHandles();
if (!self.presentOnly) { self.bindEvents(); } if (!self.presentOnly) { self.bindEvents(); }
if(self.showTicks)
self.updateTicksScale();
}); });
// Recalculate slider view dimensions // Recalculate slider view dimensions
...@@ -353,12 +370,27 @@ function throttle(func, wait, options) { ...@@ -353,12 +370,27 @@ function throttle(func, wait, options) {
}); });
this.deRegFuncs.push(unRegFn); this.deRegFuncs.push(unRegFn);
unRegFn = this.scope.$watch('rzSliderShowTicks', function(newValue, oldValue)
{
if(newValue === oldValue) { return; }
self.resetSlider();
});
this.deRegFuncs.push(unRegFn);
unRegFn = this.scope.$watch('rzSliderShowTicksValue', function(newValue, oldValue)
{
if(newValue === oldValue) { return; }
self.resetSlider();
});
this.deRegFuncs.push(unRegFn);
this.scope.$on('$destroy', function() this.scope.$on('$destroy', function()
{ {
self.minH.off(); self.minH.off();
self.maxH.off(); self.maxH.off();
self.fullBar.off(); self.fullBar.off();
self.selBar.off(); self.selBar.off();
self.ticks.off();
angular.element($window).off('resize', calcDimFn); angular.element($window).off('resize', calcDimFn);
self.deRegFuncs.map(function(unbind) { unbind(); }); self.deRegFuncs.map(function(unbind) { unbind(); });
}); });
...@@ -493,6 +525,7 @@ function throttle(func, wait, options) { ...@@ -493,6 +525,7 @@ function throttle(func, wait, options) {
case 6: this.minLab = jElem; break; case 6: this.minLab = jElem; break;
case 7: this.maxLab = jElem; break; case 7: this.maxLab = jElem; break;
case 8: this.cmbLab = jElem; break; case 8: this.cmbLab = jElem; break;
case 9: this.ticks = jElem; break;
} }
}, this); }, this);
...@@ -516,6 +549,17 @@ function throttle(func, wait, options) { ...@@ -516,6 +549,17 @@ function throttle(func, wait, options) {
this.hideEl(this.ceilLab); this.hideEl(this.ceilLab);
} }
if(this.showTicksValue) {
this.flrLab.rzAlwaysHide = true;
this.ceilLab.rzAlwaysHide = true;
this.minLab.rzAlwaysHide = true;
this.maxLab.rzAlwaysHide = true;
this.hideEl(this.flrLab);
this.hideEl(this.ceilLab);
this.hideEl(this.minLab);
this.hideEl(this.maxLab);
}
// Remove stuff not needed in single slider // Remove stuff not needed in single slider
if(this.range === false) if(this.range === false)
{ {
...@@ -561,6 +605,8 @@ function throttle(func, wait, options) { ...@@ -561,6 +605,8 @@ function throttle(func, wait, options) {
this.getWidth(this.sliderElem); this.getWidth(this.sliderElem);
this.sliderElem.rzsl = this.sliderElem[0].getBoundingClientRect().left; this.sliderElem.rzsl = this.sliderElem[0].getBoundingClientRect().left;
if(this.showTicks)
this.updateTicksScale();
if(this.initHasRun) if(this.initHasRun)
{ {
...@@ -569,6 +615,24 @@ function throttle(func, wait, options) { ...@@ -569,6 +615,24 @@ function throttle(func, wait, options) {
} }
}, },
/**
* Update the ticks position
*
* @returns {undefined}
*/
updateTicksScale: function() {
if(!this.step) return; //if step is 0, the following loop will be endless.
var positions = '';
for (var i = this.minValue; i <= this.maxValue; i += this.step) {
positions += '<li class="tick">';
if(this.showTicksValue)
positions += '<span class="tick-value">'+ this.getDisplayValue(i) +'</span>';
positions += '</li>';
}
this.ticks.html(positions);
},
/** /**
* Update position of the ceiling label * Update position of the ceiling label
* *
...@@ -783,16 +847,8 @@ function throttle(func, wait, options) { ...@@ -783,16 +847,8 @@ function throttle(func, wait, options) {
if(this.minLab.rzsl + this.minLab.rzsw + 10 >= this.maxLab.rzsl) if(this.minLab.rzsl + this.minLab.rzsw + 10 >= this.maxLab.rzsl)
{ {
if(this.customTrFn) lowTr = this.getDisplayValue(this.scope.rzSliderModel);
{ highTr = this.getDisplayValue(this.scope.rzSliderHigh);
lowTr = this.customTrFn(this.scope.rzSliderModel);
highTr = this.customTrFn(this.scope.rzSliderHigh);
}
else
{
lowTr = this.scope.rzSliderModel;
highTr = this.scope.rzSliderHigh;
}
this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false); this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false);
this.setLeft(this.cmbLab, this.selBar.rzsl + this.selBar.rzsw / 2 - this.cmbLab.rzsw / 2); this.setLeft(this.cmbLab, this.selBar.rzsl + this.selBar.rzsw / 2 - this.cmbLab.rzsw / 2);
...@@ -808,6 +864,15 @@ function throttle(func, wait, options) { ...@@ -808,6 +864,15 @@ function throttle(func, wait, options) {
} }
}, },
/**
* Return the translated value if a translate function is provided else the original value
* @param value
* @returns {*}
*/
getDisplayValue: function(value) {
return this.customTrFn ? this.customTrFn(value): value;
},
/** /**
* Round value to step and precision * Round value to step and precision
* *
...@@ -974,6 +1039,8 @@ function throttle(func, wait, options) { ...@@ -974,6 +1039,8 @@ function throttle(func, wait, options) {
this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar)); this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar));
this.selBar.on('mousedown', angular.bind(this, barStart, null, barTracking)); this.selBar.on('mousedown', angular.bind(this, barStart, null, barTracking));
this.selBar.on('mousedown', angular.bind(this, barMove, this.selBar)); this.selBar.on('mousedown', angular.bind(this, barMove, this.selBar));
this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null));
this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks));
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel')); this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
if(this.range) { this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')); } if(this.range) { this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')); }
...@@ -981,6 +1048,8 @@ function throttle(func, wait, options) { ...@@ -981,6 +1048,8 @@ function throttle(func, wait, options) {
this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar)); this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar));
this.selBar.on('touchstart', angular.bind(this, barStart, null, barTracking)); this.selBar.on('touchstart', angular.bind(this, barStart, null, barTracking));
this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar)); this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar));
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
}, },
/** /**
...@@ -1266,7 +1335,9 @@ function throttle(func, wait, options) { ...@@ -1266,7 +1335,9 @@ function throttle(func, wait, options) {
rzSliderPresentOnly: '@', rzSliderPresentOnly: '@',
rzSliderOnStart: '&', rzSliderOnStart: '&',
rzSliderOnChange: '&', rzSliderOnChange: '&',
rzSliderOnEnd: '&' rzSliderOnEnd: '&',
rzSliderShowTicks: '=?',
rzSliderShowTicksValue: '=?'
}, },
/** /**
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
@limitLabelTextColor: @labelTextColor; @limitLabelTextColor: @labelTextColor;
@barFillColor: @handleBgColor; @barFillColor: @handleBgColor;
@barNormalColor: #d8e0f3; @barNormalColor: #d8e0f3;
@ticksColor: #666;
@ticksWidth: 10px;
@ticksHeight: 10px;
@ticksValuePosition: -30px;
/* Slider size parameters */ /* Slider size parameters */
@handleSize: 32px; @handleSize: 32px;
...@@ -57,19 +61,20 @@ rzslider span.rz-bar-wrapper { ...@@ -57,19 +61,20 @@ rzslider span.rz-bar-wrapper {
padding-top: @handleSize / 2; padding-top: @handleSize / 2;
width: 100%; width: 100%;
height: @handleSize; height: @handleSize;
z-index: 1;
} }
rzslider span.rz-bar { rzslider span.rz-bar {
left: 0; left: 0;
width: 100%; width: 100%;
height: @barHeight; height: @barHeight;
z-index: 0; z-index: 1;
background: @barNormalColor; background: @barNormalColor;
.rounded(@barHeight/2); .rounded(@barHeight/2);
} }
rzslider span.rz-bar.rz-selection { rzslider span.rz-bar.rz-selection {
z-index: 1; z-index: 2;
background: @barFillColor; background: @barFillColor;
.rounded(@barHeight/2); .rounded(@barHeight/2);
} }
...@@ -80,12 +85,12 @@ rzslider span.rz-pointer { ...@@ -80,12 +85,12 @@ rzslider span.rz-pointer {
height: @handleSize; height: @handleSize;
top: -@handleSize/2 + @barHeight/2; top: -@handleSize/2 + @barHeight/2;
background-color: @handleBgColor; background-color: @handleBgColor;
z-index: 2; z-index: 3;
.rounded(@handleSize/2); .rounded(@handleSize/2);
// -webkit-transition:all linear 0.15s; // -webkit-transition:all linear 0.15s;
// -moz-transition:all linear 0.15s; // -moz-transition:all linear 0.15s;
// -o-transition:all linear 0.15s; // -o-transition:all linear 0.15s;
// transition:all linear 0.15s; // transition:all linear 0.15s;
} }
rzslider span.rz-pointer:after { rzslider span.rz-pointer:after {
...@@ -121,3 +126,31 @@ rzslider span.rz-bubble.rz-selection { ...@@ -121,3 +126,31 @@ rzslider span.rz-bubble.rz-selection {
rzslider span.rz-bubble.rz-limit { rzslider span.rz-bubble.rz-limit {
color: @limitLabelTextColor; color: @limitLabelTextColor;
} }
rzslider .rz-ticks {
box-sizing: border-box;
width: 100%;
position: absolute;
left: 0;
top: -(@ticksHeight - @barHeight) / 2;
margin: 0;
padding: 0 (@handleSize - @ticksWidth) / 2;
z-index: 1;
list-style: none;
display: flex;
justify-content: space-between;
.tick {
text-align: center;
cursor: pointer;
width: @ticksWidth;
height: @ticksHeight;
background: @ticksColor;
border-radius: 50%;
.tick-value {
position: absolute;
top: @ticksValuePosition;
transform: translate(-50%, 0);
}
}
}
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