Skip to content

Commit

Permalink
Merge branch 'stage' into analyticsusebold
Browse files Browse the repository at this point in the history
  • Loading branch information
Blainegunn authored Mar 19, 2024
2 parents 1b0c107 + 248f71c commit 83ec87f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 279 deletions.
30 changes: 13 additions & 17 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const MULTI_OFFER_CARDS = ['plans', 'product', MINI_COMPARE_CHART];
// Force cards to refresh once they become visible so that the footer rows are properly aligned.
const intersectionObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.target.clientHeight === 0) return;
const container = entry.target.closest('main > div');
if (!container) return;
[...container.querySelectorAll('merch-card')].forEach((card) => card.requestUpdate());
intersectionObserver.unobserve(entry.target);
entry.target.requestUpdate();
});
});

Expand All @@ -34,7 +35,7 @@ const isHeadingTag = (tagName) => /^H[2-5]$/.test(tagName);
const isParagraphTag = (tagName) => tagName === 'P';

const appendSlot = (slotEls, slotName, merchCard) => {
if (slotEls.length === 0 && merchCard.variant !== MINI_COMPARE_CHART) return;
if (slotEls.length === 0) return;
const newEl = createTag(
'p',
{ slot: slotName, class: slotName },
Expand Down Expand Up @@ -189,7 +190,7 @@ const simplifyHrs = (el) => {
});
};

async function extractQuantitySelect(el) {
function extractQuantitySelect(el) {
const quantitySelectConfig = el.querySelector('ul');
if (!quantitySelectConfig) return null;
const configMarkup = quantitySelectConfig.querySelector('li');
Expand All @@ -201,7 +202,7 @@ async function extractQuantitySelect(el) {
const quantityValues = config[1].textContent.split(',').map((value) => value.trim())
.filter((value) => /^\d+$/.test(value));
if (quantityValues.length !== 3) return null;
await import('../../deps/merch-quantity-select.js');
import('../../deps/merch-quantity-select.js');
[attributes.min, attributes.max, attributes.step] = quantityValues.map(Number);
const quantitySelect = createTag('merch-quantity-select', attributes);
quantitySelectConfig.remove();
Expand Down Expand Up @@ -239,12 +240,8 @@ const decorateFooterRows = (merchCard, footerRows) => {

const setMiniCompareOfferSlot = (merchCard, offers) => {
if (merchCard.variant !== MINI_COMPARE_CHART) return;
const miniCompareOffers = merchCard.querySelector('div[slot="offers"]');
if (offers) {
miniCompareOffers.append(offers);
} else {
miniCompareOffers.appendChild(createTag('p'));
}
const miniCompareOffers = createTag('div', { slot: 'offers' }, offers);
if (offers === undefined) { miniCompareOffers.appendChild(createTag('p')); }
merchCard.appendChild(miniCompareOffers);
};

Expand Down Expand Up @@ -309,7 +306,10 @@ const init = async (el) => {
}
let footerRows;
if (cardType === MINI_COMPARE_CHART) {
intersectionObserver.observe(merchCard);
const container = el.closest('[data-status="decorated"]');
if (container) {
intersectionObserver.observe(container);
}
footerRows = getMiniCompareChartFooterRows(el);
}
const images = el.querySelectorAll('picture');
Expand Down Expand Up @@ -386,11 +386,7 @@ const init = async (el) => {
merchCard.appendChild(footer);

if (MULTI_OFFER_CARDS.includes(cardType)) {
if (merchCard.variant === MINI_COMPARE_CHART) {
const miniCompareOffers = createTag('div', { slot: 'offers' });
merchCard.append(miniCompareOffers);
}
const quantitySelect = await extractQuantitySelect(el, cardType);
const quantitySelect = extractQuantitySelect(el);
const offerSelection = el.querySelector('ul');
if (offerSelection) {
const { initOfferSelection } = await import('./merch-offer-select.js');
Expand Down
1 change: 0 additions & 1 deletion libs/blocks/merch-card/merch-offer-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function createDynamicSlots(el, bodySlot) {
const descriptionSlot = el.querySelector('p[slot="description"]');
if (descriptionSlot) {
descriptionSlot.innerHTML += description.innerHTML;
description.parentNode.removeChild(description);
}
}
}
Expand Down
Loading

0 comments on commit 83ec87f

Please sign in to comment.