jQuery(document).ready(function(){
ajaxURL="https://azull.info/wp-admin/admin-ajax.php";
jQuery.ajax({
type:"post",
dataType: "html",
url:ajaxURL,
data:{
'action':'fav_counter_ajax',
},
success:function(data){
console.log(data);
jQuery('.shortlist_counter').html(data);
}});
jQuery(document).on('click','.add_shortlist',function(){
var shortlist=Cookies.get('shortlist');
if(typeof(shortlist)!="undefined"&&shortlist!==null&&shortlist!==""){
var ref=jQuery(this).data('ref');
shortlistCookie=Cookies.get('shortlist');
shortlist=Cookies.get('shortlist').split(',');
if(shortlistCookie.includes(ref)){
shortlist.splice(jQuery.inArray(shortlist,ref), 1);
jQuery(this).html(jQuery(this).data('label-add'));
}else{
shortlist.push(ref);
jQuery(this).html(jQuery(this).data('label-remove'));
}
shortlist=shortlist.join(',');
}else{
shortlist=jQuery(this).data('ref');
jQuery(this).html(jQuery(this).data('label-remove'));
}
console.log(shortlist);
Cookies.set('shortlist',shortlist, { expires: 7 , path: '/' });
ajaxURL="https://azull.info/wp-admin/admin-ajax.php";
jQuery.ajax({
type:"post",
dataType: "html",
url:ajaxURL,
data:{
'action':'send_fav_to_DB',
shortlist:shortlist
},
success:function(data){
console.log(data);
}});
var shortlistCount=0;
if(shortlist!=""){
shortlistCount=Cookies.get('shortlist').split(',').length;
}
jQuery('.shortlist_counter').html(shortlistCount);
jQuery(parent.document).find('.shortlist_counter').html(shortlistCount);
})
});