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 -
(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 -
2016-07-17 */
2016-08-01 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
......@@ -792,7 +792,10 @@
label.rzsv = valStr;
}
if(!noLabelInjection){ label.html(valStr); };
if (!noLabelInjection) {
label.html(valStr);
}
;
this.scope[which + 'Label'] = valStr;
......@@ -933,7 +936,7 @@
'background-color': this.getSelectionBarColor()
};
}
if(!tick.selected && this.options.getTickColor){
if (!tick.selected && this.options.getTickColor) {
tick.style = {
'background-color': this.getTickColor(value)
}
......@@ -1098,7 +1101,7 @@
shFloorCeil: function() {
// Show based only on hideLimitLabels if pointer labels are hidden
if (this.options.hidePointerLabels) {
return;
return;
}
var flHidden = false,
clHidden = false,
......@@ -1937,40 +1940,36 @@
valueChanged = true;
}
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);
/* This is to check if we need to switch the min and max handles */
if (this.tracking === 'lowValue' && newValue > this.highValue) {
if (this.options.noSwitching && this.highValue !== this.minValue) {
newValue = this.applyMinMaxRange(this.highValue);
}
else {
this.lowValue = this.highValue;
this.applyLowValue();
this.updateHandles(this.tracking, this.maxH.rzsp);
this.updateAriaAttributes();
this.tracking = 'highValue';
this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.maxH);
}
this.lowValue = this.highValue;
this.applyLowValue();
this.updateHandles(this.tracking, this.maxH.rzsp);
this.updateAriaAttributes();
this.tracking = 'highValue';
this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.maxH);
valueChanged = true;
}
else if (this.tracking === 'highValue' && newValue < this.lowValue) {
if (this.options.noSwitching && this.lowValue !== this.maxValue) {
newValue = this.applyMinMaxRange(this.lowValue);
}
else {
this.highValue = this.lowValue;
this.applyHighValue();
this.updateHandles(this.tracking, this.minH.rzsp);
this.updateAriaAttributes();
this.tracking = 'lowValue';
this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.minH);
}
this.highValue = this.lowValue;
this.applyHighValue();
this.updateHandles(this.tracking, this.minH.rzsp);
this.updateAriaAttributes();
this.tracking = 'lowValue';
this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.minH);
valueChanged = true;
}
}
......
This diff is collapsed.
......@@ -796,7 +796,10 @@
label.rzsv = valStr;
}
if(!noLabelInjection){ label.html(valStr); };
if (!noLabelInjection) {
label.html(valStr);
}
;
this.scope[which + 'Label'] = valStr;
......@@ -937,7 +940,7 @@
'background-color': this.getSelectionBarColor()
};
}
if(!tick.selected && this.options.getTickColor){
if (!tick.selected && this.options.getTickColor) {
tick.style = {
'background-color': this.getTickColor(value)
}
......@@ -1102,7 +1105,7 @@
shFloorCeil: function() {
// Show based only on hideLimitLabels if pointer labels are hidden
if (this.options.hidePointerLabels) {
return;
return;
}
var flHidden = false,
clHidden = false,
......@@ -1941,40 +1944,36 @@
valueChanged = true;
}
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);
/* This is to check if we need to switch the min and max handles */
if (this.tracking === 'lowValue' && newValue > this.highValue) {
if (this.options.noSwitching && this.highValue !== this.minValue) {
newValue = this.applyMinMaxRange(this.highValue);
}
else {
this.lowValue = this.highValue;
this.applyLowValue();
this.updateHandles(this.tracking, this.maxH.rzsp);
this.updateAriaAttributes();
this.tracking = 'highValue';
this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.maxH);
}
this.lowValue = this.highValue;
this.applyLowValue();
this.updateHandles(this.tracking, this.maxH.rzsp);
this.updateAriaAttributes();
this.tracking = 'highValue';
this.minH.removeClass('rz-active');
this.maxH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.maxH);
valueChanged = true;
}
else if (this.tracking === 'highValue' && newValue < this.lowValue) {
if (this.options.noSwitching && this.lowValue !== this.maxValue) {
newValue = this.applyMinMaxRange(this.lowValue);
}
else {
this.highValue = this.lowValue;
this.applyHighValue();
this.updateHandles(this.tracking, this.minH.rzsp);
this.updateAriaAttributes();
this.tracking = 'lowValue';
this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.minH);
}
this.highValue = this.lowValue;
this.applyHighValue();
this.updateHandles(this.tracking, this.minH.rzsp);
this.updateAriaAttributes();
this.tracking = 'lowValue';
this.maxH.removeClass('rz-active');
this.minH.addClass('rz-active');
if (this.options.keyboardSupport)
this.focusElement(this.minH);
valueChanged = true;
}
}
......
......@@ -28,6 +28,7 @@
floor: 0,
ceil: 100,
minRange: 10,
maxRange: 50,
noSwitching: true
}
};
......@@ -81,6 +82,44 @@
expect(helper.scope.slider.min).to.equal(45);
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() {
......
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