diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-25 23:28:12 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-25 23:28:12 +0200 |
commit | cfdfcc529dedff770dc54e78d2900d9a790f5766 (patch) | |
tree | 7b59c282a7823ded1d182aca95da5d55815456b2 /src/arrange.js | |
parent | 464af8b747389b7fdb569a933591c863b9be0f6b (diff) | |
download | svg.js-cfdfcc529dedff770dc54e78d2900d9a790f5766.tar.gz svg.js-cfdfcc529dedff770dc54e78d2900d9a790f5766.zip |
convert everything to es6 classes and imports
Diffstat (limited to 'src/arrange.js')
-rw-r--r-- | src/arrange.js | 153 |
1 files changed, 76 insertions, 77 deletions
diff --git a/src/arrange.js b/src/arrange.js index a908143..b6d5e26 100644 --- a/src/arrange.js +++ b/src/arrange.js @@ -1,97 +1,96 @@ -// ### This module adds backward / forward functionality to elements. - -// -SVG.extend(SVG.Element, { - // Get all siblings, including myself - siblings: function () { - return this.parent().children() - }, - - // Get the curent position siblings - position: function () { - return this.parent().index(this) - }, - - // Get the next element (will return null if there is none) - next: function () { - return this.siblings()[this.position() + 1] - }, - - // Get the next element (will return null if there is none) - prev: function () { - return this.siblings()[this.position() - 1] - }, - - // Send given element one step forward - forward: function () { - var i = this.position() + 1 - var p = this.parent() +import Doc from './Doc.js' - // move node one step forward - p.removeElement(this).add(this, i) +// ### This module adds backward / forward functionality to elements. - // make sure defs node is always at the top - if (p instanceof SVG.Doc) { - p.node.appendChild(p.defs().node) - } +// Get all siblings, including myself +export function siblings () { + return this.parent().children() +} + +// Get the curent position siblings +export function position () { + return this.parent().index(this) +} + +// Get the next element (will return null if there is none) +export function next () { + return this.siblings()[this.position() + 1] +} + +// Get the next element (will return null if there is none) +export function prev () { + return this.siblings()[this.position() - 1] +} + +// Send given element one step forward +export function forward () { + var i = this.position() + 1 + var 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 Doc) { + p.node.appendChild(p.defs().node) + } - return this - }, + return this +} - // Send given element one step backward - backward: function () { - var i = this.position() +// Send given element one step backward +export function backward () { + var i = this.position() - if (i > 0) { - this.parent().removeElement(this).add(this, i - 1) - } + if (i > 0) { + this.parent().removeElement(this).add(this, i - 1) + } - return this - }, + return this +} - // Send given element all the way to the front - front: function () { - var p = this.parent() +// Send given element all the way to the front +export function front () { + var p = this.parent() - // Move node forward - p.node.appendChild(this.node) + // 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) - } + // Make sure defs node is always at the top + if (p instanceof Doc) { + p.node.appendChild(p.defs().node) + } - return this - }, + return this +} - // Send given element all the way to the back - back: function () { - if (this.position() > 0) { - this.parent().removeElement(this).add(this, 0) - } +// Send given element all the way to the back +export function back () { + if (this.position() > 0) { + this.parent().removeElement(this).add(this, 0) + } - return this - }, + return this +} - // Inserts a given element before the targeted element - before: function (element) { - element.remove() +// Inserts a given element before the targeted element +export function before (element) { + element.remove() - var i = this.position() + var i = this.position() - this.parent().add(element, i) + this.parent().add(element, i) - return this - }, + return this +} - // Insters a given element after the targeted element - after: function (element) { - element.remove() +// Inserts a given element after the targeted element +export function after (element) { + element.remove() - var i = this.position() + var i = this.position() - this.parent().add(element, i + 1) + this.parent().add(element, i + 1) - return this - } -}) + return this +} |