Skip to content

Commit

Permalink
synch with aem-boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 31, 2024
1 parent 8d972a6 commit e7b0f46
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,18 @@ function decorateButtons(element) {

/**
* Add <img> for icon, prefixed with codeBasePath and optional prefix.
* @param {span} [element] span element with icon classes
* @param {string} [prefix] prefix to be added to icon the src
* @param {Element} [span] span element with icon classes
* @param {string} [prefix] prefix to be added to icon src
* @param {string} [alt] alt text to be added to icon
*/
function decorateIcon(span, prefix = '') {
function decorateIcon(span, prefix = '', alt = '') {
const iconName = Array.from(span.classList)
.find((c) => c.startsWith('icon-'))
.substring(5);
const img = document.createElement('img');
img.dataset.iconName = iconName;
img.src = `${window.hlx.codeBasePath}${prefix}/icons/${iconName}.svg`;
img.alt = alt;
img.loading = 'lazy';
span.append(img);
}
Expand Down Expand Up @@ -449,7 +451,10 @@ function decorateSections(main) {
const meta = readBlockConfig(sectionMeta);
Object.keys(meta).forEach((key) => {
if (key === 'style') {
const styles = meta.style.split(',').map((style) => toClassName(style.trim()));
const styles = meta.style
.split(',')
.filter((style) => style)
.map((style) => toClassName(style.trim()));
styles.forEach((style) => section.classList.add(style));
} else {
section.dataset[toCamelCase(key)] = meta[key];
Expand Down

0 comments on commit e7b0f46

Please sign in to comment.