Skip to content

Commit 3afcce9

Browse files
author
Valentin Hervieu
committed
fix(cmbLabel): Improve combined label position and show only one value if min==max
Closes #245
1 parent 4bff1a8 commit 3afcce9

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

dist/rzslider.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,13 @@
880880
updateLowHandle: function(newOffset) {
881881
this.setPosition(this.minH, newOffset);
882882
this.translateFn(this.scope.rzSliderModel, this.minLab);
883-
var pos = Math.min(Math.max(newOffset - this.minLab.rzsd / 2 + this.handleHalfDim, 0), this.barDimension - this.ceilLab.rzsd);
883+
var pos = Math.min(
884+
Math.max(
885+
newOffset - this.minLab.rzsd / 2 + this.handleHalfDim,
886+
0
887+
),
888+
this.barDimension - this.ceilLab.rzsd
889+
);
884890
this.setPosition(this.minLab, pos);
885891

886892
this.shFloorCeil();
@@ -895,7 +901,7 @@
895901
updateHighHandle: function(newOffset) {
896902
this.setPosition(this.maxH, newOffset);
897903
this.translateFn(this.scope.rzSliderHigh, this.maxLab);
898-
var pos = Math.min((newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim), (this.barDimension - this.ceilLab.rzsd));
904+
var pos = Math.min(newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim, this.barDimension - this.ceilLab.rzsd);
899905
this.setPosition(this.maxLab, pos);
900906

901907
this.shFloorCeil();
@@ -950,8 +956,8 @@
950956
updateSelectionBar: function() {
951957
var position = 0,
952958
dimension = 0;
953-
if(this.range) {
954-
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim;
959+
if (this.range) {
960+
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp);
955961
position = this.minH.rzsp + this.handleHalfDim;
956962
}
957963
else {
@@ -1001,14 +1007,20 @@
10011007
* @returns {undefined}
10021008
*/
10031009
updateCmbLabel: function() {
1004-
var lowTr, highTr;
10051010

10061011
if (this.minLab.rzsp + this.minLab.rzsd + 10 >= this.maxLab.rzsp) {
1007-
lowTr = this.getDisplayValue(this.scope.rzSliderModel);
1008-
highTr = this.getDisplayValue(this.scope.rzSliderHigh);
1009-
1010-
this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false);
1011-
var pos = Math.min(Math.max((this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2), 0), (this.barDimension - this.cmbLab.rzsd));
1012+
var lowTr = this.getDisplayValue(this.scope.rzSliderModel),
1013+
highTr = this.getDisplayValue(this.scope.rzSliderHigh),
1014+
labelVal = lowTr === highTr ? lowTr : lowTr + ' - ' + highTr;
1015+
1016+
this.translateFn(labelVal, this.cmbLab, false);
1017+
var pos = Math.min(
1018+
Math.max(
1019+
this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2,
1020+
0
1021+
),
1022+
this.barDimension - this.cmbLab.rzsd
1023+
);
10121024
this.setPosition(this.cmbLab, pos);
10131025
this.hideEl(this.minLab);
10141026
this.hideEl(this.maxLab);

0 commit comments

Comments
 (0)