diff options
author | wout <wout@impinc.co.uk> | 2014-06-21 18:25:29 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-06-21 18:25:29 +0200 |
commit | 19b6fd4338246d1fd9ca4806e57c7aebcec63826 (patch) | |
tree | 3dd1d207de9f586f7e4d4cd36917e347ab022a9e /src/parent.js | |
parent | bb0e6be2da0cea98c5303871c0be055f5f70d7a9 (diff) | |
download | svg.js-19b6fd4338246d1fd9ca4806e57c7aebcec63826.tar.gz svg.js-19b6fd4338246d1fd9ca4806e57c7aebcec63826.zip |
Removed all structural references
Diffstat (limited to 'src/parent.js')
-rwxr-xr-x | src/parent.js | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/parent.js b/src/parent.js index 44514c2..55878ec 100755 --- a/src/parent.js +++ b/src/parent.js @@ -11,7 +11,9 @@ SVG.Parent = SVG.invent({ , extend: { // Returns all child elements children: function() { - return this._children || (this._children = []) + return SVG.utils.map(this.node.childNodes, function(node) { + return SVG.adopt(node) + }) } // Add given element at a position , add: function(element, i) { @@ -19,22 +21,10 @@ SVG.Parent = SVG.invent({ /* define insertion index if none given */ i = i == null ? this.children().length : i - /* remove references from previous parent */ - if (element.parent) - element.parent.children().splice(element.parent.index(element), 1) - /* add element references */ - this.children().splice(i, 0, element) this.node.insertBefore(element.node, this.node.childNodes[i] || null) - element.parent = this } - /* reposition defs */ - if (this._defs) { - this.node.removeChild(this._defs.node) - this.node.appendChild(this._defs.node) - } - return this } // Basically does the same as `add()` but returns the added element instead @@ -79,25 +69,22 @@ SVG.Parent = SVG.invent({ } // Remove a child element at a position , removeElement: function(element) { - this.children().splice(this.index(element), 1) this.node.removeChild(element.node) - element.parent = null return this } // Remove all elements in this container , clear: function() { - /* remove children */ - for (var i = this.children().length - 1; i >= 0; i--) - this.removeElement(this.children()[i]) + // Remove children + while(this.node.hasChildNodes()) + this.node.removeChild(this.node.lastChild) - /* remove defs node */ - if (this._defs) - this._defs.clear() + // Remove defs cache reference + delete this._defs return this } - , // Get defs + , // Get defs defs: function() { return this.doc().defs() } |