Skip to content

Hide floor/ceil label when overlapped on combo label #357

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
Jun 29, 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 - v4.0.2 -
(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-06-07 */
2016-06-29 */
.rzslider {
position: relative;
display: inline-block;
Expand Down
23 changes: 19 additions & 4 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v4.0.2 -
(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-06-07 */
2016-06-29 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -293,6 +293,12 @@
*/
this.internalChange = false;

/**
* Internal flag to keep track of the visibility of combo label
* @type {boolean}
*/
this.cmbLabelShown = false;

// Slider DOM elements wrapped in jqLite
this.fullBar = null; // The whole slider bar
this.selBar = null; // Highlight between two handles
Expand Down Expand Up @@ -1068,12 +1074,16 @@
minLabDim = this.minLab.rzsd,
maxLabPos = this.maxLab.rzsp,
maxLabDim = this.maxLab.rzsd,
cmbLabPos = this.cmbLab.rzsp,
cmbLabDim = this.cmbLab.rzsd,
ceilLabPos = this.ceilLab.rzsp,
halfHandle = this.handleHalfDim,
isMinLabAtFloor = isRTL ? minLabPos + minLabDim >= flrLabPos - flrLabDim - 5 : minLabPos <= flrLabPos + flrLabDim + 5,
isMinLabAtCeil = isRTL ? minLabPos - minLabDim <= ceilLabPos + halfHandle + 10 : minLabPos + minLabDim >= ceilLabPos - halfHandle - 10,
isMaxLabAtFloor = isRTL ? maxLabPos >= flrLabPos - flrLabDim - halfHandle : maxLabPos <= flrLabPos + flrLabDim + halfHandle,
isMaxLabAtCeil = isRTL ? maxLabPos - maxLabDim <= ceilLabPos + 10 : maxLabPos + maxLabDim >= ceilLabPos - 10;
isMaxLabAtCeil = isRTL ? maxLabPos - maxLabDim <= ceilLabPos + 10 : maxLabPos + maxLabDim >= ceilLabPos - 10,
isCmbLabAtFloor = isRTL ? cmbLabPos >= flrLabPos - flrLabDim - halfHandle : cmbLabPos <= flrLabPos + flrLabDim + halfHandle,
isCmbLabAtCeil = isRTL ? cmbLabPos - cmbLabDim <= ceilLabPos + 10 : cmbLabPos + cmbLabDim >= ceilLabPos - 10


if (isMinLabAtFloor) {
Expand All @@ -1093,14 +1103,17 @@
}

if (this.range) {
if (isMaxLabAtCeil) {
var hideCeil = this.cmbLabelShown ? isCmbLabAtCeil : isMaxLabAtCeil;
var hideFloor = this.cmbLabelShown ? isCmbLabAtFloor : isMinLabAtFloor;

if (hideCeil) {
this.hideEl(this.ceilLab);
} else if (!clHidden) {
this.showEl(this.ceilLab);
}

// Hide or show floor label
if (isMaxLabAtFloor) {
if (hideFloor) {
this.hideEl(this.flrLab);
} else if (!flHidden) {
this.showEl(this.flrLab);
Expand Down Expand Up @@ -1209,10 +1222,12 @@
) : this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2;

this.setPosition(this.cmbLab, pos);
this.cmbLabelShown = true;
this.hideEl(this.minLab);
this.hideEl(this.maxLab);
this.showEl(this.cmbLab);
} else {
this.cmbLabelShown = false;
this.showEl(this.maxLab);
this.showEl(this.minLab);
this.hideEl(this.cmbLab);
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.

21 changes: 18 additions & 3 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@
*/
this.internalChange = false;

/**
* Internal flag to keep track of the visibility of combo label
* @type {boolean}
*/
this.cmbLabelShown = false;

// Slider DOM elements wrapped in jqLite
this.fullBar = null; // The whole slider bar
this.selBar = null; // Highlight between two handles
Expand Down Expand Up @@ -1072,12 +1078,16 @@
minLabDim = this.minLab.rzsd,
maxLabPos = this.maxLab.rzsp,
maxLabDim = this.maxLab.rzsd,
cmbLabPos = this.cmbLab.rzsp,
cmbLabDim = this.cmbLab.rzsd,
ceilLabPos = this.ceilLab.rzsp,
halfHandle = this.handleHalfDim,
isMinLabAtFloor = isRTL ? minLabPos + minLabDim >= flrLabPos - flrLabDim - 5 : minLabPos <= flrLabPos + flrLabDim + 5,
isMinLabAtCeil = isRTL ? minLabPos - minLabDim <= ceilLabPos + halfHandle + 10 : minLabPos + minLabDim >= ceilLabPos - halfHandle - 10,
isMaxLabAtFloor = isRTL ? maxLabPos >= flrLabPos - flrLabDim - halfHandle : maxLabPos <= flrLabPos + flrLabDim + halfHandle,
isMaxLabAtCeil = isRTL ? maxLabPos - maxLabDim <= ceilLabPos + 10 : maxLabPos + maxLabDim >= ceilLabPos - 10;
isMaxLabAtCeil = isRTL ? maxLabPos - maxLabDim <= ceilLabPos + 10 : maxLabPos + maxLabDim >= ceilLabPos - 10,
isCmbLabAtFloor = isRTL ? cmbLabPos >= flrLabPos - flrLabDim - halfHandle : cmbLabPos <= flrLabPos + flrLabDim + halfHandle,
isCmbLabAtCeil = isRTL ? cmbLabPos - cmbLabDim <= ceilLabPos + 10 : cmbLabPos + cmbLabDim >= ceilLabPos - 10


if (isMinLabAtFloor) {
Expand All @@ -1097,14 +1107,17 @@
}

if (this.range) {
if (isMaxLabAtCeil) {
var hideCeil = this.cmbLabelShown ? isCmbLabAtCeil : isMaxLabAtCeil;
var hideFloor = this.cmbLabelShown ? isCmbLabAtFloor : isMinLabAtFloor;

if (hideCeil) {
this.hideEl(this.ceilLab);
} else if (!clHidden) {
this.showEl(this.ceilLab);
}

// Hide or show floor label
if (isMaxLabAtFloor) {
if (hideFloor) {
this.hideEl(this.flrLab);
} else if (!flHidden) {
this.showEl(this.flrLab);
Expand Down Expand Up @@ -1213,10 +1226,12 @@
) : this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2;

this.setPosition(this.cmbLab, pos);
this.cmbLabelShown = true;
this.hideEl(this.minLab);
this.hideEl(this.maxLab);
this.showEl(this.cmbLab);
} else {
this.cmbLabelShown = false;
this.showEl(this.maxLab);
this.showEl(this.minLab);
this.hideEl(this.cmbLab);
Expand Down
40 changes: 40 additions & 0 deletions tests/specs/labels-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,46 @@
expect(helper.slider.flrLab.css('opacity')).to.equal('0');
expect(helper.slider.ceilLab.css('opacity')).to.equal('0');
});

it('should hide floor and ceil labels when cmb label is overlapping, for range slider', function() {
var sliderConf = {
minValue: 50,
maxValue: 50,
options: {
floor: 0,
ceil: 100,
translate: function(v, _, which){
if(which != 'model' && which != 'high') return v;
return "I'm whatever long text ==============================================================================================================================================================="
}
}
};

helper.createRangeSlider(sliderConf);
expect(helper.slider.flrLab.css('opacity')).to.equal('0');
expect(helper.slider.ceilLab.css('opacity')).to.equal('0');
});

it('should hide floor and ceil labels when cmb label is overlapping, for range RTL slider', function() {
var sliderConf = {
minValue: 50,
maxValue: 50,
options: {
floor: 0,
ceil: 100,
translate: function(v, _, which){
if(which != 'model' && which != 'high') return v;
return "I'm whatever long text ==============================================================================================================================================================="
}
},
rightToLeft: true
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.flrLab.css('opacity')).to.equal('0');
expect(helper.slider.ceilLab.css('opacity')).to.equal('0');
});


});
}());