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 743fe86
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(fromDomNode: Node, toDomNode: Node): Promise<void> {
const toNodes = this.getNodes(toDomNode);
const toNode = toNodes[toNodes.length - 1];
for (const fromNode of this.getNodes(fromDomNode).reverse()) {
fromNode.prepend(toNode);
}
await this.editor.dispatcher.dispatchHooks('@redraw');
}
/**
* Append a DOM Node to another DOM Node's children.
*
* @param params
*/
async append(fromDomNode: Node, toDomNode: Node): Promise<void> {
const toNodes = this.getNodes(toDomNode);
const toNode = toNodes[toNodes.length - 1];
for (const fromNode of this.getNodes(fromDomNode)) {
fromNode.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 743fe86

Please sign in to comment.