diff options
author | wout <wout@impinc.co.uk> | 2014-08-30 17:06:00 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-08-30 17:06:00 +0200 |
commit | bde8508836f9cad16b462c811d124258ca35400d (patch) | |
tree | df79d62041c7afa4a40517f27ddb2a6a45568e63 /src/attr.js | |
parent | 6c1820b4c5790be1b0872a49a50d10d97a243292 (diff) | |
download | svg.js-bde8508836f9cad16b462c811d124258ca35400d.tar.gz svg.js-bde8508836f9cad16b462c811d124258ca35400d.zip |
Added animated parametric transformations
Diffstat (limited to 'src/attr.js')
-rw-r--r-- | src/attr.js | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/attr.js b/src/attr.js index d18cc90..2d57390 100644 --- a/src/attr.js +++ b/src/attr.js @@ -1,9 +1,9 @@ SVG.extend(SVG.Element, { // Set svg element attribute attr: function(a, v, n) { - // Act as full getter + // act as full getter if (a == null) { - // Get an object of attributes + // get an object of attributes a = {} v = this.node.attributes for (n = v.length - 1; n >= 0; n--) @@ -12,15 +12,15 @@ SVG.extend(SVG.Element, { return a } else if (typeof a == 'object') { - // Apply every attribute individually if an object is passed + // apply every attribute individually if an object is passed for (v in a) this.attr(v, a[v]) } else if (v === null) { - // Remove value + // remove value this.node.removeAttribute(a) } else if (v == null) { - // Act as a getter if the first and only argument is not an object + // act as a getter if the first and only argument is not an object v = this.node.getAttribute(a) return v == null ? SVG.defaults.attrs[a] : @@ -28,13 +28,13 @@ SVG.extend(SVG.Element, { parseFloat(v) : v } else { - // BUG FIX: some browsers will render a stroke if a color is given even though stroke width is 0 + // bUG FIX: some browsers will render a stroke if a color is given even though stroke width is 0 if (a == 'stroke-width') this.attr('stroke', parseFloat(v) > 0 ? this._stroke : null) else if (a == 'stroke') this._stroke = v - // Convert image fill and stroke to patterns + // convert image fill and stroke to patterns if (a == 'fill' || a == 'stroke') { if (SVG.regex.isImage.test(v)) v = this.doc().defs().image(v, 0, 0) @@ -45,31 +45,35 @@ SVG.extend(SVG.Element, { }) } - // Ensure correct numeric values (also accepts NaN and Infinity) + // ensure correct numeric values (also accepts NaN and Infinity) if (typeof v === 'number') v = new SVG.Number(v) - // Ensure full hex color + // ensure full hex color else if (SVG.Color.isColor(v)) v = new SVG.Color(v) - // Parse array values + // parse array values else if (Array.isArray(v)) v = new SVG.Array(v) - // If the passed attribute is leading... + // store parametric transformation values locally + else if (v instanceof SVG.Matrix && v.param) + this.param = v.param + + // if the passed attribute is leading... if (a == 'leading') { // ... call the leading method instead if (this.leading) this.leading(v) } else { - // Set given attribute on node + // set given attribute on node typeof n === 'string' ? this.node.setAttributeNS(n, a, v.toString()) : this.node.setAttribute(a, v.toString()) } - // Rebuild if required + // rebuild if required if (this.rebuild && (a == 'font-size' || a == 'x')) this.rebuild(a, v) } |