Skip to content

Commit 6327b88

Browse files
GuilloOmeValentinH
authored andcommitted
fix(applyPushRange): Apply the pushRange with maxRange (#456)
Apply the pushRange when the difference is greater than the maxRange set Close issue #453
1 parent 3e83a1a commit 6327b88

File tree

7 files changed

+70
-18
lines changed

7 files changed

+70
-18
lines changed

dist/rzslider.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.8.5 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-11-05 */
4+
2016-11-08 */
55
.rzslider {
66
position: relative;
77
display: inline-block;

dist/rzslider.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.8.5 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-11-05 */
4+
2016-11-08 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -2141,17 +2141,33 @@
21412141

21422142
applyPushRange: function(newValue) {
21432143
var difference = this.tracking === 'lowValue' ? this.highValue - newValue : newValue - this.lowValue,
2144-
range = this.options.minRange !== null ? this.options.minRange : this.options.step;
2145-
if (difference < range) {
2144+
minRange = this.options.minRange !== null ? this.options.minRange : this.options.step,
2145+
maxRange = this.options.maxRange;
2146+
// if smaller than minRange
2147+
if (difference < minRange) {
21462148
if (this.tracking === 'lowValue') {
2147-
this.highValue = Math.min(newValue + range, this.maxValue);
2148-
newValue = this.highValue - range;
2149+
this.highValue = Math.min(newValue + minRange, this.maxValue);
2150+
newValue = this.highValue - minRange;
21492151
this.applyHighValue();
21502152
this.updateHandles('highValue', this.valueToPosition(this.highValue));
21512153
}
21522154
else {
2153-
this.lowValue = Math.max(newValue - range, this.minValue);
2154-
newValue = this.lowValue + range;
2155+
this.lowValue = Math.max(newValue - minRange, this.minValue);
2156+
newValue = this.lowValue + minRange;
2157+
this.applyLowValue();
2158+
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
2159+
}
2160+
this.updateAriaAttributes();
2161+
}
2162+
// if greater than maxRange
2163+
else if (maxRange !== null && difference > maxRange) {
2164+
if (this.tracking === 'lowValue') {
2165+
this.highValue = newValue + maxRange;
2166+
this.applyHighValue();
2167+
this.updateHandles('highValue', this.valueToPosition(this.highValue));
2168+
}
2169+
else {
2170+
this.lowValue = newValue - maxRange;
21552171
this.applyLowValue();
21562172
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
21572173
}

dist/rzslider.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.8.5 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-11-05 */
4+
2016-11-08 */
55
.rzslider {
66
position: relative;
77
display: inline-block;

src/rzslider.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -2145,17 +2145,33 @@
21452145

21462146
applyPushRange: function(newValue) {
21472147
var difference = this.tracking === 'lowValue' ? this.highValue - newValue : newValue - this.lowValue,
2148-
range = this.options.minRange !== null ? this.options.minRange : this.options.step;
2149-
if (difference < range) {
2148+
minRange = this.options.minRange !== null ? this.options.minRange : this.options.step,
2149+
maxRange = this.options.maxRange;
2150+
// if smaller than minRange
2151+
if (difference < minRange) {
21502152
if (this.tracking === 'lowValue') {
2151-
this.highValue = Math.min(newValue + range, this.maxValue);
2152-
newValue = this.highValue - range;
2153+
this.highValue = Math.min(newValue + minRange, this.maxValue);
2154+
newValue = this.highValue - minRange;
21532155
this.applyHighValue();
21542156
this.updateHandles('highValue', this.valueToPosition(this.highValue));
21552157
}
21562158
else {
2157-
this.lowValue = Math.max(newValue - range, this.minValue);
2158-
newValue = this.lowValue + range;
2159+
this.lowValue = Math.max(newValue - minRange, this.minValue);
2160+
newValue = this.lowValue + minRange;
2161+
this.applyLowValue();
2162+
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
2163+
}
2164+
this.updateAriaAttributes();
2165+
}
2166+
// if greater than maxRange
2167+
else if (maxRange !== null && difference > maxRange) {
2168+
if (this.tracking === 'lowValue') {
2169+
this.highValue = newValue + maxRange;
2170+
this.applyHighValue();
2171+
this.updateHandles('highValue', this.valueToPosition(this.highValue));
2172+
}
2173+
else {
2174+
this.lowValue = newValue - maxRange;
21592175
this.applyLowValue();
21602176
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
21612177
}

tests/specs/mouse-controls/pushRange-range-slider-horizontal-test.js

+20
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@
128128
expect(helper.scope.slider.min).to.equal(40);
129129
expect(helper.scope.slider.max).to.equal(40);
130130
});
131+
132+
it('should pull minH when moving maxH above maxRange', function () {
133+
helper.scope.slider.options.maxRange = 15;
134+
helper.scope.$digest();
135+
136+
helper.fireMousedown(helper.slider.maxH, 0);
137+
helper.moveMouseToValue(80);
138+
expect(helper.scope.slider.min).to.equal(65);
139+
expect(helper.scope.slider.max).to.equal(80);
140+
});
141+
142+
it('should pull maxH when moving minH above maxRange', function () {
143+
helper.scope.slider.options.maxRange = 15;
144+
helper.scope.$digest();
145+
146+
helper.fireMousedown(helper.slider.minH, 0);
147+
helper.moveMouseToValue(20);
148+
expect(helper.scope.slider.min).to.equal(20);
149+
expect(helper.scope.slider.max).to.equal(35);
150+
});
131151
});
132152

133153
}());

0 commit comments

Comments
 (0)