"use strict";(function(){var n=function(){this._getOptions=function(){var n=this;return{data:{voteAndBookmarks:{containerSelector:"",fetchUrl:"",method:"POST",onComplete:function(t){return n._setVotesAndBookmarks(t)},active:!1,completed:!1,data:null},comments:{containerSelector:"",fetchUrl:"",method:"GET",onComplete:function(n){try{var t=document.querySelector(this.containerSelector);return t.innerHTML=n,!0}catch(i){return!1}},active:!1,completed:!1,data:null},topUsers:{containerSelector:"",fetchUrl:"",method:"GET",onComplete:function(t){try{var i=document.querySelector(this.containerSelector);return i.innerHTML=t,n._setTopUsers(),!0}catch(r){return!1}},active:!1,completed:!1,data:null},recentUsers:{containerSelector:"",fetchUrl:"",method:"GET",onComplete:function(t){try{var i=document.querySelector(this.containerSelector);return i.innerHTML=t,n._setRecentUsersPopover(),!0}catch(r){return!1}},active:!1,completed:!1,data:null}}}};this.options=this._getOptions().data;this.fetcher="/Views/Workers/js/wrk_fetcher.es5.js";this._extend=function(){for(var n,t=1;t<arguments.length;t++)for(n in arguments[t])arguments[t].hasOwnProperty(n)&&(typeof arguments[0][n]=="object"&&typeof arguments[t][n]=="object"?this._extend(arguments[0][n],arguments[t][n]):arguments[0][n]=arguments[t][n]);return arguments[0]};this._setTopUsers=function(){var i=$("#top-users-carousel"),n,t;i.carousel();n=i.data("bs.carousel");t=$("#top-users-carousel-container");$(".glyphicon-chevron-left",t).on("click",function(){return n.prev()});$(".glyphicon-chevron-right",t).on("click",function(){return n.next()})};this._setRecentUsersPopover=function(){$(".active-user").popover()};this._setVotesAndBookmarks=function(n){for(var t,i,r,f=typeof n=="string"?JSON.parse(n):n,u=0;u<f.length;u++){if(t=f[u],typeof $=="undefined")return!1;if((i=$("#"+t.PostId),i.length!==0)&&(r=$(".votes-total",i),r.length>0))if(r.text(t.Votes),t.UserHasVoted?r.removeClass("not-voted").addClass("voted"):r.removeClass("voted").addClass("not-voted"),t.InUserScrapbook)$(".fa",i).unwrap().removeClass("fa-bookmark").addClass("fa-bookmark-o").attr("title","Archiviato nel tuo scrapbook");else if(t.UserIsAuthenticated)$(".fa",i).parent().attr("data-target","read-after").on("click",function(n){return storeToReadAfter(n)})}return!0};this._activate=function(n){var t=new Worker(this.fetcher);t.postMessage({url:n.fetchUrl,method:n.method});t.addEventListener("message",function(t){n.completed=n.onComplete(t.data);n.completed||(n.data=t.data)},!1)};this.execute=function(n){var i,t,r;if(window.Worker)for(this._extend(this.options,n),i=Object.entries(this.options),t=0;t<i.length;t++)r=i[t][1],r.active&&this._activate(r)};this.fallBack=function(){var t=this,n=this.options;n.recentUsers.active&&$(n.recentUsers).load(n.recentUsers.fetchUrl,function(){t._setRecentUsersPopover()});n.topUsers.active&&$(n.topUsers.containerSelector).load(n.topUsers.fetchUrl,n.topUsers.onComplete);n.voteAndBookmarks.active&&$.post(n.voteAndBookmarks.fetchUrl,function(t){n.voteAndBookmarks.onComplete(t)});n.comments.active&&$(n.comments.containerSelector).load(n.comments.fetchUrl)};this.fixRendering=function(){for(var t,n,u=this,r=Object.entries(this.options),f=this,i=0;i<r.length;i++)if(t=r[i],n=t[1],n.active&&!n.completed)if(n.data!=null)n.onComplete(n.data);else(function(){var n=u.options;switch(t[0]){case"recentUsers":$(n.recentUsers).load(n.recentUsers.fetchUrl,function(){f._setRecentUsersPopover()});break;case"topUsers":$(n.topUsers.containerSelector).load(n.topUsers.fetchUrl,n.topUsers.onComplete);break;case"voteAndBookmarks":$.post(n.voteAndBookmarks.fetchUrl,function(t){n.voteAndBookmarks.onComplete(t)});break;case"comments":$(n.comments.containerSelector).load(n.comments.fetchUrl)}})()}};window.WorkerManager=new n})(window)