aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-19 13:44:52 +0100
committerwout <wout@impinc.co.uk>2012-12-19 13:44:52 +0100
commitdfa324f1cb9c562a198ad2f9909bbb8d44807936 (patch)
treefe84b03e7e7b60c1eb965244defc4bc86e41b222 /README.md
parentdab421143cf719370cb3739d07e3e411d555cf3c (diff)
downloadsvg.js-dfa324f1cb9c562a198ad2f9909bbb8d44807936.tar.gz
svg.js-dfa324f1cb9c562a198ad2f9909bbb8d44807936.zip
Updated readme
Diffstat (limited to 'README.md')
-rw-r--r--README.md44
1 files changed, 44 insertions, 0 deletions
diff --git a/README.md b/README.md
index 0558792..9b2a528 100644
--- a/README.md
+++ b/README.md
@@ -214,6 +214,50 @@ group.add(rect);
_This functionality requires the group.js module which is included in the default distribution._
+## Extending functionality
+Svg.js has a modular structure. It is very easy to add you own methods at different levels. Let's say we want to add a method to all shape types then we would add our method to SVG.Shape:
+```javascript
+SVG.extend(SVG.Shape, {
+
+ paintRed: function() {
+ return this.fill({ color: 'red' });
+ }
+
+});
+```
+Now all shapes will have the paintRed method available. Say we want to have the paintRed method on a circle apply a slightly different color:
+```javascript
+SVG.extend(SVG.Circle, {
+
+ paintRed: function() {
+ return this.fill({ color: 'orangered' });
+ }
+
+});
+```
+The complete inheritance stack for 'SVG.Circle' is:
+
+_SVG.Circle < SVG.Shape < SVG.Element_
+
+The SVG document can be extended by using:
+
+```javascript
+SVG.extend(SVG.Doc, {
+
+ paintAllPink: function() {
+ var children = this.children();
+
+ for (var i = 0, l = children.length; i < l; i++) {
+ this.fill({ color: 'pink' });
+ };
+
+ return this;
+ }
+
+});
+```
+
+
## Compatibility
### Desktop