diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-09 11:01:56 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-09 11:01:56 +1000 |
commit | 6a57b8cd9da1d0abc77b6ba4a2ce3d15fe675048 (patch) | |
tree | 106388badb426ae6b5f079de80440fe69e7dcbef /src/elements | |
parent | 36b65881bd090e105d19952d10b3681313daf2af (diff) | |
download | svg.js-6a57b8cd9da1d0abc77b6ba4a2ce3d15fe675048.tar.gz svg.js-6a57b8cd9da1d0abc77b6ba4a2ce3d15fe675048.zip |
fixes and tests
- fixed flatten and ungroup
- added position argument to ungroup, toParent and toRoot
- added tests for Container
Diffstat (limited to 'src/elements')
-rw-r--r-- | src/elements/Container.js | 24 | ||||
-rw-r--r-- | src/elements/Svg.js | 2 |
2 files changed, 11 insertions, 15 deletions
diff --git a/src/elements/Container.js b/src/elements/Container.js index ebaba50..9278435 100644 --- a/src/elements/Container.js +++ b/src/elements/Container.js @@ -2,28 +2,26 @@ import { register } from '../utils/adopter.js' import Element from './Element.js' export default class Container extends Element { - flatten (parent) { + flatten (parent = this, index) { this.each(function () { - if (this instanceof Container) return this.flatten(parent).ungroup(parent) - return this.toParent(parent) + if (this instanceof Container) { + return this.flatten().ungroup() + } }) - // we need this so that the root does not get removed - this.node.firstElementChild || this.remove() - return this } - ungroup (parent) { - parent = parent || this.parent() + ungroup (parent = this.parent(), index = parent.index(this)) { + // when parent != this, we want append all elements to the end + index = index === -1 ? parent.children().length : index - this.each(function () { - return this.toParent(parent) + this.each(function (i, children) { + // reverse each + return children[children.length - i - 1].toParent(parent, index) }) - this.remove() - - return this + return this.remove() } } diff --git a/src/elements/Svg.js b/src/elements/Svg.js index 8699327..51f4202 100644 --- a/src/elements/Svg.js +++ b/src/elements/Svg.js @@ -25,10 +25,8 @@ export default class Svg extends Container { } isRoot () { - return !this.node.parentNode || (!(this.node.parentNode instanceof globals.window.SVGElement) && this.node.parentNode.nodeName !== '#document-fragment') - // || this.node.parentNode.nodeName === '#document' } // Add namespaces |