/* global subscriptionData */
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 = false;
function reloadOnCloseSubscriptionModal( customUrl ) {
const destinationUrl = customUrl ? new URL( customUrl ) : new URL( redirectUrl );
// Prevent redirect to external sites.
if ( destinationUrl.hostname !== window.location.hostname ) {
return;
}
try {
localStorage.setItem(
'jetpack-subscription-modal-on-comment-scroll-to',
destinationUrl.hash
);
} catch {
// Ok if we can't set it.
}
// Add cache-busting parameter
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 {
// Ignore any errors.
}
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 = true;
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', () => {
// Scroll to the last comment.
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' } );
}
}
} );
} );
;
(()=>{var e=[],t=!1,i=[],n=new Promise((e=>{"loading"!==document.readyState?e():window.addEventListener("DOMContentLoaded",(()=>e()))}));function o(e,t){if("string"==typeof e)try{e=JSON.parse(e)}catch{return}if(t&&"function"==typeof t.postMessage)try{t.postMessage(JSON.stringify({type:"likesMessage",data:e}),"*")}catch{}}function s(){const t=[];document.querySelectorAll("div.jetpack-likes-widget-unloaded").forEach((i=>{if(!(e.indexOf(i.id)>-1)&&c(i)){e.push(i.id);var n,o=/like-(post|comment)-wrapper-(\d+)-(\d+)-(\w+)/.exec(i.id);o&&5===o.length&&(n={blog_id:o[2],width:i.width},"post"===o[1]?n.post_id=o[3]:"comment"===o[1]&&(n.comment_id=o[3]),n.obj_id=o[4],t.push(n))}})),t.length>0&&o({event:"initialBatch",requests:t},window.frames["likes-master"])}function a(){const e=document.querySelector("#likes-other-gravatars");if(e){e.style.display="none",e.setAttribute("aria-hidden","true");const t=e.__resizeHandler;t&&(window.removeEventListener("resize",t),delete e.__resizeHandler)}}function r(){var e;if(t){!function(){for(let e=i.length-1;e>=0;e--){const t=i[e];if(!c(t)){const n=t&&t.parentElement&&t.parentElement.parentElement;n.classList.remove("jetpack-likes-widget-loaded"),n.classList.remove("jetpack-likes-widget-loading"),n.classList.add("jetpack-likes-widget-unloaded"),i.splice(e,1),t.remove()}}}();var n=[...document.querySelectorAll("div.jetpack-likes-widget-unloaded")].filter((e=>c(e)));n.length>0&&s();for(var o=0,a=n.length;o<=a-1;o++)(e=n[o].id)&&l(e)}else setTimeout(r,500)}function l(e){if(void 0===e)return;const t=document.querySelector("#"+e);t.querySelectorAll("iframe").forEach((e=>e.remove()));const n=t.querySelector(".likes-widget-placeholder");if(n&&n.classList.contains("post-likes-widget-placeholder")){const e=document.createElement("iframe");e.classList.add("post-likes-widget","jetpack-likes-widget"),e.name=t.dataset.name,e.src=t.dataset.src,e.height="55px",e.width="100%",e.frameBorder="0",e.scrolling="no",e.title=t.dataset.title,n.after(e)}if(n.classList.contains("comment-likes-widget-placeholder")){const e=document.createElement("iframe");e.class="comment-likes-widget-frame jetpack-likes-widget-frame",e.name=t.dataset.name,e.src=t.dataset.src,e.height="18px",e.width="100%",e.frameBorder="0",e.scrolling="no",t.querySelector(".comment-like-feedback").after(e),i.push(e)}t.classList.remove("jetpack-likes-widget-unloaded"),t.classList.add("jetpack-likes-widget-loading"),t.querySelector("iframe").addEventListener("load",(e=>{o({event:"loadLikeWidget",name:e.target.name,width:e.target.width},window.frames["likes-master"]),t.classList.remove("jetpack-likes-widget-loading"),t.classList.add("jetpack-likes-widget-loaded")}))}function c(e){const t=e.getBoundingClientRect().top,i=e.getBoundingClientRect().bottom;return t+2e3>=0&&i<=window.innerHeight+2e3}window.addEventListener("message",(function(e){let i=e&&e.data;if("string"==typeof i)try{i=JSON.parse(i)}catch{return}const r=i&&i.type,l=i&&i.data;if("likesMessage"!==r||void 0===l.event)return;if("https://widgets.wp.com"===e.origin)switch(l.event){case"masterReady":n.then((()=>{t=!0;const e={event:"injectStyles"},i=document.querySelector(".sd-text-color"),n=document.querySelector(".sd-link-color"),a=i&&getComputedStyle(i)||{},r=n&&getComputedStyle(n)||{};document.body.classList.contains("single")&&o({event:"reblogsEnabled"},window.frames["likes-master"]),e.textStyles={color:a.color,fontFamily:a["font-family"],fontSize:a["font-size"],direction:a.direction,fontWeight:a["font-weight"],fontStyle:a["font-style"],textDecoration:a["text-decoration"]},e.linkStyles={color:r.color,fontFamily:r["font-family"],fontSize:r["font-size"],textDecoration:r["text-decoration"],fontWeight:r["font-weight"],fontStyle:r["font-style"]},o(e,window.frames["likes-master"]),s()}));break;case"showLikeWidget":case"showCommentLikeWidget":break;case"killCommentLikes":document.querySelectorAll(".jetpack-comment-likes-widget-wrapper").forEach((e=>e.remove()));break;case"clickReblogFlair":wpcom_reblog&&"function"==typeof wpcom_reblog.toggle_reblog_box_flair&&wpcom_reblog.toggle_reblog_box_flair(l.obj_id);break;case"hideOtherGravatars":a();break;case"showOtherGravatars":{const e=document.querySelector("#likes-other-gravatars");if(!e)break;const t=e.querySelector("ul");e.style.display="none",t.innerHTML="",e.querySelectorAll(".likes-text span").forEach((e=>e.textContent=l.totalLikesLabel)),(l.likers||[]).forEach((async(e,i)=>{if("http"!==e.profile_URL.substr(0,4))return;const n=document.createElement("li");t.append(n);const s=encodeURI(e.profile_URL),r=encodeURI(e.avatar_URL);n.innerHTML=`\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t`,n.classList.add(e.css_class),n.querySelector("img").alt=l.avatarAltTitle.replace("%s",e.name),n.querySelector("span").innerText=e.name,i===l.likers.length-1&&n.addEventListener("keydown",(e=>{"Tab"!==e.key||e.shiftKey||(e.preventDefault(),a(),o({event:"focusLikesCount",parent:l.parent},window.frames["likes-master"]))}))}));const i=function(){const t="rtl"===getComputedStyle(e).direction,i=document.querySelector(`*[name='${l.parent}']`),n=i.getBoundingClientRect(),o=i.ownerDocument.defaultView,s=n.top+o.pageYOffset,a=n.left+o.pageXOffset;let r=0;if(e.style.top=s+l.position.top-1+"px",t){const t=l&&l.likers?Math.min(l.likers.length,5):0;r=a+l.position.left+24*t+4,e.style.transform="translateX(-100%)"}else r=a+l.position.left;e.style.left=r+"px";const c=l.width-20,d=Math.floor(c/37);let f=37*Math.ceil(l.likers.length/d)+17+22;f>204&&(f=204),e.style.left="-9999px",e.style.display="block";const m=e.offsetWidth;r+m>o.innerWidth&&(r=n.right-m),e.style.left=r+"px",e.setAttribute("aria-hidden","false")};i(),e.focus();const n=function(e,t){var i;return function(){var n=this,o=arguments;clearTimeout(i),i=setTimeout((function(){e.apply(n,o)}),t)}},s=n(i,100);e.__resizeHandler=s,window.addEventListener("resize",s),e.focus()}}})),document.addEventListener("click",a);var d,f,m,p=(d=250,f=r,function(){clearTimeout(m),m=setTimeout(f,d)});r(),window.addEventListener("scroll",p,!0)})();;
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.sbjs=e()}}(function(){return function e(t,r,n){function a(s,o){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var p=r[s]={exports:{}};t[s][0].call(p.exports,function(e){var r=t[s][1][e];return a(r||e)},p,p.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s0))return r=s.getHost(e),!0;for(var t=0;t0)for(var i=0;i0)for(var s=0;se.split(".").reduce((t,e)=>t&&t[e],t)),i=()=>null,s=t=>null===t||t===undefined?"":t,o="wc/store/checkout";function a(t){window.wp&&window.wp.data&&window.wp.data.dispatch&&window.wc&&window.wc.wcBlocksData&&window.wp.data.dispatch(window.wc.wcBlocksData.CHECKOUT_STORE_KEY).__internalSetExtensionData("woocommerce/order-attribution",t,!0)}function r(){return"undefined"!=typeof sbjs}function c(){if(window.wp&&window.wp.data&&"function"==typeof window.wp.data.subscribe){const e=window.wp.data.subscribe(function(){e(),a(t.getAttributionData())},o)}}t.getAttributionData=function(){const s=e.allowTracking&&r()?n:i,o=r()?sbjs.get:{},a=Object.entries(t.fields).map(([t,e])=>[t,s(o,e)]);return Object.fromEntries(a)},t.setOrderTracking=function(n){if(e.allowTracking=n,n){if(!r())return;sbjs.init({lifetime:Number(e.lifetime),session_length:Number(e.session),base64:Boolean(e.base64),timezone_offset:"0"})}else!function(){const t=window.location.hostname;["sbjs_current","sbjs_current_add","sbjs_first","sbjs_first_add","sbjs_session","sbjs_udata","sbjs_migrations","sbjs_promo"].forEach(e=>{document.cookie=`${e}=; path=/; max-age=-999; domain=.${t};`})}();const i=t.getAttributionData();!function(t){for(const e of document.querySelectorAll("wc-order-attribution-inputs"))e.values=t}(i),a(i)},t.setOrderTracking(e.allowTracking),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c):c(),window.customElements.define("wc-order-attribution-inputs",class extends HTMLElement{constructor(){if(super(),this._fieldNames=Object.keys(t.fields),this.hasOwnProperty("_values")){let t=this.values;delete this.values,this.values=t||{}}}connectedCallback(){this.innerHTML="";const t=new DocumentFragment;for(const n of this._fieldNames){const i=document.createElement("input");i.type="hidden",i.name=`${e.prefix}${n}`,i.value=s(this.values&&this.values[n]||""),t.appendChild(i)}this.appendChild(t)}set values(t){if(this._values=t,this.isConnected)for(const t of this._fieldNames){const n=this.querySelector(`input[name="${e.prefix}${t}"]`);n?n.value=s(this.values[t]):console.warn(`Field "${t}" not found. `+"Most likely, the '' element was manipulated.")}}get values(){return this._values}})}(window.wc_order_attribution);;