Skip to content

Commit b61a94b

Browse files
author
Valentin Hervieu
committed
feat(cmbLabel): Add a mergeRangeLabelsIfSame option
In 3afcce9 commit, I changed the behavior of the combined label for range slider. However, this broke previous implementation, so this commit add an option to configure this feature. The default behavior is back as previously: If the slider values are the same, the combined label is 'X - X' Related to #245
1 parent 9b40f68 commit b61a94b

File tree

10 files changed

+47
-17
lines changed

10 files changed

+47
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 4.0.2 (2016-06-07)
2+
## Improvement
3+
- Add a `mergeRangeLabelsIfSame` option (#245).
4+
15
# 4.0.1 (2016-06-04)
26
## Improvement
37
- Add a pointerType arg for the callbacks (onStart, onChange and onEnd) to identify which handle is used (#339).

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ The default options are:
220220
onStart: null,
221221
onChange: null,
222222
onEnd: null,
223-
rightToLeft: false
223+
rightToLeft: false,
224+
boundPointerLabels: true,
225+
mergeRangeLabelsIfSame: false
224226
}
225227
````
226228

@@ -328,6 +330,10 @@ Just pass an array with each slider value and that's it; the floor, ceil and ste
328330

329331
**onlyBindHandles** - _Boolean (defaults to false)_: Set to true to only bind events on slider handles.
330332

333+
**boundPointerLabels** - _Boolean (defaults to true)_: Set to true to keep the slider labels inside the slider bounds.
334+
335+
**mergeRangeLabelsIfSame** - _Boolean (defaults to false)_: Set to true to merge the range labels if they are the same. For instance, if min and max are 50, the label will be "50 - 50" if `mergeRangeLabelsIfSame: false`, else "50".
336+
331337
**onStart** - _Function(sliderId, modelValue, highValue, pointerType)_: Function to be called when a slider update is started. If an id was set in the options, then it's passed to this callback. This callback is called before any update on the model. `pointerType` is either 'min' or 'max' depending on which handle is used.
332338

333339
**onChange** - _Function(sliderId, modelValue, highValue, pointerType)_: Function to be called when rz-slider-model or rz-slider-high change. If an id was set in the options, then it's passed to this callback. `pointerType` is either 'min' or 'max' depending on which handle is used.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-slider",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"homepage": "https://github.com/angular-slider/angularjs-slider",
55
"authors": [
66
"Rafal Zajac <rzajac@gmail.com>",

dist/rzslider.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! angularjs-slider - v4.0.1 -
1+
/*! angularjs-slider - v4.0.2 -
22
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-06-04 */
4+
2016-06-07 */
55
.rzslider {
66
position: relative;
77
display: inline-block;

dist/rzslider.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! angularjs-slider - v4.0.1 -
1+
/*! angularjs-slider - v4.0.2 -
22
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-06-04 */
4+
2016-06-07 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -66,7 +66,8 @@
6666
onChange: null,
6767
onEnd: null,
6868
rightToLeft: false,
69-
boundPointerLabels: true
69+
boundPointerLabels: true,
70+
mergeRangeLabelsIfSame: false
7071
};
7172
var globalOptions = {};
7273

@@ -1192,7 +1193,7 @@
11921193
var lowTr = this.getDisplayValue(this.lowValue, 'model'),
11931194
highTr = this.getDisplayValue(this.highValue, 'high'),
11941195
labelVal = '';
1195-
if (lowTr === highTr) {
1196+
if (this.options.mergeRangeLabelsIfSame && lowTr === highTr) {
11961197
labelVal = lowTr;
11971198
} else {
11981199
labelVal = this.options.rightToLeft ? highTr + ' - ' + lowTr : lowTr + ' - ' + highTr;

dist/rzslider.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-slider",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"description": "AngularJS slider directive with no external dependencies. Mobile friendly!.",
55
"main": "dist/rzslider.js",
66
"repository": {

src/rzslider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
onChange: null,
7171
onEnd: null,
7272
rightToLeft: false,
73-
boundPointerLabels: true
73+
boundPointerLabels: true,
74+
mergeRangeLabelsIfSame: false
7475
};
7576
var globalOptions = {};
7677

@@ -1196,7 +1197,7 @@
11961197
var lowTr = this.getDisplayValue(this.lowValue, 'model'),
11971198
highTr = this.getDisplayValue(this.highValue, 'high'),
11981199
labelVal = '';
1199-
if (lowTr === highTr) {
1200+
if (this.options.mergeRangeLabelsIfSame && lowTr === highTr) {
12001201
labelVal = lowTr;
12011202
} else {
12021203
labelVal = this.options.rightToLeft ? highTr + ' - ' + lowTr : lowTr + ' - ' + highTr;

tests/specs/options-handling-test.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,22 @@
667667
expect(helper.slider.lowValue).to.equal(1);
668668
expect(helper.slider.highValue).to.equal(3);
669669
});
670+
671+
it('should set the correct combined label when range values are the same and mergeRangeLabelsIfSame option is false', function() {
672+
helper.scope.slider.options.mergeRangeLabelsIfSame = false;
673+
helper.scope.slider.min = 50;
674+
helper.scope.slider.max = 50;
675+
helper.scope.$digest();
676+
expect(helper.slider.cmbLab.text()).to.equal('50 - 50');
677+
});
678+
679+
it('should set the correct combined label when range values are the same and mergeRangeLabelsIfSame option is true', function() {
680+
helper.scope.slider.options.mergeRangeLabelsIfSame = true;
681+
helper.scope.slider.min = 50;
682+
helper.scope.slider.max = 50;
683+
helper.scope.$digest();
684+
expect(helper.slider.cmbLab.text()).to.equal('50');
685+
});
670686
});
671687

672688
describe('options expression specific - ', function() {
@@ -889,8 +905,9 @@
889905
}
890906
};
891907
helper.createSlider(sliderConf);
892-
var expectedDimension = Math.floor(helper.slider.valueToOffset(8) + helper.slider.handleHalfDim);
893-
expect(helper.slider.selBar[0].getBoundingClientRect().width).to.equal(expectedDimension);
908+
var expectedDimension = Math.floor(helper.slider.valueToOffset(8) + helper.slider.handleHalfDim),
909+
actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
910+
expect(actualDimension).to.equal(expectedDimension);
894911
expect(helper.slider.selBar.css('left')).to.equal(helper.slider.valueToOffset(2) + helper.slider.handleHalfDim + 'px');
895912
});
896913

@@ -939,8 +956,9 @@
939956
};
940957
helper.createSlider(sliderConf);
941958
var expectedDimension = Math.floor(helper.slider.valueToOffset(13)),
959+
actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width),
942960
expectedPosition = helper.slider.valueToOffset(10) + helper.slider.handleHalfDim;
943-
expect(helper.slider.selBar[0].getBoundingClientRect().width).to.equal(expectedDimension);
961+
expect(actualDimension).to.equal(expectedDimension);
944962
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
945963
});
946964

0 commit comments

Comments
 (0)