summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2016-01-23 00:24:57 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2016-01-23 00:24:57 +0100
commit0858bca9eb30a7544bd1f381d940ade494f43e13 (patch)
treefb675904974e9ac2b3285b0980d0b86bd20c7dd9 /src
parentd17bab6bcccc8319b8b4c96db0def8926e93152d (diff)
downloadsvg.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')
-rw-r--r--src/fx.js2
-rw-r--r--src/number.js14
-rw-r--r--src/regex.js2
3 files changed, 9 insertions, 9 deletions
diff --git a/src/fx.js b/src/fx.js
index 4ed85a2..758ce50 100644
--- a/src/fx.js
+++ b/src/fx.js
@@ -246,7 +246,7 @@ SVG.FX = SVG.invent({
this.attrs[a] = SVG.Color.isColor(v) ?
// prepare color for morphing
new SVG.Color(from).morph(v) :
- SVG.regex.unit.test(v) ?
+ SVG.regex.numberAndUnit.test(v) ?
// prepare number for morphing
new SVG.Number(from).morph(v) :
// prepare for plain morphing
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
diff --git a/src/regex.js b/src/regex.js
index d2e6c78..265a11a 100644
--- a/src/regex.js
+++ b/src/regex.js
@@ -1,7 +1,7 @@
// Storage for regular expressions
SVG.regex = {
// Parse unit value
- unit: /^(-?[\d\.]+)([a-z%]{0,2})$/
+ numberAndUnit: /^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i
// Parse hex value
, hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i