Skip to content

Commit

Permalink
Create cards.js
Browse files Browse the repository at this point in the history
  • Loading branch information
oharris69 authored Sep 29, 2024
1 parent c20b8b8 commit e507806
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions blocks/cards/cards.js
Original file line number Diff line number Diff line change
@@ -0,0 +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');
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('picture > 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);
}

0 comments on commit e507806

Please sign in to comment.