
define('wikia.pageviewsInSession',['wikia.window','wikia.document','wikia.cookies','wikia.sessionStorage','mw'],function(window,document,cookies,sessionStorage,mw){'use strict';var wikiaDomain=mw.config.get('wgCookieDomain'),pageviewsCookieName='pageviewsInSession',opentabsNumberCookieName='openTabsNumber',wikiPageShownSessionKey='wasWikiPageShownInCurrentTab',cookieOptions={domain:wikiaDomain,path:mw.config.get('wgCookiePath')};function init(){increaseNumberOfOpenTabs();setPageviewsCount();window.addEventListener('unload',function(){decreaseNumberOfOpenTabs();sessionStorage.setItem(wikiPageShownSessionKey,true);});}
function getPageviewsCount(){var pageviews=cookies.get(pageviewsCookieName);return pageviews?parseInt(pageviews):0;}
function setPageviewsCount(){if(isUserFirstPageview()){clearPageviewsCount();}
cookies.set(pageviewsCookieName,getPageviewsCount()+1,cookieOptions);}
function clearPageviewsCount(){cookies.set(pageviewsCookieName,0,cookieOptions);}
function getNumberOfOpenTabs(){var opentabs=cookies.get(opentabsNumberCookieName);return opentabs?parseInt(opentabs):0;}
function increaseNumberOfOpenTabs(){setNumberOfOpenTabs(getNumberOfOpenTabs()+1);}
function decreaseNumberOfOpenTabs(){setNumberOfOpenTabs(getNumberOfOpenTabs()-1);}
function setNumberOfOpenTabs(numberOfTabs){cookies.set(opentabsNumberCookieName,numberOfTabs,cookieOptions);}
function isUserFirstPageview(){var lastUrl=document.referrer;return(getNumberOfOpenTabs()===1&&!sessionStorage.getItem(wikiPageShownSessionKey)&&(!lastUrl||!hasWikiaDomain(lastUrl)));}
function hasWikiaDomain(url){var hostname=getUrlHostname(url);if(hostname.indexOf('.')!==-1){return hostname.substr(hostname.length-wikiaDomain.length)===wikiaDomain;}
return false;}
function getUrlHostname(url){var location=document.createElement('a');location.href=url;return location.hostname;}
init();return{getPageviewsCount:getPageviewsCount}});;define('wikia.sessionStorage',['wikia.window'],function(window){'use strict';try{return window.sessionStorage;}catch(err){return{};}});;define('CommunityPageBenefitsModal',['jquery','wikia.loader','mw','wikia.mustache','wikia.tracker','wikia.nirvana','wikia.cookies'],function($,loader,mw,mustache,tracker,nirvana,cookies){'use strict';var modalConfig={vars:{id:'CommunityPageBenefitsModal',classes:['community-page-benefits-modal'],size:'content-size'}},specialCommunityTitle=new mw.Title('Community',-1),track=tracker.buildTrackingFunction({action:tracker.ACTIONS.CLICK,category:'community-page-benefits-modal',trackingMethod:'analytics'});function openModal(){$.when(loader({type:loader.MULTI,resources:{mustache:'extensions/wikia/CommunityPage/templates/benefitsModal.mustache',messages:'CommunityPageBenefits'}}),nirvana.sendRequest({controller:'CommunityPageSpecial',method:'getBenefitsModalData',type:'get',format:'json'})).then(handleRequestsForModal);}
function handleRequestsForModal(loaderRes,nirvanaRes){var wikiTopic=nirvanaRes[0].wikiTopic,allMembersCount=nirvanaRes[0].memberCount,modalImageUrl=nirvanaRes[0].modalImageUrl,image=new Image();mw.messages.set(loaderRes.messages);modalConfig.vars.content=mustache.render(loaderRes.mustache[0],{mainTitle:mw.message('communitypage-entrypoint-modal-title',wikiTopic,allMembersCount).plain(),editSubtitle:mw.message('communitypage-entrypoint-modal-edit-title').plain(),connectSubtitle:mw.message('communitypage-entrypoint-modal-connect-title').plain(),exploreSubtitle:mw.message('communitypage-entrypoint-modal-explore-title').plain(),editText:mw.message('communitypage-entrypoint-modal-edit-text',wikiTopic).plain(),connectText:mw.message('communitypage-entrypoint-modal-connect-text',wikiTopic).plain(),exploreText:mw.message('communitypage-entrypoint-modal-explore-text',wikiTopic).plain(),buttonText:mw.message('communitypage-entrypoint-modal-button-text').plain(),buttonUrl:specialCommunityTitle.getUrl(),benefitsImageUrl:modalImageUrl});image.onload=image.onerror=function(){require(['wikia.ui.factory'],function(uiFactory){uiFactory.init(['modal']).then(createComponent);});};image.src=modalImageUrl;}
function createComponent(uiModal){uiModal.createComponent(modalConfig,processInstance);}
function processInstance(modalInstance){modalInstance.show();track({action:tracker.ACTIONS.IMPRESSION,label:'benefits-modal-shown'});modalInstance.$element.on('mousedown',function(e){track({label:$(e.target).data('track')||'modal-area'});if(e.target.title!=='close'){cookies.set('cpBenefitsModalClicked',1,{domain:mw.config.get('wgCookieDomain'),expires:2592000000,path:mw.config.get('wgCookiePath')});}});modalInstance.bind('close',function(){track({action:tracker.ACTIONS.CLOSE,label:'modal-closed'});});setModalShownCookie();}
function setModalShownCookie(){cookies.set('cpBenefitsModalShown',getTimestamp(),{domain:mw.config.get('wgCookieDomain'),expires:2592000000,path:mw.config.get('wgCookiePath')});}
function getTimestamp(){return(new Date()).toISOString().substr(0,19).replace('T',' ');}
return{open:openModal};});;require(['wikia.pageviewsInSession','CommunityPageBenefitsModal','wikia.cookies'],function(pageviews,modal,cookies){'use strict';function init(){if(!cookies.get('cpBenefitsModalShown')&&pageviews.getPageviewsCount()>=4){modal.open();}}
init();});;