Skip to content

Commit

Permalink
Fixed code climate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
junchangchen committed Apr 23, 2017
1 parent b17425e commit 536a494
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
7 changes: 4 additions & 3 deletions dist/bootstrap-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,11 @@ var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(win

/* Create highlight range elements */
this.rangeHighlightElements = [];
if (Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) {
for (var j = 0; j < this.options.rangeHighlights.length; j++) {
var rangeHighlightsOpts = this.options.rangeHighlights;
if (Array.isArray(rangeHighlightsOpts) && rangeHighlightsOpts.length > 0) {
for (var j = 0; j < rangeHighlightsOpts.length; j++) {
var rangeHighlightElement = document.createElement("div");
rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + (this.options.rangeHighlights[j].class || "");
rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + (rangeHighlightsOpts[j].class || "");
this.rangeHighlightElements.push(rangeHighlightElement);
sliderTrack.appendChild(rangeHighlightElement);
}
Expand Down
4 changes: 2 additions & 2 deletions dist/bootstrap-slider.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/js/bootstrap-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,11 @@ const windowIsDefined = (typeof window === "object");

/* Create highlight range elements */
this.rangeHighlightElements = [];
if (Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) {
for (let j = 0; j < this.options.rangeHighlights.length; j++) {
var rangeHighlightsOpts = this.options.rangeHighlights;
if (Array.isArray(rangeHighlightsOpts) && rangeHighlightsOpts.length > 0) {
for (let j = 0; j < rangeHighlightsOpts.length; j++) {
var rangeHighlightElement = document.createElement("div");
rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + (this.options.rangeHighlights[j].class || "");
rangeHighlightElement.className = "slider-rangeHighlight slider-selection " + (rangeHighlightsOpts[j].class || "");
this.rangeHighlightElements.push(rangeHighlightElement);
sliderTrack.appendChild(rangeHighlightElement);
}
Expand Down
48 changes: 20 additions & 28 deletions test/specs/RangeHighlightsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@ describe("RangeHighlights Render Tests", function() {

//setup
beforeEach(function() {
var rangeHighlightsOpts1 = [
{ "start": 2, "end": 5, "class": "category1" }, // left: 10%; width: 15%
{ "start": 7, "end": 8, "class": "category2" }, // left: 35%; width: 5%
{ "start": 17, "end": 19 }, // left: 85%; width: 10%
{ "start": 17, "end": 24 }, //out of range - not visible
{ "start": -3, "end": 19 } //out of range - not visible
];

var rangeHighlightsOpts2 = [
{ "start": 2, "end": 5, "class": "category1" }, // top: 10%; height: 15%
{ "start": 7, "end": 8, "class": "category2" }, // top: 35%; height: 5%
{ "start": 17, "end": 19 }, // top: 85%; height: 10%
{ "start": 7, "end": -4 }, //out of range - not visible
{ "start": 23, "end": 15 } //out of range - not visible
];

testSlider1 = $('#testSlider1').slider({
id: 'slider1',
min: 0,
max: 20,
step: 1,
value: 14,
rangeHighlights: [
{ "start": 2, "end": 5, "class": "category1" }, // left: 10%; width: 15%
{ "start": 7, "end": 8, "class": "category2" }, // left: 35%; width: 5%
{ "start": 17, "end": 19 }, // left: 85%; width: 10%
{ "start": 17, "end": 24 }, //out of range - not visible
{ "start": -3, "end": 19 } //out of range - not visible
]
rangeHighlights: rangeHighlightsOpts1
});

testSlider2 = $('#testSlider2').slider({
Expand All @@ -32,13 +42,7 @@ describe("RangeHighlights Render Tests", function() {
step: 1,
value: 14,
orientation: 'vertical',
rangeHighlights: [
{ "start": 2, "end": 5, "class": "category1" }, // top: 10%; height: 15%
{ "start": 7, "end": 8, "class": "category2" }, // top: 35%; height: 5%
{ "start": 17, "end": 19 }, // top: 85%; height: 10%
{ "start": 7, "end": -4 }, //out of range - not visible
{ "start": 23, "end": 15 } //out of range - not visible
]
rangeHighlights: rangeHighlightsOpts2
});

testSlider3 = $('#testSlider3').slider({
Expand All @@ -48,13 +52,7 @@ describe("RangeHighlights Render Tests", function() {
step: 1,
value: 14,
reversed: true,
rangeHighlights: [
{ "start": 2, "end": 5, "class": "category1" }, // left: 75%; width: 15%
{ "start": 7, "end": 8, "class": "category2" }, // left: 60%; width: 5%
{ "start": 17, "end": 19 }, // left: 5%; width: 10%
{ "start": 17, "end": 24 }, //out of range - not visible
{ "start": -3, "end": 19 } //out of range - not visible
]
rangeHighlights: rangeHighlightsOpts1
});

testSlider4 = $('#testSlider4').slider({
Expand All @@ -65,13 +63,7 @@ describe("RangeHighlights Render Tests", function() {
value: 14,
reversed: true,
orientation: 'vertical',
rangeHighlights: [
{ "start": 2, "end": 5, "class": "category1" }, // top: 75%; height: 15%
{ "start": 7, "end": 8, "class": "category2" }, // top: 60%; height: 5%
{ "start": 17, "end": 19 }, // top: 5%; height: 10%
{ "start": 7, "end": -4 }, //out of range - not visible
{ "start": 23, "end": 15 } //out of range - not visible
]
rangeHighlights: rangeHighlightsOpts2
});
});

Expand Down

0 comments on commit 536a494

Please sign in to comment.