diff options
author | wout <wout@impinc.co.uk> | 2014-03-04 22:19:01 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-03-04 22:19:01 +0100 |
commit | 1286e3de26baa3d75ec6a6eafbb2eaa11305c2e1 (patch) | |
tree | b39257a6256836b9e645f5e5faf37adcbe8d4c4d /src/number.js | |
parent | f3b9e808601e8aa250b9373447527ca67ba75ec4 (diff) | |
download | svg.js-1286e3de26baa3d75ec6a6eafbb2eaa11305c2e1.tar.gz svg.js-1286e3de26baa3d75ec6a6eafbb2eaa11305c2e1.zip |
Bumped to 1.0.0-rc.6
Diffstat (limited to 'src/number.js')
-rwxr-xr-x | src/number.js | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/number.js b/src/number.js index 697d1dc..92ff796 100755 --- a/src/number.js +++ b/src/number.js @@ -6,36 +6,34 @@ SVG.Number = function(value) { this.unit = '' /* parse value */ - switch(typeof value) { - case 'number': - /* ensure a valid numeric value */ - this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value - break - case 'string': - var match = value.match(SVG.regex.unit) + if (typeof value === 'number') { + /* ensure a valid numeric value */ + this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value - if (match) { - /* make value numeric */ - this.value = parseFloat(match[1]) + } else if (typeof value === 'string') { + var match = value.match(SVG.regex.unit) + + if (match) { + /* make value numeric */ + this.value = parseFloat(match[1]) - /* normalize percent value */ - if (match[2] == '%') - this.value /= 100 - else if (match[2] == 's') - this.value *= 1000 + /* normalize percent value */ + if (match[2] == '%') + this.value /= 100 + else if (match[2] == 's') + this.value *= 1000 - /* store unit */ - this.unit = match[2] - } - - break - default: - if (value instanceof SVG.Number) { - this.value = value.value - this.unit = value.unit - } - break + /* store unit */ + this.unit = match[2] + } + + } else { + if (value instanceof SVG.Number) { + this.value = value.value + this.unit = value.unit + } } + } SVG.extend(SVG.Number, { @@ -93,7 +91,7 @@ SVG.extend(SVG.Number, { /* make sure a destination is defined */ if (!this.destination) return this - /* generate morphed number */ + /* generate new morphed number */ return new SVG.Number(this.destination) .minus(this) .times(pos) |