aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-31 14:43:26 +0100
committerwout <wout@impinc.co.uk>2012-12-31 14:43:26 +0100
commit8dbe3599dd9b80738c4124f7e71bc12e763c50dc (patch)
tree97b9d3a3c85ae2cabd17702b74388f219accb2ef
parentf210affa28f5ad2a92a12d8ca17c7ae6083b1d98 (diff)
downloadsvg.js-8dbe3599dd9b80738c4124f7e71bc12e763c50dc.tar.gz
svg.js-8dbe3599dd9b80738c4124f7e71bc12e763c50dc.zip
Added position()
-rw-r--r--README.md8
-rw-r--r--src/arrange.js13
-rw-r--r--src/element.js7
3 files changed, 22 insertions, 6 deletions
diff --git a/README.md b/README.md
index 857bf8d..554303e 100644
--- a/README.md
+++ b/README.md
@@ -356,6 +356,14 @@ rect.forward();
rect.backward();
```
+The arrange.js module brings some additional methods:
+
+```javascript
+// returns the position (a number) of the element between its siblings
+rect.position();
+```
+
+
_This functionality requires the arrange.js module which is included in the default distribution._
diff --git a/src/arrange.js b/src/arrange.js
index ac53e43..ff255be 100644
--- a/src/arrange.js
+++ b/src/arrange.js
@@ -7,6 +7,11 @@ SVG.extend(SVG.Element, {
return this.parent.children();
},
+ // get the curent position siblings
+ position: function() {
+ return this.siblings().indexOf(this);
+ },
+
// send given element one step forwards
forward: function() {
var i = this.siblings().indexOf(this);
@@ -18,7 +23,7 @@ SVG.extend(SVG.Element, {
backward: function() {
var i, p = this.parent.level();
- i = this.siblings().indexOf(this);
+ i = this.position();
if (i > 1)
p.remove(this).add(this, i - 1);
@@ -33,11 +38,9 @@ SVG.extend(SVG.Element, {
// send given element all the way to the back
back: function() {
- var i, p = this.parent.level();
+ var p = this.parent.level();
- i = this.siblings().indexOf(this);
-
- if (i > 1)
+ if (this.position() > 1)
p.remove(this).add(this, 0);
return this;
diff --git a/src/element.js b/src/element.js
index 3f1afa3..a9cd7cd 100644
--- a/src/element.js
+++ b/src/element.js
@@ -43,6 +43,7 @@ SVG.extend(SVG.Element, {
var c,
n = this.node.nodeName;
+ // invoke shape method with shape-specific arguments
c = n == 'rect' ?
this.parent[n](this.attrs.width, this.attrs.height) :
n == 'ellipse' ?
@@ -53,7 +54,11 @@ SVG.extend(SVG.Element, {
this.parent[n](this.content) :
this.parent[n]();
- return c.attr(this.attrs);
+ // copy translations
+ c.trans = this.trans;
+
+ // apply attributes and translations
+ return c.attr(this.attrs).transform({});
},
// remove element