summaryrefslogtreecommitdiffstats
path: root/src/container.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-02-27 20:36:17 +0100
committerwout <wout@impinc.co.uk>2013-02-27 20:36:17 +0100
commite9fa07a7b33b8f19c0690b0fc3df2f57a404d224 (patch)
treefe7af0f65d7a0b4b1177a225e3ac885c62fa4bca /src/container.js
parent968406ea2f45e756f081268370703c522a929cfb (diff)
downloadsvg.js-e9fa07a7b33b8f19c0690b0fc3df2f57a404d224.tar.gz
svg.js-e9fa07a7b33b8f19c0690b0fc3df2f57a404d224.zip
Bumped to v0.7 with reworked id sequence, attr nullifier, and various other fixes
Diffstat (limited to 'src/container.js')
-rw-r--r--src/container.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/container.js b/src/container.js
index a78d93f..fd41a96 100644
--- a/src/container.js
+++ b/src/container.js
@@ -10,7 +10,16 @@ SVG.extend(SVG.Container, {
// Add given element at a position
add: function(element, index) {
if (!this.has(element)) {
+ /* define insertion index if none given */
index = index == null ? this.children().length : index
+
+ /* remove references from previous parent */
+ if (element.parent) {
+ var i = element.parent.children().indexOf(element)
+ element.parent.children().splice(i, 1)
+ }
+
+ /* add element references */
this.children().splice(index, 0, element)
this.node.insertBefore(element.node, this.node.childNodes[index] || null)
element.parent = this
@@ -42,18 +51,13 @@ SVG.extend(SVG.Container, {
return this
}
- // Remove a given child element
+ // Remove a child element at a position
, remove: function(element) {
- return this.removeAt(this.children().indexOf(element))
- }
- // Remove a child element at a given position
-, removeAt: function(index) {
- if (0 <= index && index < this.children().length) {
- var element = this.children()[index]
- this.children().splice(index, 1)
- this.node.removeChild(element.node)
- element.parent = null
- }
+ var index = this.children().indexOf(element)
+
+ this.children().splice(index, 1)
+ this.node.removeChild(element.node)
+ element.parent = null
return this
}