Tummy Control, Feminine Health Defense Legging
Men's PFA-Free Cooling, Flame Resistant, Breathable Boxer Briefs
The Absorbent, Antimicrobial Insert (2-Pack)
(function() {
const ID = 'amuqrbuxdstfzsw81aaigenblock09bc980uk7dpd';
function refreshCart() {
// Step 1: Add the item to the cart data, then trigger the drawer
// the way the theme expects โ by simulating a click on the cart icon,
// which lets the theme's own cc-popup JS handle open/close properly.
fetch('/?sections=cart-drawer')
.then(r => r.json())
.then(data => {
if (!data['cart-drawer']) return;
const parser = new DOMParser();
const doc = parser.parseFromString(data['cart-drawer'], 'text/html');
const drawer = document.querySelector('[data-section-type="cart-drawer"]');
if (!drawer) return;
// Update the cart-form contents with fresh HTML
const newCartForm = doc.querySelector('cart-form');
const oldCartForm = drawer.querySelector('cart-form');
if (newCartForm && oldCartForm) {
oldCartForm.innerHTML = newCartForm.innerHTML;
}
// Open the drawer by clicking the theme's own cart trigger button
// so the theme's cc-popup JS registers it as open (and close works)
const cartTrigger = document.querySelector(
'.cc-popup-trigger[aria-controls="CartDrawerModal"], ' +
'[data-popup-trigger="cart-drawer"], ' +
'.js-cart-trigger, ' +
'[href="#cart-drawer"], ' +
'a[href="#CartDrawerModal"]'
);
if (cartTrigger) {
cartTrigger.click();
} else {
// Fallback: dispatch the theme's tap-target open event
const modal = drawer.querySelector('.cart-drawer-modal');
if (modal) {
modal.dispatchEvent(new CustomEvent('cc-popup:open', { bubbles: true }));
modal.dispatchEvent(new CustomEvent('tap-target:open', { bubbles: true }));
// Last resort: manually set classes
modal.removeAttribute('aria-hidden');
modal.classList.add('is-visible', 'active', 'open');
document.body.classList.add('cc-popup-open', 'freeze-scroll');
}
}
// Update cart count badge
fetch('/cart.js')
.then(r => r.json())
.then(cart => {
document.querySelectorAll(
'[data-cart-count], .cart-count, #cart-count, .cart__count, ' +
'.header__cart-count, [data-cart-item-count], .cart-item-count, ' +
'.cc-cart-count, [data-cc-cart-count]'
).forEach(el => { el.textContent = cart.item_count; });
})
.catch(() => {});
})
.catch(() => {});
}
async function addToCart(variantId, btn, onSuccess, onError) {
const originalText = btn.textContent.trim();
btn.disabled = true;
btn.textContent = 'Addingโฆ';
try {
const res = await fetch('/cart/add.js', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: Number(variantId), quantity: 1 })
});
btn.textContent = originalText;
if (res.ok) {
refreshCart();
if (onSuccess) onSuccess();
} else {
btn.disabled = false;
const err = await res.json().catch(() => ({}));
if (onError) onError(err.description || 'Could not add to cart. Please try again.');
}
} catch {
btn.textContent = originalText;
btn.disabled = false;
if (onError) onError('Something went wrong. Please try again.');
}
}
class VideoTiles extends HTMLElement {
connectedCallback() {
this.querySelectorAll('.ai-video-tiles__video-' + ID).forEach(v => {
v.addEventListener('loadedmetadata', () => v.play().catch(() => {}));
});
this.setupQuickShop();
}
setupQuickShop() {
const modal = document.getElementById('ai-qs-modal-' + ID);
const backdrop = document.getElementById('ai-qs-backdrop-' + ID);
const closeBtn = document.getElementById('ai-qs-close-' + ID);
const titleEl = document.getElementById('ai-qs-product-title-' + ID);
const optsEl = document.getElementById('ai-qs-options-container-' + ID);
const atcBtn = document.getElementById('ai-qs-atc-btn-' + ID);
const msgEl = document.getElementById('ai-qs-msg-' + ID);
let variants = [];
let options = [];
let selected = {};
const openModal = (trigger) => {
variants = JSON.parse(trigger.dataset.variants || '[]');
options = JSON.parse(trigger.dataset.options || '[]');
selected = {};
titleEl.textContent = trigger.dataset.productTitle || '';
renderOptions();
modal.classList.add('is-open');
document.body.style.overflow = 'hidden';
msgEl.textContent = '';
atcBtn.disabled = true;
atcBtn.textContent = 'Add to Cart';
};
const closeModal = () => {
modal.classList.remove('is-open');
document.body.style.overflow = '';
};
const allSelected = () => options.every(opt => selected[opt.name] !== undefined);
const renderOptions = () => {
optsEl.innerHTML = '';
options.forEach((opt) => {
const group = document.createElement('div');
group.className = 'ai-qs-option-group-' + ID;
const label = document.createElement('div');
label.className = 'ai-qs-option-label-' + ID;
label.textContent = opt.name;
group.appendChild(label);
const btnRow = document.createElement('div');
btnRow.className = 'ai-qs-options-' + ID;
opt.values.forEach(val => {
const btn = document.createElement('button');
btn.className = 'ai-qs-option-btn-' + ID;
btn.textContent = val;
btn.type = 'button';
const isAvailable = variants.some(v => {
const matches = options.every((o, i) => {
if (o.name === opt.name) return v['option' + (i + 1)] === val;
if (selected[o.name]) return v['option' + (i + 1)] === selected[o.name];
return true;
});
return matches && v.available;
});
if (!isAvailable) btn.disabled = true;
if (selected[opt.name] === val) btn.classList.add('selected');
btn.addEventListener('click', () => {
selected[opt.name] = val;
renderOptions();
atcBtn.disabled = !allSelected();
});
btnRow.appendChild(btn);
});
group.appendChild(btnRow);
optsEl.appendChild(group);
});
};
atcBtn.addEventListener('click', () => {
const variant = variants.find(v =>
options.every((opt, idx) => v['option' + (idx + 1)] === selected[opt.name])
);
if (!variant) return;
addToCart(
variant.id,
atcBtn,
() => {
msgEl.textContent = 'โ Added to cart!';
atcBtn.disabled = true;
setTimeout(closeModal, 800);
},
(errMsg) => {
msgEl.textContent = errMsg;
}
);
});
this.querySelectorAll('.ai-qs-trigger-' + ID).forEach(trigger => {
trigger.addEventListener('click', () => {
if (trigger.dataset.singleVariant === 'true') {
addToCart(
trigger.dataset.variantId,
trigger,
() => {
const orig = trigger.textContent.trim();
trigger.textContent = 'โ Added!';
trigger.disabled = true;
setTimeout(() => {
trigger.textContent = orig;
trigger.disabled = false;
}, 1500);
},
() => { trigger.disabled = false; }
);
return;
}
openModal(trigger);
});
});
closeBtn.addEventListener('click', closeModal);
backdrop.addEventListener('click', closeModal);
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeModal(); });
}
}
customElements.define('video-tiles-' + ID, VideoTiles);
})();