diff options
author | Saivan <savian@me.com> | 2018-03-02 12:48:54 +1100 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-03-02 12:48:54 +1100 |
commit | 1cba40f6a039d8ff0b87043b5cb9e1f28b3655ee (patch) | |
tree | 6bab575b25fef489aea8998686a638eb9abc4fa4 | |
parent | a208ed5c5de4b654efc54c2bcbe8dc7d4875392d (diff) | |
parent | 0b2cb052313e26c5626cdba3e58dea915f0aa444 (diff) | |
download | svg.js-1cba40f6a039d8ff0b87043b5cb9e1f28b3655ee.tar.gz svg.js-1cba40f6a039d8ff0b87043b5cb9e1f28b3655ee.zip |
Merge branch '3.0.0' of github.com:svgdotjs/svg.js into 786-new-transformations
-rw-r--r-- | src/flatten.js | 22 |
1 files changed, 21 insertions, 1 deletions
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)) @@ -14,5 +17,22 @@ SVG.extend(SVG.Parent, { 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 } }) |