Skip to content

Commit 2e5f59d

Browse files
committed
Merge pull request #299 from nparrish/master
Feat: Allow custom translate function when slider steps are specified
2 parents 8946cc8 + 13c6dbf commit 2e5f59d

File tree

6 files changed

+47
-19
lines changed

6 files changed

+47
-19
lines changed

dist/rzslider.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! angularjs-slider - v2.10.4 -
2-
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
3-
https://github.com/angular-slider/angularjs-slider -
4-
2016-03-16 */
1+
/*! angularjs-slider - v2.10.4 -
2+
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
3+
https://github.com/angular-slider/angularjs-slider -
4+
2016-03-28 */
55
rzslider {
66
position: relative;
77
display: inline-block;
@@ -227,4 +227,4 @@ rzslider.rz-vertical .rz-ticks .rz-tick .rz-tick-value {
227227
top: auto;
228228
right: -30px;
229229
transform: translate(0, -28%);
230-
}
230+
}

dist/rzslider.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! angularjs-slider - v2.10.4 -
2-
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
3-
https://github.com/angular-slider/angularjs-slider -
4-
2016-03-16 */
1+
/*! angularjs-slider - v2.10.4 -
2+
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
3+
https://github.com/angular-slider/angularjs-slider -
4+
2016-03-28 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -423,9 +423,14 @@
423423
this.options.floor = 0;
424424
this.options.ceil = this.options.stepsArray.length - 1;
425425
this.options.step = 1;
426-
this.customTrFn = function(value) {
427-
return this.options.stepsArray[value];
428-
};
426+
if (this.options.translate) {
427+
this.customTrFn = this.options.translate;
428+
}
429+
else {
430+
this.customTrFn = function(value) {
431+
return this.options.stepsArray[value];
432+
};
433+
}
429434
} else if (this.options.translate)
430435
this.customTrFn = this.options.translate;
431436
else

dist/rzslider.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rzslider.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,14 @@
427427
this.options.floor = 0;
428428
this.options.ceil = this.options.stepsArray.length - 1;
429429
this.options.step = 1;
430-
this.customTrFn = function(value) {
431-
return this.options.stepsArray[value];
432-
};
430+
if (this.options.translate) {
431+
this.customTrFn = this.options.translate;
432+
}
433+
else {
434+
this.customTrFn = function(value) {
435+
return this.options.stepsArray[value];
436+
};
437+
}
433438
} else if (this.options.translate)
434439
this.customTrFn = this.options.translate;
435440
else

tests/specs/options-handling-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@
115115
expect(helper.slider.customTrFn(2)).to.equal('C');
116116
});
117117

118+
it('should allow a custom translate function when stepsArray is used', function() {
119+
helper.scope.slider.options.stepsArray = [{'foo': 'barA'}, {'foo': 'barB'}, {'foo': 'barC'}];
120+
helper.scope.slider.options.translate = function(value, sliderId, label) {
121+
if (value >= 0 && value < helper.scope.slider.options.stepsArray.length) {
122+
return helper.scope.slider.options.stepsArray[value]['foo'];
123+
} else {
124+
return ""
125+
}
126+
};
127+
helper.scope.$digest();
128+
expect(helper.slider.options.step).to.equal(1);
129+
expect(helper.slider.options.floor).to.equal(0);
130+
expect(helper.slider.options.ceil).to.equal(2);
131+
132+
expect(helper.slider.customTrFn(0)).to.equal('barA');
133+
expect(helper.slider.customTrFn(2)).to.equal('barC');
134+
});
135+
118136
it('should sanitize rzSliderModel between floor and ceil', function() {
119137
helper.scope.slider.options.enforceRange = true;
120138
helper.scope.slider.value = 1000;

0 commit comments

Comments
 (0)