diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2016-01-23 00:24:57 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2016-01-23 00:24:57 +0100 |
commit | 0858bca9eb30a7544bd1f381d940ade494f43e13 (patch) | |
tree | fb675904974e9ac2b3285b0980d0b86bd20c7dd9 /src/number.js | |
parent | d17bab6bcccc8319b8b4c96db0def8926e93152d (diff) | |
download | svg.js-0858bca9eb30a7544bd1f381d940ade494f43e13.tar.gz svg.js-0858bca9eb30a7544bd1f381d940ade494f43e13.zip |
fixed unit unit regex and renamed it to numberAndUnit, added specs (fix #443)
Diffstat (limited to 'src/number.js')
-rw-r--r-- | src/number.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/number.js b/src/number.js index f0c53e0..8eb7a1c 100644 --- a/src/number.js +++ b/src/number.js @@ -12,20 +12,20 @@ SVG.Number = SVG.invent({ this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value } else if (typeof value === 'string') { - unit = value.match(SVG.regex.unit) + unit = value.match(SVG.regex.numberAndUnit) if (unit) { // make value numeric this.value = parseFloat(unit[1]) - + // normalize - if (unit[2] == '%') + if (unit[5] == '%') this.value /= 100 - else if (unit[2] == 's') + else if (unit[5] == 's') this.value *= 1000 - + // store unit - this.unit = unit[2] + this.unit = unit[5] } } else { @@ -74,7 +74,7 @@ SVG.Number = SVG.invent({ // Convert to different unit , to: function(unit) { var number = new SVG.Number(this) - + if (typeof unit === 'string') number.unit = unit |