aboutsummaryrefslogtreecommitdiffstats
path: root/src/shape.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-17 16:55:16 +0100
committerwout <wout@impinc.co.uk>2012-12-17 16:55:16 +0100
commit6a013f19d6fa84e538d31bca5f1466c5f3479630 (patch)
tree3807acc4240bb1dbd5f25406b262a240351fa67a /src/shape.js
parent9ba8a780e0da4de4839df119f1d57d7f6327b1c6 (diff)
downloadsvg.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.js53
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