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

Commit 56d6fe6

Browse files
committed
[IMP] add updateAttributes in domHelpres
1 parent 3af4d5e commit 56d6fe6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/plugin-dom-helpers/src/DomHelpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ export class DomHelpers<T extends JWPluginConfig = JWPluginConfig> extends JWPlu
5959
}
6060
await this.editor.dispatcher.dispatchHooks('@redraw');
6161
}
62+
63+
/**
64+
* Update the attributes with the given dictionnary and clear all previous
65+
* attributes.
66+
*/
67+
async updateAttributes(
68+
domNode: Node | Node[],
69+
attributes: { [key: string]: string },
70+
): Promise<void> {
71+
for (const node of this.getNodes(domNode)) {
72+
node.modifiers.get(Attributes).clear();
73+
for (const [name, value] of Object.entries(attributes)) {
74+
node.modifiers.get(Attributes).set(name, value);
75+
}
76+
}
77+
await this.editor.dispatcher.dispatchHooks('@redraw');
78+
}
6279
/**
6380
* Set a style key/value pair on a DOM node or a list of DOM nodes.
6481
*

0 commit comments

Comments
 (0)