Skip to content

fix(applyPushRange): Apply the pushRange with maxRange #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/rzslider.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.5 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2016-11-05 */
2016-11-08 */
.rzslider {
position: relative;
display: inline-block;
Expand Down
30 changes: 23 additions & 7 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.5 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2016-11-05 */
2016-11-08 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -2141,17 +2141,33 @@

applyPushRange: function(newValue) {
var difference = this.tracking === 'lowValue' ? this.highValue - newValue : newValue - this.lowValue,
range = this.options.minRange !== null ? this.options.minRange : this.options.step;
if (difference < range) {
minRange = this.options.minRange !== null ? this.options.minRange : this.options.step,
maxRange = this.options.maxRange;
// if smaller than minRange
if (difference < minRange) {
if (this.tracking === 'lowValue') {
this.highValue = Math.min(newValue + range, this.maxValue);
newValue = this.highValue - range;
this.highValue = Math.min(newValue + minRange, this.maxValue);
newValue = this.highValue - minRange;
this.applyHighValue();
this.updateHandles('highValue', this.valueToPosition(this.highValue));
}
else {
this.lowValue = Math.max(newValue - range, this.minValue);
newValue = this.lowValue + range;
this.lowValue = Math.max(newValue - minRange, this.minValue);
newValue = this.lowValue + minRange;
this.applyLowValue();
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
}
this.updateAriaAttributes();
}
// if greater than maxRange
else if (maxRange !== null && difference > maxRange) {
if (this.tracking === 'lowValue') {
this.highValue = newValue + maxRange;
this.applyHighValue();
this.updateHandles('highValue', this.valueToPosition(this.highValue));
}
else {
this.lowValue = newValue - maxRange;
this.applyLowValue();
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
}
Expand Down
2 changes: 1 addition & 1 deletion dist/rzslider.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/rzslider.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rzslider.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.5 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2016-11-05 */
2016-11-08 */
.rzslider {
position: relative;
display: inline-block;
Expand Down
28 changes: 22 additions & 6 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2145,17 +2145,33 @@

applyPushRange: function(newValue) {
var difference = this.tracking === 'lowValue' ? this.highValue - newValue : newValue - this.lowValue,
range = this.options.minRange !== null ? this.options.minRange : this.options.step;
if (difference < range) {
minRange = this.options.minRange !== null ? this.options.minRange : this.options.step,
maxRange = this.options.maxRange;
// if smaller than minRange
if (difference < minRange) {
if (this.tracking === 'lowValue') {
this.highValue = Math.min(newValue + range, this.maxValue);
newValue = this.highValue - range;
this.highValue = Math.min(newValue + minRange, this.maxValue);
newValue = this.highValue - minRange;
this.applyHighValue();
this.updateHandles('highValue', this.valueToPosition(this.highValue));
}
else {
this.lowValue = Math.max(newValue - range, this.minValue);
newValue = this.lowValue + range;
this.lowValue = Math.max(newValue - minRange, this.minValue);
newValue = this.lowValue + minRange;
this.applyLowValue();
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
}
this.updateAriaAttributes();
}
// if greater than maxRange
else if (maxRange !== null && difference > maxRange) {
if (this.tracking === 'lowValue') {
this.highValue = newValue + maxRange;
this.applyHighValue();
this.updateHandles('highValue', this.valueToPosition(this.highValue));
}
else {
this.lowValue = newValue - maxRange;
this.applyLowValue();
this.updateHandles('lowValue', this.valueToPosition(this.lowValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@
expect(helper.scope.slider.min).to.equal(40);
expect(helper.scope.slider.max).to.equal(40);
});

it('should pull minH when moving maxH above maxRange', function () {
helper.scope.slider.options.maxRange = 15;
helper.scope.$digest();

helper.fireMousedown(helper.slider.maxH, 0);
helper.moveMouseToValue(80);
expect(helper.scope.slider.min).to.equal(65);
expect(helper.scope.slider.max).to.equal(80);
});

it('should pull maxH when moving minH above maxRange', function () {
helper.scope.slider.options.maxRange = 15;
helper.scope.$digest();

helper.fireMousedown(helper.slider.minH, 0);
helper.moveMouseToValue(20);
expect(helper.scope.slider.min).to.equal(20);
expect(helper.scope.slider.max).to.equal(35);
});
});

}());
Expand Down