summaryrefslogtreecommitdiffstats
path: root/src/elements/Container.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/elements/Container.js')
-rw-r--r--src/elements/Container.js24
1 files changed, 11 insertions, 13 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()
}
}