diff options
Diffstat (limited to 'src/shared/modify-dom.ts')
| -rw-r--r-- | src/shared/modify-dom.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/shared/modify-dom.ts b/src/shared/modify-dom.ts index 22b8e8e..b268ae2 100644 --- a/src/shared/modify-dom.ts +++ b/src/shared/modify-dom.ts @@ -10,6 +10,11 @@ type DOMModificationRules = (DOMModificaitonRule | null)[]; let domModificationRules: DOMModificationRules = []; let domModificationFinishedCount = 0; +/** + * Runs whenever the DOM mutates. Iterates over pending modification + * rules; when the selector matches, the element's innerHTML and + * attributes are updated and the rule is marked as complete. + */ observeDOM(() => { for (let i = 0; i < domModificationRules.length; i++) { if (domModificationRules[i]) { @@ -45,6 +50,15 @@ observeDOM(() => { return false; }); +/** + * Registers one or more DOM modification rules. Each rule is a tuple of + * `[selector, attributeMap]`. When an element matching the selector is + * found, its `innerHTML` is replaced (if `attributeMap.innerHTML` is set) + * and all other entries in the map are applied as `setAttribute` calls + * (or `removeAttribute` when the value is `null`). + * + * @param modificationRules - Array of `[selector, attributes]` rules. + */ export function modifyDOM(modificationRules: DOMModificationRules) { domModificationRules = domModificationRules.concat(modificationRules); }; |
