diff options
author | wout <wout@impinc.co.uk> | 2012-12-31 16:16:05 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-31 16:16:05 +0100 |
commit | 5e7c26e9423f3c543e04bc9a11656125ec7bf8ca (patch) | |
tree | 5e568b9a8083aa23b1bf830b7f4a42a3c8c1a1c0 /src/container.js | |
parent | 8dbe3599dd9b80738c4124f7e71bc12e763c50dc (diff) | |
download | svg.js-5e7c26e9423f3c543e04bc9a11656125ec7bf8ca.tar.gz svg.js-5e7c26e9423f3c543e04bc9a11656125ec7bf8ca.zip |
Added each(), next(), previous() and more
Diffstat (limited to 'src/container.js')
-rw-r--r-- | src/container.js | 33 |
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. |