diff options
author | wout <wout@impinc.co.uk> | 2012-12-18 19:54:12 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-18 19:54:12 +0100 |
commit | 1293edb66a5263f8f7064f16f11cbf6b8f550800 (patch) | |
tree | a336fb50db98d52ec8151b494bfa7762128c170e /src/container.js | |
parent | ecc7c2b21cc484a0a57cd7df02a533c65f7bde97 (diff) | |
download | svg.js-1293edb66a5263f8f7064f16f11cbf6b8f550800.tar.gz svg.js-1293edb66a5263f8f7064f16f11cbf6b8f550800.zip |
Separated core from optional libraries
Diffstat (limited to 'src/container.js')
-rw-r--r-- | src/container.js | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/src/container.js b/src/container.js index 9d8b5af..46e8200 100644 --- a/src/container.js +++ b/src/container.js @@ -1,53 +1,23 @@ SVG.Container = { - add: function(e) { - return this.addAt(e); - }, - - addAt: function(e, i) { - if (!this.contains(e)) { + add: function(e, i) { + if (!this.has(e)) { i = i == null ? this.children().length : i; this.children().splice(i, 0, e); - this.node.insertBefore(e.node, this.node.childNodes[i + 1]); + this.node.insertBefore(e.node, this.node.childNodes[i]); e.parent = this; } return this; }, - contains: function(e) { + has: function(e) { return Array.prototype.indexOf.call(this.children(), e) >= 0; }, children: function() { - return this._children || []; - }, - - sendBack: function(e) { - var i = this.children().indexOf(e); - if (i !== -1) - return this.remove(e).addAt(e, i - 1); - }, - - bringForward: function(e) { - var i = this.children().indexOf(e); - if (i !== -1) - return this.remove(e).addAt(e, i + 1); - }, - - bringToFront: function(e) { - if (this.contains(e)) - this.remove(e).add(e); - - return this; - }, - - sendToBottom: function(e) { - if (this.contains(e)) - this.remove(e).addAt(e, 0); - - return this; + return this._children || (this._children = []); }, remove: function(e) { @@ -68,12 +38,20 @@ SVG.Container = { defs: function() { if (this._defs == null) { this._defs = new SVG.Defs(); - this.add(this._defs); + this.add(this._defs, 0); } return this._defs; }, + levelDefs: function() { + var d = this.defs(); + + this.remove(d).add(d, 0); + + return this; + }, + group: function() { var e = new SVG.G(); this.add(e); |