<div style="display:none" class="tips-link">
<a href="#order:Tips 15%=">Tips 15%</a>
<a href="#order:Tips 20%=">Tips 20%</a>
<a href="#order:Tips 25%=">Tips 25%</a>
<a href="#order:Custom tips=">Custom tips</a>
</div>
<style>
div.t706__cartwin_showed { opacity: 1 !important;}
div.addpack .t706__product-plusminus , div.addpack .t706__product-del {
opacity: 0 !important;
pointer-events: none;
}
</style>
<script>
let tipsImage = ':::image=https://static.tildacdn.com/tild3464-6666-4630-b661-613764303135/foreign-currency-sav.jpg';
$(document).ready(function() {
var prName=[];
$('.tips-link a').each(function (index, value){
prName[index] = $(this).text();
});
$('input[name="tips_custom"]').closest('.t-input-group').addClass('tips-cut-wrapper').hide();
//Устанавливает класс для чаевых среди товаров
function setpack(){
setTimeout(function(){
$.each(prName, function (index, value) {
$('div.t706__product-title a:contains('+prName[index]+')').closest('.t706__product').addClass('addpack');
});
}, 50);
};
//Удаляет чаевые
function delPack(){ $('div.addpack .t706__product-del').click();tcart__openCart()};
//Добавить чаевые
function contChecked(){
let fillSumm = false;
var plpac = $('input[name="tips"]:checked').parent('label').index();
delPack();
if(plpac==0){}else{
delPack();
let tipsSumm = tcart.amount;
if(plpac==1) tipsSumm = (tipsSumm*0.15).toFixed(2);
if(plpac==2) tipsSumm = (tipsSumm*0.2).toFixed(2);
if(plpac==3) tipsSumm = (tipsSumm*0.25).toFixed(2);
if(plpac==4){
$('.tips-cut-wrapper').show();
let custSumm = $('.tips-cut-wrapper input').val();
if(custSumm!=''){
tipsSumm=custSumm;
fillSumm=true;
}else{
fillSumm=false;
};
}else{
$('.tips-cut-wrapper').hide();
$('.tips-cut-wrapper input').val('');
};
let linkElem = $('.tips-link a:eq('+(plpac-1)+')');
let href = linkElem.attr('href');
href = href.split('=')[0];
href = href+'='+tipsSumm+tipsImage;
linkElem.attr('href', href);
if(plpac==4){
if(fillSumm) linkElem.click();
}else{
linkElem.click();
};
setpack();
tcart__openCart();
};
};
//При изменении чаевых
$("input[name='tips']").change(function() {contChecked(); tcart__openCart(); });
//При изменении суммы в корзине
$(".t706__cartwin-prodamount").bind( 'DOMSubtreeModified',function() {
setpack(); var itemProd = $('.t706__product').length;
//Если осталась в корзине только чаевые, то удаляем их, закрываем корзину
setTimeout(function(){
if( ( $('.t706__product').length==1) && ($('.t706__product').hasClass('addpack') ) ){
$('input[name="tips"]:eq(0)').prop("checked", true);
delPack();
tcart__closeCart();
};
}, 330);
});
//Активирует нужный выбор чаевых
function checkItem(){
setTimeout(function(){ setpack();
$.each(prName, function (index, value) {
if ($('div.t706__product-title a').text().indexOf(prName[index]) > -1) {
$('input[name="tips"]:eq('+(index+1)+')').prop("checked", true);
};
});
}, 100);
};
//При добавлении товара в корзину
$(document).on('click','a[href^="#order"]:not(.tips-link a), .t706__carticon-wrapper',function(e){
setTimeout(function(){
if($('.t706__cartwin').hasClass('t706__cartwin_showed')){
checkItem(); setTimeout(function(){contChecked() }, 200);
};
}, 50);
});
//При отмене удаления товара
$(document).on('click','.t706__product-deleted__timer__return',function(e){ setTimeout(function(){checkItem() }, 500); });
//При попытке удалении товар
// $(document).on('click','.t706__product-del , .t706__product-minus, .t706__product-plus',function(e){
// let readdclass = setInterval(function() {
// if (document.querySelector('.t706__product-deleted')){
// }else{ setpack(); clearInterval(readdclass);
// };
// }, 200);
// setTimeout(function(){ clearInterval(readdclass)}, 5000);
// });
//Запрет ввода букв в поля
$(document).on('input', 'input[name="tips_custom"]', function(){
this.value = this.value.replace(/[^0-9]/g, '');
});
$(document).on('click','.t706__product-del',function(e){
let elemWrapper = $(this).closest('.t706__product');
if(!elemWrapper.hasClass('addpack')){
setTimeout(function(){
contChecked();
}, 1000);
};
});
let delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$('input[name="tips_custom"]').keyup(function() {
delay(function(){
contChecked();
}, 700 );
});
$(document).on('click','.t706__product-minus, .t706__product-plus',function(e){
delay(function(){
contChecked();
}, 700 );
});
$(document).on('blur','.t706__cartwin-products input',function(e){
delay(function(){
contChecked();
}, 700 );
});
});
</script>