From ae26b9a642d9f935f376ff8d211590525f51a71d Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Sun, 26 Apr 2020 12:52:57 +1000 Subject: added tests for sugar.js --- src/modules/optional/arrange.js | 14 ++++---------- src/modules/optional/sugar.js | 7 +++---- 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src/modules') diff --git a/src/modules/optional/arrange.js b/src/modules/optional/arrange.js index 7db4386..b6c03e0 100644 --- a/src/modules/optional/arrange.js +++ b/src/modules/optional/arrange.js @@ -23,16 +23,11 @@ export function prev () { // Send given element one step forward export function forward () { - var i = this.position() + 1 + var i = this.position() 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 (typeof p.isRoot === 'function' && p.isRoot()) { - p.node.appendChild(p.defs().node) - } + p.add(this.remove(), i + 1) return this } @@ -40,10 +35,9 @@ export function forward () { // Send given element one step backward export function backward () { var i = this.position() + var p = this.parent() - if (i > 0) { - this.parent().removeElement(this).add(this, i - 1) - } + p.add(this.remove(), i ? i - 1 : 0) return this } diff --git a/src/modules/optional/sugar.js b/src/modules/optional/sugar.js index 72c02ca..13806f1 100644 --- a/src/modules/optional/sugar.js +++ b/src/modules/optional/sugar.js @@ -1,4 +1,3 @@ -import { on, off } from '../core/event.js' import { registerMethods } from '../../utils/methods.js' import Color from '../../types/Color.js' import Element from '../../elements/Element.js' @@ -106,7 +105,7 @@ registerMethods('radius', { // Add x and y radius radius: function (x, y = x) { var type = (this._element || this).type - return type === 'radialGradient' || type === 'radialGradient' + return type === 'radialGradient' ? this.attr('r', new SVGNumber(x)) : this.rx(x).ry(y) } @@ -159,9 +158,9 @@ const methods = [ 'click', // add event to Element const fn = function (f) { if (f === null) { - off(this, event) + this.off(event) } else { - on(this, event, f) + this.on(event, f) } return this } -- cgit v1.2.3