aboutsummaryrefslogtreecommitdiffstats
path: root/src/container.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-29 18:12:53 +0100
committerwout <wout@impinc.co.uk>2012-12-29 18:12:53 +0100
commit68367e494fcab754ae4833e64804a824032cf31c (patch)
treec9d5d9fe5995ccbbe819f29752c1133c7415882d /src/container.js
parent52ed3ba98715ed3c63e74ff29a9892972a7bec19 (diff)
downloadsvg.js-68367e494fcab754ae4833e64804a824032cf31c.tar.gz
svg.js-68367e494fcab754ae4833e64804a824032cf31c.zip
Code refactoring
Diffstat (limited to 'src/container.js')
-rw-r--r--src/container.js30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/container.js b/src/container.js
index f436d4d..6482450 100644
--- a/src/container.js
+++ b/src/container.js
@@ -1,6 +1,8 @@
+// methods for container elements like SVG.Doc, SVG.Group, SVG.Defs, ...
SVG.Container = {
+ // add given element at goven position
add: function(e, i) {
if (!this.has(e)) {
i = i == null ? this.children().length : i;
@@ -12,23 +14,28 @@ SVG.Container = {
return this;
},
+ // basically does the same as add() but returns the added element rather than 'this'
put: function(e, i) {
this.add(e, i);
return e;
},
+ // chacks if the given element is a child
has: function(e) {
return this.children().indexOf(e) >= 0;
},
+ // returns all child elements and initializes store array if non existant
children: function() {
return this._children || (this._children = []);
},
+ // remove a given child element
remove: function(e) {
return this.removeAt(this.children().indexOf(e));
},
+ // remove child element at a given position
removeAt: function(i) {
if (0 <= i && i < this.children().length) {
var e = this.children()[i];
@@ -40,58 +47,63 @@ SVG.Container = {
return this;
},
+ // returns defs element and initializes store array if non existant
defs: function() {
- if (this._defs == null) {
- this._defs = new SVG.Defs();
- this.add(this._defs, 0);
- }
-
- return this._defs;
+ return this._defs || (this._defs = this.put(new SVG.Defs(), 0));
},
+ // re-level defs to first positon in element stack
level: function() {
- var d = this.defs();
-
- return this.remove(d).add(d, 0);
+ return this.remove(d).put(this.defs(), 0);
},
+ // create a group element
group: function() {
return this.put(new SVG.G());
},
+ // create a rect element
rect: function(w, h) {
return this.put(new SVG.Rect().size(w, h));
},
+ // create circle element, based on ellipse
circle: function(d) {
return this.ellipse(d);
},
+ // create and ellipse
ellipse: function(w, h) {
return this.put(new SVG.Ellipse().size(w, h));
},
+ // create a polyline element
polyline: function(p) {
return this.put(new SVG.Polyline().plot(p));
},
+ // create a polygon element
polygon: function(p) {
return this.put(new SVG.Polygon().plot(p));
},
+ // create a path element
path: function(d) {
return this.put(new SVG.Path().plot(d));
},
+ // create image element, load image and set its size
image: function(s, w, h) {
w = w != null ? w : 100;
return this.put(new SVG.Image().load(s).size(w, h != null ? h : w));
},
+ // create text element
text: function(t) {
return this.put(new SVG.Text().text(t));
},
+ // create element in defs
gradient: function(t, b) {
return this.defs().gradient(t, b);
},