Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
[IMP] DomHelpers: add append and prepend in domHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Goaman committed Jun 26, 2020
1 parent a218fbe commit 3d22437
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/plugin-dom-helpers/src/DomHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,32 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
}
await this.editor.dispatcher.dispatchHooks('@redraw');
}
/**
* Prepend a DOM Node to another DOM Node's children.
*
* @param params
*/
async prepend(container: Node, node: Node): Promise<void> {
const toNodes = this.getNodes(node);
const toNode = toNodes[toNodes.length - 1];
for (const vnode of this.getNodes(container).reverse()) {
vnode.prepend(toNode);
}
await this.editor.dispatcher.dispatchHooks('@redraw');
}
/**
* Append a DOM Node to another DOM Node's children.
*
* @param params
*/
async append(container: Node, node: Node): Promise<void> {
const toNodes = this.getNodes(node);
const toNode = toNodes[toNodes.length - 1];
for (const vnode of this.getNodes(container)) {
vnode.append(toNode);
}
await this.editor.dispatcher.dispatchHooks('@redraw');
}
/**
* Insert html content before, after or inside a DOM Node. If no DOM Node
* was provided, empty the range and insert the html content before the it.
Expand Down

0 comments on commit 3d22437

Please sign in to comment.