forked from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: in-context editable blocks (#5)
* feat: support in-context authoring for blocks * fix: preserve rte instrumentation * fix: decorate richtext after decorating blocks on reload * fix: move editor-support-rte.js scripts to boilerplate * chore: short hand for moving instrumentation * fix: remove moved attribute
- Loading branch information
Showing
5 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { createOptimizedPicture } from '../../scripts/aem.js'; | ||
import { moveInstrumentation } from '../../scripts/scripts.js'; | ||
|
||
export default function decorate(block) { | ||
/* change to ul, li */ | ||
const ul = document.createElement('ul'); | ||
[...block.children].forEach((row) => { | ||
const li = document.createElement('li'); | ||
[...row.attributes].forEach(({ nodeName, nodeValue }) => { | ||
li.setAttribute(nodeName, nodeValue); | ||
}); | ||
moveInstrumentation(row, li); | ||
while (row.firstElementChild) li.append(row.firstElementChild); | ||
[...li.children].forEach((div) => { | ||
if (div.children.length === 1 && div.querySelector('picture')) div.className = 'cards-card-image'; | ||
else div.className = 'cards-card-body'; | ||
}); | ||
ul.append(li); | ||
}); | ||
ul.querySelectorAll('img').forEach((img) => img.closest('picture').replaceWith(createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }]))); | ||
ul.querySelectorAll('img').forEach((img) => { | ||
const optimizedPic = createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }]); | ||
moveInstrumentation(img, optimizedPic.querySelector('img')); | ||
img.closest('picture').replaceWith(optimizedPic); | ||
}); | ||
block.textContent = ''; | ||
block.append(ul); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters