Skip to content

Commit

Permalink
refactor methor of checking for picture that must be wrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
shsteimer committed Mar 1, 2024
1 parent 8c166b2 commit 2523dd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
13 changes: 5 additions & 8 deletions dist/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,11 @@ function wrapTextNodes(block) {
&& validWrappers.some((tagName) => blockColumn.firstElementChild.tagName === tagName);
if (!hasWrapper) {
wrap(blockColumn);
} else if (blockColumn.firstElementChild.tagName === 'PICTURE') {
const nonEmptySiblings = [...blockColumn.childNodes].some((n) => {
if (n.nodeType === Node.TEXT_NODE) return !!n.textContent.trim();
return n !== blockColumn.firstElementChild;
});
if (nonEmptySiblings) {
wrap(blockColumn);
}
} else if (
blockColumn.firstElementChild.tagName === 'PICTURE'
&& (blockColumn.children.length > 1 || !!blockColumn.textContent.trim())
) {
wrap(blockColumn);
}
}
});
Expand Down
11 changes: 3 additions & 8 deletions src/dom-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,9 @@ export function wrapTextNodes(block) {
&& validWrappers.some((tagName) => blockColumn.firstElementChild.tagName === tagName);
if (!hasWrapper) {
wrap(blockColumn);
} else if (blockColumn.firstElementChild.tagName === 'PICTURE') {
const nonEmptySiblings = [...blockColumn.childNodes].some((n) => {
if (n.nodeType === Node.TEXT_NODE) return !!n.textContent.trim();
return n !== blockColumn.firstElementChild;
});
if (nonEmptySiblings) {
wrap(blockColumn);
}
} else if (blockColumn.firstElementChild.tagName === 'PICTURE'
&& (blockColumn.children.length > 1 || !!blockColumn.textContent.trim())) {
wrap(blockColumn);
}
}
});
Expand Down

0 comments on commit 2523dd3

Please sign in to comment.