diff options
author | wout <wout@impinc.co.uk> | 2012-12-17 16:55:16 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-17 16:55:16 +0100 |
commit | 6a013f19d6fa84e538d31bca5f1466c5f3479630 (patch) | |
tree | 3807acc4240bb1dbd5f25406b262a240351fa67a /src/shape.js | |
parent | 9ba8a780e0da4de4839df119f1d57d7f6327b1c6 (diff) | |
download | svg.js-6a013f19d6fa84e538d31bca5f1466c5f3479630.tar.gz svg.js-6a013f19d6fa84e538d31bca5f1466c5f3479630.zip |
Refactored code for readability and size
Diffstat (limited to 'src/shape.js')
-rw-r--r-- | src/shape.js | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/shape.js b/src/shape.js index 194ff84..a57b9f2 100644 --- a/src/shape.js +++ b/src/shape.js @@ -6,30 +6,35 @@ SVG.Shape = function Shape(element) { // inherit from SVG.Element SVG.Shape.prototype = new SVG.Element(); -// set fill color and opacity -SVG.Shape.prototype.fill = function(fill) { - if (fill.color != null) - this.setAttribute('fill', fill.color); +// Add shape-specific functions +SVG.Utils.merge(SVG.Shape, { - if (fill.opacity != null) - this.setAttribute('fill-opacity', fill.opacity); - - return this; -}; + // set fill color and opacity + fill: function(fill) { + if (fill.color != null) + this.attr('fill', fill.color); -// set stroke color and opacity -SVG.Shape.prototype.stroke = function(stroke) { - if (stroke.color != null) - this.setAttribute('stroke', stroke.color); - - if (stroke.width != null) - this.setAttribute('stroke-width', stroke.width); - - if (stroke.opacity != null) - this.setAttribute('stroke-opacity', stroke.opacity); - - if (this.attributes['fill-opacity'] == null) - this.fill({ opacity: 0 }); + if (fill.opacity != null) + this.attr('fill-opacity', fill.opacity); + + return this; + }, + + // set stroke color and opacity + stroke: function(stroke) { + if (stroke.color != null) + this.attr('stroke', stroke.color); + + if (stroke.width != null) + this.attr('stroke-width', stroke.width); + + if (stroke.opacity != null) + this.attr('stroke-opacity', stroke.opacity); + + if (this.attrs['fill-opacity'] == null) + this.fill({ opacity: 0 }); + + return this; + } - return this; -};
\ No newline at end of file +});
\ No newline at end of file |