document.addEventListener('DOMContentLoaded',function(){const modal=document.getElementsByClassName('jetpack-subscription-modal')[0];if(!modal){return} const close=document.getElementsByClassName('jetpack-subscription-modal__close')[0];let redirectUrl='';let hasLoaded=!1;function reloadOnCloseSubscriptionModal(customUrl){const destinationUrl=customUrl?new URL(customUrl):new URL(redirectUrl);if(destinationUrl.hostname!==window.location.hostname){return} try{localStorage.setItem('jetpack-subscription-modal-on-comment-scroll-to',destinationUrl.hash)}catch{} destinationUrl.searchParams.set('_ctn',Date.now());window.location.href=destinationUrl.toString()} function JetpackSubscriptionModalOnCommentMessageListener(event){let message=event&&event.data;if(typeof message==='string'){try{message=JSON.parse(message)}catch{return}} const type=message&&message.type;const data=message&&message.data;if(type!=='subscriptionModalShow'||typeof data.url==='undefined'){return} if(subscriptionData.homeUrl!==event.origin){return} if(data.email){const emailInput=document.querySelector('.jetpack-subscription-modal__modal-content input[type="email"]');if(!emailInput){reloadOnCloseSubscriptionModal(data.url);return} const appSource=document.querySelector('.jetpack-subscription-modal__modal-content input[name="app_source"]');if(!appSource){reloadOnCloseSubscriptionModal(data.url);return} emailInput.value=data.email;if(data.is_logged_in){emailInput.setAttribute('readonly','readonly');appSource.value='atomic-subscription-modal-li'}} if(!hasLoaded){try{const storedCount=parseInt(sessionStorage.getItem('jetpack-subscription-modal-shown-count'));const showCount=(isNaN(storedCount)?0:storedCount)+1;sessionStorage.setItem('jetpack-subscription-modal-shown-count',showCount);if(showCount>5){new Image().src=document.location.protocol+'//pixel.wp.com/g.gif?v=wpcom-no-pv&x_jetpack-subscribe-modal-comm=hidden_views_limit&r='+Math.random();reloadOnCloseSubscriptionModal(data.url);return}}catch{} new Image().src=document.location.protocol+'//pixel.wp.com/g.gif?v=wpcom-no-pv&x_jetpack-subscribe-modal-comm=showed&r='+Math.random();modal.classList.toggle('open');hasLoaded=!0;redirectUrl=data.url}} window.addEventListener('message',JetpackSubscriptionModalOnCommentMessageListener);if(close){close.onclick=function(event){event.preventDefault();modal.classList.toggle('open');reloadOnCloseSubscriptionModal()}} window.onclick=function(event){if(event.target===modal){modal.style.display='none';reloadOnCloseSubscriptionModal()}};window.addEventListener('load',()=>{const subscriptionScroll=localStorage.getItem('jetpack-subscription-modal-on-comment-scroll-to');if(subscriptionScroll){window.location.hash=subscriptionScroll;localStorage.removeItem('jetpack-subscription-modal-on-comment-scroll-to');const comment=document.querySelector(subscriptionScroll);if(comment){comment.scrollIntoView({block:'center',behavior:'smooth'})}}})}); const{domReady}=wp;domReady(()=>{const modal=document.querySelector('.jetpack-subscribe-modal');const modalDismissedCookie='jetpack_post_subscribe_modal_dismissed';const skipUrlParam='jetpack_skip_subscription_popup';function hasEnoughTimePassed(){const lastDismissed=localStorage.getItem(modalDismissedCookie);return lastDismissed?Date.now()-lastDismissed>Jetpack_Subscriptions.modalInterval:!0} function skipModal(){const url=new URL(window.location.href);if(url.searchParams.has(skipUrlParam)){url.searchParams.delete(skipUrlParam);window.history.replaceState({},'',url);storeCloseTimestamp();return!0} return!1} if(!modal||!hasEnoughTimePassed()||skipModal()){return} const modalLoadTimeout=setTimeout(openModal,Jetpack_Subscriptions.modalLoadTime);const targetElement=(document.querySelector('.entry-content')||document.documentElement).getBoundingClientRect();function hasPassedScrollThreshold(){const scrollPosition=window.scrollY+window.innerHeight/2;const scrollPositionThreshold=targetElement.top+(targetElement.height*Jetpack_Subscriptions.modalScrollThreshold)/100;return scrollPosition>scrollPositionThreshold} function onScroll(){requestAnimationFrame(()=>{if(hasPassedScrollThreshold()){openModal()}})} window.addEventListener('scroll',onScroll,{passive:!0});function onLocalStorage(event){if(event.key===modalDismissedCookie){closeModal();removeEventListeners()}} window.addEventListener('storage',onLocalStorage);const form=modal.querySelector('form');if(form){form.addEventListener('subscription-modal-loaded',closeModal)} function onCloseButtonClick(event){event.preventDefault();closeModal()} const close=document.getElementsByClassName('jetpack-subscribe-modal__close')[0];if(close){close.addEventListener('click',onCloseButtonClick)} function closeOnWindowClick(event){if(event.target===modal){closeModal()}} function closeModalOnEscapeKeydown(event){if(event.key==='Escape'){closeModal()}} function openModal(){if(document.activeElement&&document.activeElement.tagName!=='BODY'){return} modal.classList.add('open');document.body.classList.add('jetpack-subscribe-modal-open');window.addEventListener('keydown',closeModalOnEscapeKeydown);window.addEventListener('click',closeOnWindowClick);removeEventListeners()} function closeModal(){modal.classList.remove('open');document.body.classList.remove('jetpack-subscribe-modal-open');window.removeEventListener('keydown',closeModalOnEscapeKeydown);window.removeEventListener('storage',onLocalStorage);window.removeEventListener('click',closeOnWindowClick);storeCloseTimestamp()} function removeEventListeners(){window.removeEventListener('scroll',onScroll);clearTimeout(modalLoadTimeout)} function storeCloseTimestamp(){localStorage.setItem(modalDismissedCookie,Date.now())}});