<script>
$( document ).ready(function() {
let productLink = {
"Электро-велосипед Forward 322" : "/thank-you",
"Электро-велосипед Forward 123" : "/thank-what",
"Электро-велосипед Forward 456" : "/thank-who",
"Электро-велосипед Forward 111" : "/thank-why"
};
function prodComplete(){
//При загрузке товаров
let tistore = setInterval(function() {
setTimeout(function(){
if ( $('.uc-mn-block .js-store-grid-cont div').length>0 || $('.t-store__prod-snippet__container').length>0 ){
clearInterval(tistore)
setTimeout(function(){
checkFavorites();
}, 200);
};
}, 600);
}, 100);
};
prodComplete();
function checkFavorites(){
$('.uc-mn-block .t-store__card.t-col').each(function(){
let card = $(this);
let cardName = card.find('.js-store-prod-name').text();
let heart = card.find('.t1002__addBtn');
if(heart.hasClass('t1002__addBtn_active')){
$("a[href='#fvr:"+cardName+"']").addClass('active-favorites');
};
});
};
function changeLink(){
setTimeout(function(){
if(twishlist.products.length){
let lastFavorName = twishlist.products[twishlist.products.length-1].name;
$.each(productLink, function( key, value ) {
if( key == lastFavorName ){
twishlist.products[twishlist.products.length-1].url = value;
setTimeout(function(){
twishlist__saveLocalObj();
twishlist__reDrawProducts()
}, 100);
};
});
};
}, 500);
};
//При добавлении товара в избранное
$(document).on('click',' a[href^="#addtofavorites:"] ',function(e){
changeLink();
});
//При нажатии избранного из Zero
$(document).on('click','a[href^="#fvr:"]',function(e){
e.preventDefault();
let btn = $(this);
let link = btn.attr('href');
let prName = link.split(':')[1];
$('.uc-mn-block .t-store__card.t-col').each(function(){
let card = $(this);
let cardName = card.find('.js-store-prod-name').text();
if(prName==cardName){
let heart = card.find('.t1002__addBtn');
if(heart.hasClass('t1002__addBtn_active')){
btn.removeClass('active-favorites');
}else{
btn.addClass('active-favorites');
};
heart[0].click();
};
});
changeLink();
});
//Убираем активное состояние иконок избранного
$(document).on('click','.t1002__product-del',function(e){
let prodName = $(this).closest('.t1002__product').find('.t1002__product-link').text();
$("a[href='#fvr:"+prodName+"']").removeClass('active-favorites');
});
});
</script>
<style>
a.active-favorites:after {
content: "";
width: 100%;
height: 100%;
background-image: url(https://static.tildacdn.com/tild3333-3161-4330-a663-323239306338/icons8-----100_1.png);
position: absolute;
background-size: cover;
top: 0;
left: 0;
transform: scale(1.05);
}
a.active-favorites img {
opacity: 0;
}
.uc-mn-block{
display: none;
}
</style>