<script>
document.addEventListener("DOMContentLoaded", function() {
(function () {
const hideMode = false; //Скрыть-Показать пустую корзину - true-false
const cartcopyElem = document.querySelectorAll(".cartcopy_elem");
cartcopyElem.forEach(function (el, index) {
el.classList.add('cartcopy');
});
const carttotalElem = document.querySelectorAll(".carttotal_elem");
carttotalElem.forEach(function (el, index) {
el.classList.add('carttotal');
});
const cartpriceElem = document.querySelectorAll(".cartprice_elem");
cartpriceElem.forEach(function (el, index) {
el.classList.add('cartcopyprice');
});
function showCart(){
document.querySelectorAll('.cartcopy').forEach(el=>el.classList.add('show-cart'));
document.querySelectorAll('.carttotal').forEach(el=>el.classList.add('show-cart'));
document.querySelectorAll('.cartcopyprice').forEach(el=>el.classList.add('show-cart'));
};
function checkCartTotal(){
if (window.tcart != undefined) {
if(!hideMode) showCart()
const chCounter = window.tcart.total;
const chPrice = window.tcart.prodamount;
if (chPrice==0){
document.querySelectorAll('.cartcopyprice').forEach(el=>el.innerHTML='');
if(hideMode) {
document.querySelectorAll('.cartcopy').forEach(el=>el.classList.remove('show-cart'));
document.querySelectorAll('.carttotal').forEach(el=>el.classList.remove('show-cart'));
document.querySelectorAll('.cartcopyprice').forEach(el=>el.classList.remove('show-cart'));
}else{
showCart();
};
}else{
document.querySelectorAll('.cartcopyprice').forEach(el=>el.innerHTML=chPrice+' руб');
if(hideMode) showCart();
};
document.querySelectorAll('.carttotal').forEach(el=>el.innerHTML=chCounter);
if(chCounter==0){
document.querySelectorAll('.cartcopy').forEach(el=>el.classList.add('blkElem'));
document.querySelectorAll('.carttotal').forEach(el=>el.classList.add('blkElem'));
}else{
document.querySelectorAll('.cartcopy').forEach(el=>el.classList.remove('blkElem'));
document.querySelectorAll('.carttotal').forEach(el=>el.classList.remove('blkElem'));
};
if(chCounter=='') document.querySelectorAll('.carttotal').forEach(el=>el.innerHTML=0);
};
};
setTimeout(function(){
checkCartTotal();
}, 500);
const observer = new MutationObserver(mutationRecords => {
setTimeout(function(){
checkCartTotal();
}, 300);
document.querySelectorAll('.cartcopy').forEach(el=>el.classList.add('cartcopyanim'));
setTimeout(function(){
document.querySelectorAll('.cartcopy').forEach(el=>el.classList.remove('cartcopyanim'));
}, 1000);
});
const carticonCounter = document.querySelector('.t706__carticon-counter');
if(carticonCounter!=null){
observer.observe(carticonCounter, {
childList: true,
subtree: true,
characterDataOldValue: true
});
}else{
console.log('cart counter option not active');
};
document.addEventListener('click', function(e) {
const target = e.target.closest('.cartcopy, .carttotal, .cartcopyprice');
if (target) {
e.preventDefault();
tcart__openCart();
}
});
})();
});
</script>
<style>
.blkElem{pointer-events:none; }
.cartcopyanim {
-webkit-animation: t706__pulse-anim 0.6s;
animation: t706__pulse-anim 0.6s;}
.cartcopy_elem,
.cartprice_elem,
.carttotal_elem
{
opacity:0;
pointer-events: none;
}
.r .show-cart{
opacity: 1;
pointer-events: auto;
}
.cartcopy,
.carttotal,
.cartcopyprice
{cursor:pointer}
.t706__carticon {display: none !important;}
</style>