Commit 64e8a942 authored by Valentin Hervieu's avatar Valentin Hervieu Committed by GitHub

Fix for #377 (#378)

* Add unit test showing the issue

* Fix the issue
parent c7b11698
/*! angularjs-slider - v5.4.1 - /*! angularjs-slider - v5.4.1 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - (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 - https://github.com/angular-slider/angularjs-slider -
2016-07-17 */ 2016-08-01 */
/*jslint unparam: true */ /*jslint unparam: true */
/*global angular: false, console: false, define, module */ /*global angular: false, console: false, define, module */
(function(root, factory) { (function(root, factory) {
...@@ -792,7 +792,10 @@ ...@@ -792,7 +792,10 @@
label.rzsv = valStr; label.rzsv = valStr;
} }
if(!noLabelInjection){ label.html(valStr); }; if (!noLabelInjection) {
label.html(valStr);
}
;
this.scope[which + 'Label'] = valStr; this.scope[which + 'Label'] = valStr;
...@@ -933,7 +936,7 @@ ...@@ -933,7 +936,7 @@
'background-color': this.getSelectionBarColor() 'background-color': this.getSelectionBarColor()
}; };
} }
if(!tick.selected && this.options.getTickColor){ if (!tick.selected && this.options.getTickColor) {
tick.style = { tick.style = {
'background-color': this.getTickColor(value) 'background-color': this.getTickColor(value)
} }
...@@ -1098,7 +1101,7 @@ ...@@ -1098,7 +1101,7 @@
shFloorCeil: function() { shFloorCeil: function() {
// Show based only on hideLimitLabels if pointer labels are hidden // Show based only on hideLimitLabels if pointer labels are hidden
if (this.options.hidePointerLabels) { if (this.options.hidePointerLabels) {
return; return;
} }
var flHidden = false, var flHidden = false,
clHidden = false, clHidden = false,
...@@ -1937,40 +1940,36 @@ ...@@ -1937,40 +1940,36 @@
valueChanged = true; valueChanged = true;
} }
else { else {
if (this.options.noSwitching) {
if (this.tracking === 'lowValue' && newValue > this.highValue)
newValue = this.applyMinMaxRange(this.highValue);
else if (this.tracking === 'highValue' && newValue < this.lowValue)
newValue = this.applyMinMaxRange(this.lowValue);
}
newValue = this.applyMinMaxRange(newValue); newValue = this.applyMinMaxRange(newValue);
/* This is to check if we need to switch the min and max handles */ /* This is to check if we need to switch the min and max handles */
if (this.tracking === 'lowValue' && newValue > this.highValue) { if (this.tracking === 'lowValue' && newValue > this.highValue) {
if (this.options.noSwitching && this.highValue !== this.minValue) { this.lowValue = this.highValue;
newValue = this.applyMinMaxRange(this.highValue); this.applyLowValue();
} this.updateHandles(this.tracking, this.maxH.rzsp);
else { this.updateAriaAttributes();
this.lowValue = this.highValue; this.tracking = 'highValue';
this.applyLowValue(); this.minH.removeClass('rz-active');
this.updateHandles(this.tracking, this.maxH.rzsp); this.maxH.addClass('rz-active');
this.updateAriaAttributes(); if (this.options.keyboardSupport)
this.tracking = 'highValue'; this.focusElement(this.maxH);
this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.maxH);
}
valueChanged = true; valueChanged = true;
} }
else if (this.tracking === 'highValue' && newValue < this.lowValue) { else if (this.tracking === 'highValue' && newValue < this.lowValue) {
if (this.options.noSwitching && this.lowValue !== this.maxValue) { this.highValue = this.lowValue;
newValue = this.applyMinMaxRange(this.lowValue); this.applyHighValue();
} this.updateHandles(this.tracking, this.minH.rzsp);
else { this.updateAriaAttributes();
this.highValue = this.lowValue; this.tracking = 'lowValue';
this.applyHighValue(); this.maxH.removeClass('rz-active');
this.updateHandles(this.tracking, this.minH.rzsp); this.minH.addClass('rz-active');
this.updateAriaAttributes(); if (this.options.keyboardSupport)
this.tracking = 'lowValue'; this.focusElement(this.minH);
this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.minH);
}
valueChanged = true; valueChanged = true;
} }
} }
......
This diff is collapsed.
...@@ -796,7 +796,10 @@ ...@@ -796,7 +796,10 @@
label.rzsv = valStr; label.rzsv = valStr;
} }
if(!noLabelInjection){ label.html(valStr); }; if (!noLabelInjection) {
label.html(valStr);
}
;
this.scope[which + 'Label'] = valStr; this.scope[which + 'Label'] = valStr;
...@@ -937,7 +940,7 @@ ...@@ -937,7 +940,7 @@
'background-color': this.getSelectionBarColor() 'background-color': this.getSelectionBarColor()
}; };
} }
if(!tick.selected && this.options.getTickColor){ if (!tick.selected && this.options.getTickColor) {
tick.style = { tick.style = {
'background-color': this.getTickColor(value) 'background-color': this.getTickColor(value)
} }
...@@ -1102,7 +1105,7 @@ ...@@ -1102,7 +1105,7 @@
shFloorCeil: function() { shFloorCeil: function() {
// Show based only on hideLimitLabels if pointer labels are hidden // Show based only on hideLimitLabels if pointer labels are hidden
if (this.options.hidePointerLabels) { if (this.options.hidePointerLabels) {
return; return;
} }
var flHidden = false, var flHidden = false,
clHidden = false, clHidden = false,
...@@ -1941,40 +1944,36 @@ ...@@ -1941,40 +1944,36 @@
valueChanged = true; valueChanged = true;
} }
else { else {
if (this.options.noSwitching) {
if (this.tracking === 'lowValue' && newValue > this.highValue)
newValue = this.applyMinMaxRange(this.highValue);
else if (this.tracking === 'highValue' && newValue < this.lowValue)
newValue = this.applyMinMaxRange(this.lowValue);
}
newValue = this.applyMinMaxRange(newValue); newValue = this.applyMinMaxRange(newValue);
/* This is to check if we need to switch the min and max handles */ /* This is to check if we need to switch the min and max handles */
if (this.tracking === 'lowValue' && newValue > this.highValue) { if (this.tracking === 'lowValue' && newValue > this.highValue) {
if (this.options.noSwitching && this.highValue !== this.minValue) { this.lowValue = this.highValue;
newValue = this.applyMinMaxRange(this.highValue); this.applyLowValue();
} this.updateHandles(this.tracking, this.maxH.rzsp);
else { this.updateAriaAttributes();
this.lowValue = this.highValue; this.tracking = 'highValue';
this.applyLowValue(); this.minH.removeClass('rz-active');
this.updateHandles(this.tracking, this.maxH.rzsp); this.maxH.addClass('rz-active');
this.updateAriaAttributes(); if (this.options.keyboardSupport)
this.tracking = 'highValue'; this.focusElement(this.maxH);
this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.maxH);
}
valueChanged = true; valueChanged = true;
} }
else if (this.tracking === 'highValue' && newValue < this.lowValue) { else if (this.tracking === 'highValue' && newValue < this.lowValue) {
if (this.options.noSwitching && this.lowValue !== this.maxValue) { this.highValue = this.lowValue;
newValue = this.applyMinMaxRange(this.lowValue); this.applyHighValue();
} this.updateHandles(this.tracking, this.minH.rzsp);
else { this.updateAriaAttributes();
this.highValue = this.lowValue; this.tracking = 'lowValue';
this.applyHighValue(); this.maxH.removeClass('rz-active');
this.updateHandles(this.tracking, this.minH.rzsp); this.minH.addClass('rz-active');
this.updateAriaAttributes(); if (this.options.keyboardSupport)
this.tracking = 'lowValue'; this.focusElement(this.minH);
this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.minH);
}
valueChanged = true; valueChanged = true;
} }
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
floor: 0, floor: 0,
ceil: 100, ceil: 100,
minRange: 10, minRange: 10,
maxRange: 50,
noSwitching: true noSwitching: true
} }
}; };
...@@ -81,6 +82,44 @@ ...@@ -81,6 +82,44 @@
expect(helper.scope.slider.min).to.equal(45); expect(helper.scope.slider.min).to.equal(45);
expect(helper.scope.slider.max).to.equal(55); expect(helper.scope.slider.max).to.equal(55);
}); });
it('should not modify any value if new range would be larger than maxRange when moving minH', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 0;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(5);
});
it('should not modify any value if new range would be larger than maxRange when moving maxH', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 100;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(95);
});
it('should not switch min/max when moving minH far higher than maxH (issue #377)', function() {
helper.scope.slider.min = 0;
helper.scope.slider.max = 10;
helper.scope.$digest();
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 100;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(10);
});
it('should not switch min/max when moving maxH far lower than minH (issue #377)', function() {
helper.scope.slider.min = 90;
helper.scope.slider.max = 100;
helper.scope.$digest();
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 0;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(90);
expect(helper.scope.slider.max).to.equal(100);
});
}); });
describe('Right to left Mouse controls - minRange and noSwitching Range Horizontal', function() { describe('Right to left Mouse controls - minRange and noSwitching Range Horizontal', function() {
......
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