Skip to content

Commit b72e236

Browse files
feat(): added option boundPointerLabels
added new option boundPointerLabels (default: true). If it is false - pointer label will not stick to the ends of slider.
1 parent 5e5c94a commit b72e236

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

dist/rzslider.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.13.0 -
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-04-24 */
4+
2016-05-13 */
55
rzslider {
66
position: relative;
77
display: inline-block;

dist/rzslider.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.13.0 -
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-04-24 */
4+
2016-05-13 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -62,7 +62,8 @@
6262
onStart: null,
6363
onChange: null,
6464
onEnd: null,
65-
rightToLeft: false
65+
rightToLeft: false,
66+
boundPointerLabels: true
6667
};
6768
var globalOptions = {};
6869

@@ -904,6 +905,9 @@
904905
nearHandlePos = newOffset - labelRzsd / 2 + this.handleHalfDim,
905906
endOfBarPos = this.barDimension - labelRzsd;
906907

908+
if (!this.options.boundPointerLabels)
909+
return nearHandlePos;
910+
907911
if (this.options.rightToLeft && labelName === 'minLab' || !this.options.rightToLeft && labelName === 'maxLab') {
908912
return Math.min(nearHandlePos, endOfBarPos);
909913
} else {
@@ -1100,13 +1104,14 @@
11001104
}
11011105

11021106
this.translateFn(labelVal, this.cmbLab, 'cmb', false);
1103-
var pos = Math.min(
1107+
var pos = this.options.boundPointerLabels ? Math.min(
11041108
Math.max(
11051109
this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2,
11061110
0
11071111
),
11081112
this.barDimension - this.cmbLab.rzsd
1109-
);
1113+
) : this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2;
1114+
11101115
this.setPosition(this.cmbLab, pos);
11111116
this.hideEl(this.minLab);
11121117
this.hideEl(this.maxLab);

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.

src/rzslider.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
onStart: null,
6767
onChange: null,
6868
onEnd: null,
69-
rightToLeft: false
69+
rightToLeft: false,
70+
boundPointerLabels: true
7071
};
7172
var globalOptions = {};
7273

@@ -908,6 +909,9 @@
908909
nearHandlePos = newOffset - labelRzsd / 2 + this.handleHalfDim,
909910
endOfBarPos = this.barDimension - labelRzsd;
910911

912+
if (!this.options.boundPointerLabels)
913+
return nearHandlePos;
914+
911915
if (this.options.rightToLeft && labelName === 'minLab' || !this.options.rightToLeft && labelName === 'maxLab') {
912916
return Math.min(nearHandlePos, endOfBarPos);
913917
} else {
@@ -1104,13 +1108,14 @@
11041108
}
11051109

11061110
this.translateFn(labelVal, this.cmbLab, 'cmb', false);
1107-
var pos = Math.min(
1111+
var pos = this.options.boundPointerLabels ? Math.min(
11081112
Math.max(
11091113
this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2,
11101114
0
11111115
),
11121116
this.barDimension - this.cmbLab.rzsd
1113-
);
1117+
) : this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2;
1118+
11141119
this.setPosition(this.cmbLab, pos);
11151120
this.hideEl(this.minLab);
11161121
this.hideEl(this.maxLab);

tests/specs/options-handling-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,28 @@
11631163
expect(helper.slider.minValue).to.equal(1);
11641164
expect(helper.slider.maxValue).to.equal(1000);
11651165
});
1166+
1167+
it('should set the correct position for labels for single slider with boundPointerLabels=false', function() {
1168+
var sliderConf = {
1169+
min: 100000000,
1170+
max: 100001000,
1171+
options: {
1172+
floor: 100000000,
1173+
ceil: 100001000,
1174+
boundPointerLabels: false
1175+
}
1176+
};
1177+
1178+
helper.createRangeSlider(sliderConf);
1179+
expect(helper.slider.minLab.css('left')).to.equal('-' + (helper.slider.minLab.rzsd / 2 - helper.slider.handleHalfDim) + 'px');
1180+
expect(helper.slider.maxLab.css('left')).to.equal((helper.slider.barDimension - (helper.slider.maxLab.rzsd / 2 + helper.slider.handleHalfDim)) + 'px');
1181+
1182+
sliderConf.max = 100000001;
1183+
helper.createRangeSlider(sliderConf);
1184+
1185+
expect(parseInt(helper.slider.cmbLab.css('left'))).to.be.below(0);
1186+
});
1187+
11661188
});
11671189
});
11681190

0 commit comments

Comments
 (0)