Skip to content

Fix for #377 #378

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 2 commits into from
Aug 2, 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
63 changes: 31 additions & 32 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.4.1 -
(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-07-17 */
2016-08-01 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -792,7 +792,10 @@
label.rzsv = valStr;
}

if(!noLabelInjection){ label.html(valStr); };
if (!noLabelInjection) {
label.html(valStr);
}
;

this.scope[which + 'Label'] = valStr;

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/rzslider.min.js

Large diffs are not rendered by default.

61 changes: 30 additions & 31 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,10 @@
label.rzsv = valStr;
}

if(!noLabelInjection){ label.html(valStr); };
if (!noLabelInjection) {
label.html(valStr);
}
;

this.scope[which + 'Label'] = valStr;

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
floor: 0,
ceil: 100,
minRange: 10,
maxRange: 50,
noSwitching: true
}
};
Expand Down Expand Up @@ -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() {
Expand Down