aboutsummaryrefslogtreecommitdiffstats
path: root/src/container.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/container.js')
-rw-r--r--src/container.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/container.js b/src/container.js
index 6482450..3656892 100644
--- a/src/container.js
+++ b/src/container.js
@@ -30,6 +30,19 @@ SVG.Container = {
return this._children || (this._children = []);
},
+ // iterates over all children
+ each: function(b) {
+ var i,
+ c = this.children();
+
+ // iteralte all shapes
+ for (i = 1, l = c.length; i < l; i++)
+ if (c[i] instanceof SVG.Shape)
+ b.apply(c[i], [i, c]);
+
+ return this;
+ },
+
// remove a given child element
remove: function(e) {
return this.removeAt(this.children().indexOf(e));
@@ -108,6 +121,26 @@ SVG.Container = {
return this.defs().gradient(t, b);
},
+ // get first child, skipping the defs node
+ first: function() {
+ return this.children()[1];
+ },
+
+ // let the last child
+ last: function() {
+ return this.children()[this.children().length - 1];
+ },
+
+ // clears all elements of this container
+ clear: function() {
+ this._children = [];
+
+ while (this.node.hasChildNodes())
+ this.node.removeChild(this.node.lastChild);
+
+ return this;
+ },
+
// hack for safari preventing text to be rendered in one line,
// basically it sets the position of the svg node to absolute
// when the dom is loaded, and resets it to relative a few ms later.