<script>
$( document ).ready(function() {
function prodComplete(){
//При загрузке товаров
let tistore = setInterval(function() {
setTimeout(function(){
if ( $('.js-store-grid-cont div').length>0 || $('.t-store__prod-snippet__container').length>0 ){
clearInterval(tistore)
setTimeout(function(){
setLink();
}, 200);
};
}, 250);
}, 100);
};
prodComplete();
let linkBtn = '#popup:shopform';
let popupForm = $('div[data-tooltip-hook="'+linkBtn+'"]');
popupForm.find('.t702__descr').before('<div class="popup_img"></div>');
function setLink(){
setTimeout(function(){
$('.js-product-price').each(function(){
let price = $(this).attr('data-product-price-def');
if (price == '0' || price == '' ){
$(this).closest('.js-product').addClass('noprice');
};
});
let orderBtn = $('.noprice').find('.t-store__prod-popup__btn');
let orderBtn2 = $('.noprice').find('.js-store-prod-btn2');
if( ( orderBtn.length>0 || orderBtn2.length>0) && popupForm.length>0 ){
orderBtn.off('click').attr('href', linkBtn);
orderBtn2.off('click').attr('href', linkBtn);
$(document).on('click','.noprice .t-store__prod-popup__btn , .noprice .js-store-prod-btn2 ',function(e){
let cardInfo = $(this).closest('.js-product');
let title = cardInfo.find('.js-store-prod-name').text();
let sku = 'Артикул: '+cardInfo.find('.js-store-prod-sku').text();
let image = cardInfo.find('.t-slds__item_active .t-slds__bgimg').attr('data-original');
if(cardInfo.find('.js-product-img')){
image = cardInfo.find('.js-product-img:first').attr('data-original');
};
let quant = '';
if( cardInfo.find('.t-store__prod__quantity-input').length ) {
quant = cardInfo.find('.t-store__prod__quantity-input').val()+' шт.';
};
popupForm.find('.t702__descr').html(title+'<br>'+sku+'<br>'+quant);
popupForm.find('input[name="prodinfo"]').val(title+' - '+sku+' - '+quant);
$('.popup_img').css('background-image', 'url('+image+')');
});
}else{
console.log('Order button or popup '+linkBtn+' not found');
};
$('.js-product').addClass('viewed-card');
}, 100);
};
$(document).on('click','.js-store-filter , .js-store-filter-chosen-item , .js-store-load-more-btn , .js-store-parts-switcher',function(e){ prodComplete(); });
$(document).on('keydown','.js-store-filter',function(event){if(event.keyCode == 13) { prodComplete()}});
$(document).on('change','.t-store__sort-select',function(e){ prodComplete() });
//При открытии карточки товара
$(document).on('click','a[href*="/tproduct/"]',function(e){ prodComplete() });
$(document).on('click','a[href*="#order"]',function(e){ prodComplete() });
let startScroll,
toHandler,
endScroll;
$(window).on("scroll",function(){
if (!startScroll) {
startScroll = $(window).scrollTop();
} else {
if (toHandler) {
clearTimeout(toHandler)
}
toHandler = setTimeout(function(){
endScroll = $(window).scrollTop();
let btw = endScroll-startScroll;
if(btw>50){
let jp = $('.js-product').length;
let vc = $('.viewed-card').length;
console.log(jp);
console.log(vc);
if(jp>vc) prodComplete();
};
startScroll = 0;
},200)
}
});
});
</script>
<style>
.popup_img {
width: 100px;
height: 100px;
background-size: cover;
background-position: center;
margin: 15px auto;
}
.noprice a.js-store-prod-btn2 span:after,
.noprice .js-store-prod-popup-buy-btn-txt:after{
content: "Запросить цену";
font-size: 14px;
}
.noprice a.js-store-prod-btn2 span,
.noprice .js-store-prod-popup-buy-btn-txt{
font-size: 0;
}
</style>