diff options
author | wout <wout@impinc.co.uk> | 2012-12-31 14:43:26 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-31 14:43:26 +0100 |
commit | 8dbe3599dd9b80738c4124f7e71bc12e763c50dc (patch) | |
tree | 97b9d3a3c85ae2cabd17702b74388f219accb2ef | |
parent | f210affa28f5ad2a92a12d8ca17c7ae6083b1d98 (diff) | |
download | svg.js-8dbe3599dd9b80738c4124f7e71bc12e763c50dc.tar.gz svg.js-8dbe3599dd9b80738c4124f7e71bc12e763c50dc.zip |
Added position()
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | src/arrange.js | 13 | ||||
-rw-r--r-- | src/element.js | 7 |
3 files changed, 22 insertions, 6 deletions
@@ -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 |