Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update morph example #3

Merged
merged 5 commits into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ If you want to reprocess the element you will need to remove the property entire
```js
elt.removeEventListener(elt.__fixi.evt, elt.__fixi)
delete elt.__fixi
elt.dispatchEvent(new CustomEvent("fx:process"), {bubble:true})
elt.dispatchEvent(new CustomEvent("fx:process"), {bubbles:true})
```

You can also use this property to store extension-related information. See the [polling example](#polling) below.
Expand Down Expand Up @@ -902,9 +902,17 @@ You can implement a custom swap strategies using the [`fx:config`](#fxconfig) ev
in `fx-swap`:

```js
document.addEventListener("fx:config", (evt) => {
if (evt.detail.cfg.swap == 'morph') evt.detail.cfg.swap = (cfg)=>Idiomorph.morph(cfg.target, cfg.text, { morphStyle: "outerHTML" })
if (evt.detail.cfg.swap == 'innerMorph') evt.detail.cfg.swap = (cfg)=>Idiomorph.morph(cfg.target, cfg.text, { morphStyle: "innerHTML" })
document.addEventListener("fx:config", (evt) => {
function morph(cfg, style) {
Idiomorph.morph(cfg.target, cfg.text, { morphStyle: style }).forEach((n) => {
// process nodes as morphing existing nodes will not trigger fixi MutationObserver
n.dispatchEvent(new CustomEvent("fx:process", { bubbles: true }));
});
}
if (evt.detail.cfg.swap == "morph")
evt.detail.cfg.swap = (cfg) => morph(cfg, "outerHTML");
if (evt.detail.cfg.swap == "innerMorph")
evt.detail.cfg.swap = (cfg) => morph(cfg, "innerHTML");
});
```
```html
Expand Down