From f2b27b88f65ba73961b931ea93d98b2ba88d7977 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulrich-Matthias=20Sch=C3=A4fer?= Date: Thu, 1 Mar 2018 23:55:53 +0100 Subject: [PATCH] make ungroup working on groups and nested for one depths --- src/flatten.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/flatten.js b/src/flatten.js index 3ba6e22..19eebd7 100644 --- a/src/flatten.js +++ b/src/flatten.js @@ -1,6 +1,9 @@ SVG.extend(SVG.Parent, { flatten: function (parent) { - if (this instanceof SVG.Defs) return this + // flattens is only possible for nested svgs and groups + if (!(this instanceof SVG.G || this instanceof SVG.Doc)) { + return this + } parent = parent || (this instanceof SVG.Doc && this.isRoot() ? this : this.parent(SVG.Parent)) @@ -13,6 +16,23 @@ SVG.extend(SVG.Parent, { // we need this so that SVG.Doc does not get removed this.node.firstElementChild || this.remove() + return this + }, + ungroup: function (parent) { + // ungroup is only possible for nested svgs and groups + if (!(this instanceof SVG.G || (this instanceof SVG.Doc && !this.isRoot()))) { + return this + } + + parent = parent || this.parent(SVG.Parent) + + this.each(function () { + return this.toParent(parent) + }) + + // we need this so that SVG.Doc does not get removed + this.remove() + return this } }) -- 2.39.5