jQuery(function ($){
if(typeof zndPostViews==='undefined') return;
const viewElements=$('.znd-post-meta .znd-views[data-post-id]');
const idsMap={};
const ids=[];
viewElements.each(function (){
const id=parseInt($(this).data('post-id'), 10);
if(id&&!idsMap[id]){
idsMap[id]=true;
ids.push(id);
}});
if(ids.length){
$.post(zndPostViews.ajax_url, {
action: 'znd_get_post_views',
post_ids: ids
}, function (response){
if(response&&response.success&&response.data&&response.data.views){
viewElements.each(function (){
const id=parseInt($(this).data('post-id'), 10);
const views=response.data.views[id];
if(typeof views!=='undefined'){
$(this).find('.znd-views-count').text(views);
$(this).stop(true).animate({ opacity: 1 }, 250);
}});
}});
}
if(zndPostViews.post_id){
setTimeout(function (){
$.post(zndPostViews.ajax_url + '?t=' + Date.now(), {
action: 'znd_update_post_views',
post_id: zndPostViews.post_id
}, function (response){
if(response&&response.success&&response.data&&typeof response.data.views!=='undefined'){
const target=$('.znd-post-meta .znd-views[data-post-id="' + zndPostViews.post_id + '"]');
target.find('.znd-views-count').text(response.data.views);
target.stop(true).animate({ opacity: 1 }, 250);
}});
}, 200);
}});