From 0bb294ad9189797014b1e1bf55e41ca4b1ead19e Mon Sep 17 00:00:00 2001 From: wout Date: Sat, 21 Jun 2014 21:19:06 +0200 Subject: Back on track with the specs --- src/arrange.js | 24 +++++++++++++++++++++--- src/parent.js | 5 ++--- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/arrange.js b/src/arrange.js index 5c4e878..b6721b4 100755 --- a/src/arrange.js +++ b/src/arrange.js @@ -20,8 +20,17 @@ SVG.extend(SVG.Element, { } // Send given element one step forward , forward: function() { - var i = this.position() - return this.parent().removeElement(this).put(this, i + 1) + var i = this.position() + 1 + , p = this.parent() + + // Move node one step forward + p.removeElement(this).add(this, i) + + // Make sure defs node is always at the top + if (p instanceof SVG.Doc) + p.node.appendChild(p.defs().node) + + return this } // Send given element one step backward , backward: function() { @@ -34,7 +43,16 @@ SVG.extend(SVG.Element, { } // Send given element all the way to the front , front: function() { - return this.parent().removeElement(this).put(this) + var p = this.parent() + + // Move node forward + p.node.appendChild(this.node) + + // Make sure defs node is always at the top + if (p instanceof SVG.Doc) + p.node.appendChild(p.defs().node) + + return this } // Send given element all the way to the back , back: function() { diff --git a/src/parent.js b/src/parent.js index 095120a..bde35da 100755 --- a/src/parent.js +++ b/src/parent.js @@ -79,9 +79,8 @@ SVG.Parent = SVG.invent({ while(this.node.hasChildNodes()) this.node.removeChild(this.node.lastChild) - // Ensure new defs node - if (this instanceof SVG.Doc) - this.defs() + // Remove defs reference + delete this._defs return this } -- cgit v1.2.3