!function(n){"use strict";function s(t){return(t=parseInt(t,10))<1?0:1e6<=t?(t=Math.floor(t/1e5)/10)+"M":1e3<=t?(t=Math.floor(t/100)/10)+"K":t}function l(t,a){var i;t&&t.length&&(i=t.attr("data-post-id"),t=t.data("like-count"),(i=n(".post-like[data-post-id="+i+"]"))&&i.length&&(t=a?parseInt(t,10)+1:t-1,i.data("like-count",Math.max(0,t)),i.find(".count").text(s(t)),i.find(".label").length&&(i=(a=i.find(".label")).first().parent(),a.text(1<t?i.data("plural-label"):i.data("single-label")))))}var c={likes:!1,itemName:"loftocean/liked",init:function(){var t;!n(".post-like").length||(t=c.getItem(c.itemName))&&(c.likes=JSON.parse(t),c.hasLikes()&&n(document).ready(function(){c.addLikedClass()})),n(document).on("loftcean/moreContent/loaded",function(){c.addLikedClass()})},addLikedClass:function(){c.hasLikes()&&c.likes.forEach(function(t){t=n(".post-like[data-post-id="+t+"]");t.length&&t.addClass("liked")})},set:function(t){c.hasLikes()?-1===c.likes.indexOf(t)&&(c.likes.push(t),c.save()):(c.likes=[t],c.save())},isLiked:function(t){return!!c.hasLikes()&&-1!==c.likes.indexOf(t)},remove:function(t){!c.hasLikes()||-1!==(t=c.likes.indexOf(t))&&(c.likes.splice(t,1),c.save())},save:function(){try{window.localStorage.setItem(c.itemName,JSON.stringify(c.likes))}catch(t){}},hasLikes:function(){return c.likes&&Array.isArray(c.likes)},getItem:function(t){try{return localStorage.getItem(t)}catch(t){return null}}};c.init(),n(document).ready(function(){var e,o,t,a,i;n(".post-like").length&&n("body").on("click",".post-like",function(t){t.preventDefault();var a,i,e,o=n(this);return o.data("animating")||(a=o.attr("data-post-id"),(i=n(".post-like[data-post-id="+a+"]")).data("animating",!0),o.hasClass("liked")?(e={action:loftoceanSocialAjax.like.action,post_id:a,unliked:!0},n.post(loftoceanSocialAjax.url,e).done(function(){c.remove(a),0<o.data("like-count")&&(l(o,!1),i.removeClass("liked")),i.data("animating",!1)})):a&&!c.isLiked(a)?(e={action:loftoceanSocialAjax.like.action,post_id:a},i.addClass("liked clicking"),n.post(loftoceanSocialAjax.url,e).done(function(){c.set(a),l(o,!0),i.data("animating",!1),i.removeClass("clicking")})):i.data("animating",!1)),!1}),n(".post-list-social-icon-list a.popup-window, .article-share a.popup-window, .tweet-it, .social-share-icons > a").length&&n("body").on("click",".post-list-social-icon-list a.popup-window, .article-share a.popup-window, .tweet-it, .social-share-icons > a",function(t){t.preventDefault();var i=n(this),t=i.attr("data-props")?i.attr("data-props"):"width=555,height=401";return window.open(i.attr("href"),i.attr("title"),t),i.data("social-type")&&i.data("post-id")&&(t={action:loftoceanSocialAjax.social.action,post_id:i.data("post-id"),social:i.data("social-type")},n.post(loftoceanSocialAjax.url,t).done(function(){var t=(i.data("raw-counter")||0)+1,a='.loftocean-social-share-icon[data-social-type="'+i.data("social-type")+'"]';n(a).data("raw-counter",t).find("span.counter").text(s(t))})),!1}),wpApiSettings&&wpApiSettings.root&&loftoceanSocialAjax&&loftoceanSocialAjax.loadPostMetasDynamically&&(e=n(".loftocean-view-meta"),o=n(".loftocean-like-meta"),(t=n("<div>",{class:"temp-div"}).add(e).add(o).not(".temp-div")).length&&(a=[],i=loftoceanSocialAjax.currentPostID,t.each(function(){n(this).data("post-id")&&!a.includes(n(this).data("post-id"))&&a.push(n(this).data("post-id"))}),i&&!a.includes(parseInt(i,10))&&a.push(i),a.length&&(i=wpApiSettings.root+"loftocean/v1/get-post-metas/"+a.join(",")+"/"+(i||0),n.get(i).done(function(a,t,i){200==i.status&&200==a.status&&(a=a.data,e.each(function(){var t=n(this).data("post-id");a[t]&&a[t]["loftocean-view-count"]&&(t=a[t]["loftocean-view-count"],n(this).find(".count").length&&n(this).find(".count").text(t.format))}),o.each(function(){var t=n(this).data("post-id");a[t]&&a[t]["loftocean-like-count"]&&(t=a[t]["loftocean-like-count"],n(this).data("like-count",Math.max(0,t.raw)),n(this).find(".count").length&&n(this).find(".count").text(t.format))}))}))))})}(jQuery);