summaryrefslogtreecommitdiffstats
path: root/src/arrange.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-18 19:54:12 +0100
committerwout <wout@impinc.co.uk>2012-12-18 19:54:12 +0100
commit1293edb66a5263f8f7064f16f11cbf6b8f550800 (patch)
treea336fb50db98d52ec8151b494bfa7762128c170e /src/arrange.js
parentecc7c2b21cc484a0a57cd7df02a533c65f7bde97 (diff)
downloadsvg.js-1293edb66a5263f8f7064f16f11cbf6b8f550800.tar.gz
svg.js-1293edb66a5263f8f7064f16f11cbf6b8f550800.zip
Separated core from optional libraries
Diffstat (limited to 'src/arrange.js')
-rw-r--r--src/arrange.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/arrange.js b/src/arrange.js
new file mode 100644
index 0000000..d7fcb5f
--- /dev/null
+++ b/src/arrange.js
@@ -0,0 +1,53 @@
+
+// add backward / forward functionality to elements
+SVG.extend(SVG.Element, {
+
+ // get all siblings, including me
+ siblings: function() {
+ return this.mother().children();
+ },
+
+ // send given element one step forwards
+ forward: function() {
+ var i = this.siblings().indexOf(this);
+ this.mother().remove(this).add(this, i + 1);
+
+ return this;
+ },
+
+ // send given element one step backwards
+ backward: function() {
+ var i, p = this.mother();
+
+ p.levelDefs();
+
+ i = this.siblings().indexOf(this);
+
+ if (i > 1)
+ p.remove(this).add(this, i - 1);
+
+ return this;
+ },
+
+ // send given element all the way to the front
+ front: function() {
+ this.mother().remove(this).add(this);
+
+ return this;
+ },
+
+ // send given element all the way to the back
+ back: function() {
+ var i, p = this.mother();
+
+ p.levelDefs();
+
+ i = this.siblings().indexOf(this);
+
+ if (i > 1)
+ p.remove(this).add(this, 0);
+
+ return this;
+ }
+
+}); \ No newline at end of file