When we first checked out our new headphones, we noticed the box said “improved bass”. We had to wonder if this was marketing jargon or the real thing? But it only took a moment to realize that bass was not kidding.
document.addEventListener('DOMContentLoaded', function () {
var hiddenCard = document.querySelector('#rec2502427561');
function syncAvailability() {
document.querySelectorAll('.size-option').forEach(function (overlay) {
var size = overlay.getAttribute('data-size').toUpperCase();
var input = hiddenCard.querySelector(
'.t-product__option-input[value="' + size + '"]'
);
if (!input) return;
var isUnavailable = input
.closest('.t-product__option-item')
.classList.contains('t-product__option-item_disabled');
overlay.classList.toggle('is-disabled', isUnavailable);
});
}
syncAvailability();
setTimeout(syncAvailability, 1000); // на случай, если карточка дорисовывается с задержкой
// блокировка клика
document.addEventListener('click', function (e) {
var btn = e.target.closest('[data-size]');
if (!btn || !btn.classList.contains('size-option')) return;
if (btn.classList.contains('is-disabled')) {
return; // недоступный размер — игнорируем клик
}
document.querySelectorAll('.size-option').forEach(function (b) {
b.classList.remove('is-active');
});
btn.classList.add('is-active');
var selectedSize = btn.getAttribute('data-size').toUpperCase();
var sizeInput = hiddenCard.querySelector(
'.t-product__option-input[value="' + selectedSize + '"]'
);
if (sizeInput) {
var label = sizeInput.closest('.t-product__option-item');
if (label) label.click();
}
window.selectedSize = selectedSize; // сохраняем глобально для обработчика "В корзину"
});
// клик по "В корзину"
document.addEventListener('click', function (e) {
var buyBtn = e.target.closest('.buy-btn');
if (!buyBtn) return;
if (!window.selectedSize) {
alert('Пожалуйста, выберите размер');
return;
}
var realBuyBtn = hiddenCard.querySelector('.t922__btn');
if (realBuyBtn) {
realBuyBtn.click();
}
});
});