Commit 1e5a483c authored by Valentin Hervieu's avatar Valentin Hervieu

feat(range): Add a minRange option

The minimum range authorized on the slider.

Closes #231
parent 171aaccc
# 2.5.0 (not-released)
## Features
- Add a `minRange` option to set a minimal range (#231).
# 2.4.1 (2016-01-15)
## Performance improvements
- Remove the $timeout call in the init method (#223).
......
......@@ -157,6 +157,7 @@ The default options are:
ceil: null, //defaults to rz-slider-model
step: 1,
precision: 0,
minRange: 0,
id: null,
translate: null,
stepsArray: null,
......@@ -192,6 +193,8 @@ The default options are:
**precision** - _Number (defaults to 0)_: The precision to display values with. The `toFixed()` is used internally for this.
**minRange** - _Number (defaults to 0)_: The minimum range authorized on the slider.
**translate** - _Function(value, sliderId)_: Custom translate function. Use this if you want to translate values displayed on the slider. For example if you want to display dollar amounts instead of just numbers:
```html
<div>
......
......@@ -6,6 +6,29 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
value: 10
};
//Range slider config
$scope.rangeSlider = {
minValue: 10,
maxValue: 90,
options: {
floor: 0,
ceil: 100,
step: 1
}
};
//Range slider with minRange config
$scope.minRangeSlider = {
minValue: 10,
maxValue: 90,
options: {
floor: 0,
ceil: 100,
step: 1,
minRange: 10
}
};
//Slider with selection bar
$scope.slider_visible_bar = {
value: 10,
......@@ -13,6 +36,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
showSelectionBar: true
}
};
//Slider with selection bar end
$scope.slider_visible_bar_end = {
value: 10,
......@@ -22,17 +46,6 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
}
};
//Range slider config
$scope.minRangeSlider = {
minValue: 10,
maxValue: 90,
options: {
floor: 0,
ceil: 100,
step: 1
}
};
//Slider with selection bar
$scope.color_slider_bar = {
value: 12,
......
......@@ -27,8 +27,17 @@
<article>
<h2>Range slider</h2>
Min Value: <input type="number" ng-model="minRangeSlider.minValue"/><br/>
Max Value: <input type="number" ng-model="minRangeSlider.maxValue"/><br/>
Min Value: <input type="number" ng-model="rangeSlider.minValue"/><br/>
Max Value: <input type="number" ng-model="rangeSlider.maxValue"/><br/>
<rzslider
rz-slider-model="rangeSlider.minValue"
rz-slider-high="rangeSlider.maxValue"
rz-slider-options="rangeSlider.options"
></rzslider>
</article>
<article>
<h2>Range slider with minimum range of 10</h2>
<rzslider
rz-slider-model="minRangeSlider.minValue"
rz-slider-high="minRangeSlider.maxValue"
......
/*! angularjs-slider - v2.4.1 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
https://github.com/angular-slider/angularjs-slider -
2016-01-15 */
2016-01-22 */
rzslider {
position: relative;
display: inline-block;
......
/*! angularjs-slider - v2.4.1 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
https://github.com/angular-slider/angularjs-slider -
2016-01-15 */
2016-01-22 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
......@@ -31,6 +31,7 @@
ceil: null, //defaults to rz-slider-model
step: 1,
precision: 0,
minRange: 0,
id: null,
translate: null,
stepsArray: null,
......@@ -736,7 +737,7 @@
this.scope.ticks = [];
for (var i = 0; i < ticksCount; i++) {
var value = this.roundStep(this.minValue + i * this.step);
var tick =   {
var tick = {
selected: this.isTickSelected(value)
};
if (tick.selected && this.options.getSelectionBarColor) {
......@@ -1514,7 +1515,9 @@
var switched = false;
if (this.range) {
/* This is to check if we need to switch the min and max handles*/
newValue = this.applyMinRange(newValue);
newOffset = this.valueToOffset(newValue);
/* This is to check if we need to switch the min and max handles */
if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) {
switched = true;
this.scope[this.tracking] = this.scope.rzSliderHigh;
......@@ -1553,6 +1556,21 @@
return switched;
},
applyMinRange: function(newValue) {
if (this.options.minRange !== 0) {
var oppositeValue = this.tracking === 'rzSliderModel' ? this.scope.rzSliderHigh : this.scope.rzSliderModel,
difference = Math.abs(newValue - oppositeValue);
if (difference < this.options.minRange) {
if (this.tracking === 'rzSliderModel')
return this.scope.rzSliderHigh - this.options.minRange;
else
return this.scope.rzSliderModel + this.options.minRange;
}
}
return newValue;
},
/**
* Apply the model values using scope.$apply.
* We wrap it with the internalChange flag to avoid the watchers to be called
......
/*! angularjs-slider - v2.4.1 - (c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - https://github.com/angular-slider/angularjs-slider - 2016-01-15 */
/*! angularjs-slider - v2.4.1 - (c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - https://github.com/angular-slider/angularjs-slider - 2016-01-22 */
rzslider{position:relative;display:inline-block;width:100%;height:4px;margin:35px 0 15px 0;vertical-align:middle;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}rzslider[disabled]{cursor:not-allowed}rzslider[disabled] .rz-pointer{cursor:not-allowed;background-color:#d8e0f3}rzslider span{position:absolute;display:inline-block;white-space:nowrap}rzslider .rz-base{width:100%;height:100%;padding:0}rzslider .rz-bar-wrapper{left:0;z-index:1;width:100%;height:32px;padding-top:16px;margin-top:-16px;box-sizing:border-box}rzslider .rz-bar-wrapper.rz-draggable{cursor:move}rzslider .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 .rz-bar.rz-selection{z-index:2;background:#0db9f0;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider .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 .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 .rz-pointer:hover:after{background-color:#fff}rzslider .rz-pointer.rz-active:after{background-color:#451aff}rzslider .rz-bubble{bottom:16px;padding:1px 3px;color:#55637d;cursor:default}rzslider .rz-bubble.rz-selection{top:16px}rzslider .rz-bubble.rz-limit{color:#55637d}rzslider .rz-ticks{position:absolute;top:-3px;left:0;z-index:1;display:-webkit-flex;display:-ms-flexbox;display:flex;width:100%;height:0;padding:0 11px;margin:0;list-style:none;box-sizing:border-box;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between}rzslider .rz-ticks .tick{width:10px;height:10px;text-align:center;cursor:pointer;background:#d8e0f3;border-radius:50%}rzslider .rz-ticks .tick.selected{background:#0db9f0}rzslider .rz-ticks .tick .tick-value{position:absolute;top:-30px;transform:translate(-50%,0)}rzslider.vertical{position:relative;width:4px;height:100%;padding:0;margin:0 20px;vertical-align:baseline}rzslider.vertical .rz-base{width:100%;height:100%;padding:0}rzslider.vertical .rz-bar-wrapper{top:auto;left:0;width:32px;height:100%;padding:0 0 0 16px;margin:0 0 0 -16px}rzslider.vertical .rz-bar{bottom:0;left:auto;width:4px;height:100%}rzslider.vertical .rz-pointer{top:auto;bottom:0;left:-14px!important}rzslider.vertical .rz-bubble{bottom:0;left:16px!important;margin-left:3px}rzslider.vertical .rz-bubble.rz-selection{top:auto;left:16px!important}rzslider.vertical .rz-ticks{top:0;left:-3px;z-index:1;width:0;height:100%;padding:11px 0;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse}rzslider.vertical .rz-ticks .tick{vertical-align:middle}rzslider.vertical .rz-ticks .tick .tick-value{top:auto;right:-30px;transform:translate(0,-28%)}
\ No newline at end of file
This diff is collapsed.
......@@ -35,6 +35,7 @@
ceil: null, //defaults to rz-slider-model
step: 1,
precision: 0,
minRange: 0,
id: null,
translate: null,
stepsArray: null,
......@@ -740,7 +741,7 @@
this.scope.ticks = [];
for (var i = 0; i < ticksCount; i++) {
var value = this.roundStep(this.minValue + i * this.step);
var tick =   {
var tick = {
selected: this.isTickSelected(value)
};
if (tick.selected && this.options.getSelectionBarColor) {
......@@ -1518,7 +1519,9 @@
var switched = false;
if (this.range) {
/* This is to check if we need to switch the min and max handles*/
newValue = this.applyMinRange(newValue);
newOffset = this.valueToOffset(newValue);
/* This is to check if we need to switch the min and max handles */
if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) {
switched = true;
this.scope[this.tracking] = this.scope.rzSliderHigh;
......@@ -1557,6 +1560,21 @@
return switched;
},
applyMinRange: function(newValue) {
if (this.options.minRange !== 0) {
var oppositeValue = this.tracking === 'rzSliderModel' ? this.scope.rzSliderHigh : this.scope.rzSliderModel,
difference = Math.abs(newValue - oppositeValue);
if (difference < this.options.minRange) {
if (this.tracking === 'rzSliderModel')
return this.scope.rzSliderHigh - this.options.minRange;
else
return this.scope.rzSliderModel + this.options.minRange;
}
}
return newValue;
},
/**
* Apply the model values using scope.$apply.
* We wrap it with the internalChange flag to avoid the watchers to be called
......
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