Skip to content

Commit

Permalink
Merge branch 'main' into mwpw-133172-caas-configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadparwaiz authored Aug 3, 2023
2 parents d2004fd + 85ced02 commit 1338486
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 18 additions & 17 deletions libs/blocks/section-metadata/section-metadata.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
function handleBackground(div, section) {
const pic = div.background.content.querySelector('picture');
if (pic) {
section.classList.add('has-background');
pic.classList.add('section-background');
handleFocalpoint(pic, div.background.content);
section.insertAdjacentElement('afterbegin', pic);
} else {
const color = div.background.content.textContent;
if (color) {
section.style.background = color;
}
}
}

export function handleFocalpoint(pic, child, removeChild) {
const image = pic.querySelector('img');
if (!child || !image) return;
let text = '';
if (child.childElementCount === 2) {
const dataElement = child.querySelectorAll('p')[1];
text = dataElement?.textContent;
removeChild ? dataElement?.remove() : '';
if (removeChild) dataElement?.remove();
} else if (child.textContent) {
text = child.textContent;
const childData = child.childNodes;
removeChild ? childData.forEach((c) => c.nodeType === Node.TEXT_NODE && c.remove()) : '';
if (removeChild) childData.forEach((c) => c.nodeType === Node.TEXT_NODE && c.remove());
}
const directions = text.trim().toLowerCase().split(',');
const [x, y = ''] = directions;
image.style.objectPosition = `${x} ${y}`;
}
function handleBackground(div, section) {
const pic = div.background.content?.querySelector('picture');
if (pic) {
section.classList.add('has-background');
pic.classList.add('section-background');
handleFocalpoint(pic, div.background.content);
section.insertAdjacentElement('afterbegin', pic);
} else {
const color = div.background.content?.textContent;
if (color) {
section.style.background = color;
}
}
}

function handleTopHeight(section) {
const headerHeight = document.querySelector('header').offsetHeight;
Expand All @@ -39,10 +38,12 @@ async function handleStickySection(sticky, section) {
const main = document.querySelector('main');
switch (sticky) {
case 'sticky-top':
{
const { debounce } = await import('../../utils/action.js');
window.addEventListener('resize', debounce(() => handleTopHeight(section)));
main.prepend(section);
break;
}
case 'sticky-bottom':
main.append(section);
break;
Expand Down
2 changes: 2 additions & 0 deletions libs/utils/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export function debounce(callback, time = 300) {
timer = setTimeout(() => callback(...args), time);
};
}

export default { debounce };

0 comments on commit 1338486

Please sign in to comment.