Skip to content

Commit 87ca837

Browse files
committed
Add rtl support
1 parent e86204e commit 87ca837

File tree

5 files changed

+50
-38
lines changed

5 files changed

+50
-38
lines changed

dist/rzslider.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.5.1 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-09-22 */
4+
2016-10-07 */
55
.rzslider {
66
position: relative;
77
display: inline-block;

dist/rzslider.js

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.5.1 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-09-22 */
4+
2016-10-07 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -61,6 +61,7 @@
6161
getTickColor: null,
6262
getPointerColor: null,
6363
keyboardSupport: true,
64+
logScale: false,
6465
scale: 1,
6566
enforceStep: true,
6667
enforceRange: false,
@@ -831,6 +832,8 @@
831832
this.precision = +this.options.precision;
832833

833834
this.minValue = this.options.floor;
835+
if (this.options.logScale && this.minValue === 0)
836+
throw new Error("Can't use floor=0 with logarithmic scale");
834837

835838
if (this.options.enforceStep) {
836839
this.lowValue = this.roundStep(this.lowValue);
@@ -1407,10 +1410,17 @@
14071410
* @returns {number}
14081411
*/
14091412
valueToOffset: function(val) {
1410-
if (this.options.rightToLeft) {
1411-
return (this.maxValue - this.sanitizeValue(val)) * this.maxPos / this.valueRange || 0;
1412-
}
1413-
return (this.sanitizeValue(val) - this.minValue) * this.maxPos / this.valueRange || 0;
1413+
var sanitizedValue = this.sanitizeValue(val),
1414+
minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
1415+
maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
1416+
range = maxValue - minValue;
1417+
1418+
if (this.options.logScale)
1419+
sanitizedValue = Math.log(sanitizedValue);
1420+
1421+
if (this.options.rightToLeft)
1422+
return (maxValue - sanitizedValue) * this.maxPos / range || 0;
1423+
return (sanitizedValue - minValue) * this.maxPos / range || 0;
14141424
},
14151425

14161426
/**
@@ -1430,10 +1440,16 @@
14301440
* @returns {number}
14311441
*/
14321442
offsetToValue: function(offset) {
1433-
if (this.options.rightToLeft) {
1434-
return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue;
1435-
}
1436-
return (offset / this.maxPos) * this.valueRange + this.minValue;
1443+
var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
1444+
maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
1445+
range = maxValue - minValue,
1446+
value = 0;
1447+
if (this.options.rightToLeft)
1448+
value = (1 - offset / this.maxPos) * range + minValue;
1449+
else
1450+
value = offset / this.maxPos * range + minValue;
1451+
1452+
return this.options.logScale ? Math.exp(value) : value;
14371453
},
14381454

14391455
// Events

dist/rzslider.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rzslider.js

+21-25
Original file line numberDiff line numberDiff line change
@@ -1414,19 +1414,17 @@
14141414
* @returns {number}
14151415
*/
14161416
valueToOffset: function(val) {
1417-
var sanitizedValue = this.sanitizeValue(val);
1418-
if (!this.options.logScale) {
1419-
if (this.options.rightToLeft) {
1420-
return (this.maxValue - sanitizedValue) * this.maxPos / this.valueRange || 0;
1421-
}
1422-
return (sanitizedValue - this.minValue) * this.maxPos / this.valueRange || 0;
1423-
}
1424-
else {
1425-
var minLog = Math.log(this.minValue),
1426-
maxLog = Math.log(this.maxValue),
1427-
scale = (maxLog - minLog) / (this.maxPos);
1428-
return (Math.log(sanitizedValue) - minLog) / scale || 0;
1429-
}
1417+
var sanitizedValue = this.sanitizeValue(val),
1418+
minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
1419+
maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
1420+
range = maxValue - minValue;
1421+
1422+
if (this.options.logScale)
1423+
sanitizedValue = Math.log(sanitizedValue);
1424+
1425+
if (this.options.rightToLeft)
1426+
return (maxValue - sanitizedValue) * this.maxPos / range || 0;
1427+
return (sanitizedValue - minValue) * this.maxPos / range || 0;
14301428
},
14311429

14321430
/**
@@ -1446,18 +1444,16 @@
14461444
* @returns {number}
14471445
*/
14481446
offsetToValue: function(offset) {
1449-
if (!this.options.logScale) {
1450-
if (this.options.rightToLeft) {
1451-
return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue;
1452-
}
1453-
return (offset / this.maxPos) * this.valueRange + this.minValue;
1454-
}
1455-
else {
1456-
var minLog = Math.log(this.minValue),
1457-
maxLog = Math.log(this.maxValue),
1458-
scale = (maxLog - minLog) / (this.maxPos);
1459-
return Math.exp(minLog + scale * offset);
1460-
}
1447+
var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
1448+
maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
1449+
range = maxValue - minValue,
1450+
value = 0;
1451+
if (this.options.rightToLeft)
1452+
value = (1 - offset / this.maxPos) * range + minValue;
1453+
else
1454+
value = offset / this.maxPos * range + minValue;
1455+
1456+
return this.options.logScale ? Math.exp(value) : value;
14611457
},
14621458

14631459
// Events

0 commit comments

Comments
 (0)