diff options
author | wout <wout@impinc.co.uk> | 2014-02-01 14:27:31 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-01 14:27:31 +0100 |
commit | f047e3c3aad7920df978a2dbc758a961112c9d43 (patch) | |
tree | d97689f6563aebd823d1190cc76809073da3a449 /src/parent.js | |
parent | 745a0148c9de8c14367507eb21355604a42e84d5 (diff) | |
download | svg.js-f047e3c3aad7920df978a2dbc758a961112c9d43.tar.gz svg.js-f047e3c3aad7920df978a2dbc758a961112c9d43.zip |
Added index() method to SVG.Parent and SVG.Set
Diffstat (limited to 'src/parent.js')
-rwxr-xr-x | src/parent.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/parent.js b/src/parent.js index 8b11f5f..4436d72 100755 --- a/src/parent.js +++ b/src/parent.js @@ -18,10 +18,8 @@ SVG.extend(SVG.Parent, { i = i == null ? this.children().length : i /* remove references from previous parent */ - if (element.parent) { - var index = element.parent.children().indexOf(element) - element.parent.children().splice(index, 1) - } + if (element.parent) + element.parent.children().splice(element.parent.index(element), 1) /* add element references */ this.children().splice(i, 0, element) @@ -44,7 +42,11 @@ SVG.extend(SVG.Parent, { } // Checks if the given element is a child , has: function(element) { - return this.children().indexOf(element) >= 0 + return this.index(element) >= 0 + } + // Gets index of given element +, index: function(element) { + return this.children().indexOf(element) } // Get a element at the given index , get: function(i) { @@ -75,9 +77,7 @@ SVG.extend(SVG.Parent, { } // Remove a child element at a position , removeElement: function(element) { - var i = this.children().indexOf(element) - - this.children().splice(i, 1) + this.children().splice(this.index(element), 1) this.node.removeChild(element.node) element.parent = null |