aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/arrange.js4
-rwxr-xr-xsrc/parent.js16
-rwxr-xr-xsrc/set.js8
3 files changed, 15 insertions, 13 deletions
diff --git a/src/arrange.js b/src/arrange.js
index 0eb2830..a48ec5d 100755
--- a/src/arrange.js
+++ b/src/arrange.js
@@ -8,9 +8,7 @@ SVG.extend(SVG.Element, {
}
// Get the curent position siblings
, position: function() {
- var siblings = this.siblings()
-
- return siblings.indexOf(this)
+ return this.parent.index(this)
}
// Get the next element (will return null if there is none)
, next: function() {
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
diff --git a/src/set.js b/src/set.js
index 3808a91..9a6addc 100755
--- a/src/set.js
+++ b/src/set.js
@@ -22,7 +22,7 @@ SVG.extend(SVG.Set, {
}
// Remove element from set
, remove: function(element) {
- var i = this.members.indexOf(element)
+ var i = this.index(element)
/* remove given child */
if (i > -1)
@@ -46,7 +46,11 @@ SVG.extend(SVG.Set, {
}
// Checks if a given element is present in set
, has: function(element) {
- return this.members.indexOf(element) >= 0
+ return this.index(element) >= 0
+ }
+ // retuns index of given element in set
+, index: function(element) {
+ return this.members.indexOf(element)
}
// Get member at given index
, get: function(i) {