@automattic/newspack-blocks
Advanced tools
Comparing version 4.3.0-epic-ras-acc.9 to 4.3.0-epic-ras-acc.10
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";function e(e,t=!1){const n=e.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');if(0===n.length)return!1;const o=n?.[0];let c;o.focus(),t?(document.addEventListener("keydown",(function(e){if(("Tab"===e.key||9===e.keyCode)&&e.shiftKey&&document.activeElement===o){const n=t.contentWindow.document,o=n.getElementById("customer_details"),a=n.getElementById("after_customer_details"),r=n.getElementById("checkout-after-success");null!==r?c=r:null!==o.offsetParent?c=n.getElementById("checkout_continue"):null!==a.offsetParent&&(c=n.getElementById("checkout_back")),c.focus(),e.preventDefault()}})),document.getElementById("newspack-a11y-last-element").addEventListener("focus",(()=>{o.focus()}))):(c=n[n.length-1],document.addEventListener("keydown",(function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement===o&&(c.focus(),e.preventDefault()):document.activeElement===c&&(o.focus(),e.preventDefault()))})))}const t=(e,t={})=>({...t,action:e}),n=(e,t="np_modal_checkout_interaction")=>{"function"==typeof window.gtag&&e&&window.gtag("event",t,e)},o=(e="")=>{if("function"!=typeof window.gtag)return;let o="opened";const{action_type:c,amount:a="",currency:r,is_variable:i="",price:s="",product_id:l,product_type:d,recurrence:u,referrer:p,variation_id:_=""}=e,m={action_type:c,currency:r,product_id:l,product_type:d,referrer:p};(a||s)&&(m.amount=a||s),i&&(m.is_variable=i),_&&(m.variation_id=_),u&&(m.recurrence=u),i&&!_&&(o="opened_variations");const y=t(o,m);n(y)};function c(e,t=null){const n=document.createElement("input");return n.type="hidden",n.name=e,t&&(n.value=t),n}const a=newspackBlocksModal.newspack_class_prefix,r="newspack_modal_checkout_iframe",i="newspack_modal_checkout_container",s=`${a}__modal`,l="newspack-blocks__modal-variation";let d={};var u;u=()=>{const u=document.querySelector("#newspack_modal_checkout");if(!u)return;const p=u.querySelector(`.${s}__content`),_=c("modal_checkout","1"),m=p.querySelector(`.${a}__spinner`);let y=document.querySelector(".newspack-reader__account-link")?.[0];const f="600px",h=document.createElement("iframe");function w(){const t=h.contentWindow.location;if(window.newspackReaderActivation&&t.href.indexOf("order-received")>-1){const e=window.newspackReaderActivation,n=new Proxy(new URLSearchParams(t.search),{get:(e,t)=>e.get(t)});n.email&&(e.setReaderEmail(n.email),e.setAuthenticated(!0))}const n=h?.contentDocument?.querySelector(`#${i}`),o=()=>{g.observe(n),"none"!==m.style.display&&(m.style.display="none"),"visible"!==h.style.visibility&&(h.style.visibility="visible"),h._ready=!0};n&&(n.checkoutComplete?($("small"),A(newspackBlocksModal.labels.thankyou_modal_title),o(),e(u.querySelector(`.${s}`))):($(),A(newspackBlocksModal.labels.checkout_modal_title)),n.checkoutReady?o():n.addEventListener("checkout-ready",o))}h.name=r,h.style.height=f,h.style.visibility="hidden",h.addEventListener("load",w);const k=t=>{const n=t.target;n.classList.add("modal-processing");const i=n.dataset.product;if(i){const e=JSON.parse(i);Object.keys(e).forEach((t=>{0===n.querySelectorAll('input[name="'+t+'"]').length&&n.appendChild(c(t,e[t]))}))}const s=new FormData(n);s.get("variation_id")||(y=t.submitter);const u=document.querySelectorAll(`.${l}`);if(u.forEach((e=>{E(e)})),s.get("is_variable")&&!s.get("variation_id")){const a=[...u].find((e=>e.dataset.productId===s.get("product_id")));if(a){a.querySelectorAll(`form[target="${r}"]`).forEach((e=>{["after_success_behavior","after_success_url","after_success_button_label"].forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.appendChild(c(t,s.get(t)))}));const t=e.dataset.product;if(t){const n=JSON.parse(t);Object.keys(n).forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.appendChild(c(t,n[t]))}))}})),t.preventDefault(),n.classList.remove("modal-processing"),q(a),e(a,!1);const i=n.getAttribute("data-product");return d=i?JSON.parse(i):{},o(d),void document.getElementById("newspack_modal_checkout").setAttribute("data-order-details",JSON.stringify(d))}}n.classList.remove("modal-processing");const p=s.get("newspack_donate"),_=s.get("newspack_checkout");if(_){const e=n.getAttribute("data-product");d=e?JSON.parse(e):{}}else if(p){const e=s.get("donation_frequency");let t="",n="";for(const n of s.keys())n.indexOf("donation_value_"+e)>=0&&"other"!==s.get(n)&&""!==s.get(n)&&(t=s.get(n));const o=JSON.parse(s.get("frequency_ids"));for(const t in o)t===e&&(n=o[t].toString());d={amount:t,action_type:"donation",currency:s.get("donation_currency"),product_id:n,product_type:"donation",recurrence:e,referrer:s.get("_wp_http_referer")}}if("undefined"==typeof newspack_ras_config||newspack_ras_config?.is_logged_in||window?.newspackReaderActivation?.getReader?.()?.authenticated||!window?.newspackReaderActivation?.openAuthModal)S(),o(d),document.getElementById("newspack_modal_checkout").setAttribute("data-order-details",JSON.stringify(d));else{t.preventDefault();let e="",o="0",c="";if(p){const e=s.get("donation_frequency"),t=n.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`);if(t?.length){const a=n.querySelectorAll(`input[name="donation_value_${e}"], input[name="donation_value_${e}_untiered"]`);if(a?.length)a.forEach((e=>{e.checked&&"other"!==e.value&&(o=e.value)})),t.forEach((t=>{const n=JSON.parse(t.dataset.product);if(n.hasOwnProperty(`donation_price_summary_${e}`)&&n?.[`donation_price_summary_${e}`].includes(o)&&(c=n[`donation_price_summary_${e}`]),"0"===o&&c){let t=s.get(`donation_value_${e}_other`);t||(t=s.get(`donation_value_${e}_untiered`)),t&&(c=c.replace("0",t))}}));else{const n=s.get("donation_tier_index");if(n){const o=JSON.parse(t?.[n].dataset.product);o.hasOwnProperty(`donation_price_summary_${e}`)&&(c=o[`donation_price_summary_${e}`])}}}}else if(_){const e=n.querySelector('input[name="product_price_summary"]');e&&(c=e.value)}c&&(e=`<div class="order-details-summary ${a}__box ${a}__box--text-center"><p><strong>${c}</strong></p></div>`);const r=(e=>new Promise(((t,n)=>{const o=new URLSearchParams(e);o.append("action","modal_checkout_request"),fetch(newspackBlocksModal.ajax_url+"?"+o.toString()).then((e=>{e.ok||n(e),e.json().then((e=>{t(e.url)})).catch(n)})).catch(n)})))(s);r.then((e=>{window.newspackReaderActivation?.setPendingCheckout?.(e)})),window.newspackReaderActivation.openAuthModal({title:newspackBlocksModal.labels.auth_modal_title,callback:(e,t)=>{r.then((e=>{t?.registered&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`);const n=v(e);L(n)})).catch((e=>{console.warn("Unable to generate cart:",e),b()}))},skipSuccess:!0,skipNewslettersSignup:!0,labels:{signin:{title:newspackBlocksModal.labels.signin_modal_title},register:{title:newspackBlocksModal.labels.register_modal_title}},content:e,trigger:t.submitter})}},v=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=r,t.style.display="none";const n=document.createElement("button");return n.setAttribute("type","submit"),t.appendChild(n),document.body.appendChild(t),t.addEventListener("submit",k),t},g=new ResizeObserver((e=>{if(!e||!e.length)return;const t=e[0].contentRect;if(t){const e=t.top+t.bottom;if(0===e)return void(h.style.visibility="hidden");p.style.height=e+"px",h.style.height=e+"px"}})),b=()=>{const e=h?.contentDocument?.querySelector(`#${i}`),o=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal"),r=!o||!c||!e?.checkoutComplete;if((r||a)&&(m.style.display="flex",h&&p.contains(h)&&(h._ready=!1,h.src="about:blank",h.style.height=f,h.style.visibility="hidden",p.style.height=f,p.removeChild(h)),g&&g.disconnect(),document.querySelectorAll(`.${s}-container`).forEach((e=>E(e))),y&&y.focus()),e?.checkoutComplete){const e=()=>{if(o&&c){const e=o.getAttribute("value"),t=c.getAttribute("value");"custom"===t?window.location.href=e:"referrer"===t&&window.history.back()}window?.newspackReaderActivation?.setPendingCheckout?.()};window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({callback:e,closeOnSuccess:r}):e(),r&&($(),A(newspackBlocksModal.labels.checkout_modal_title))}else window?.newspackReaderActivation?.setPendingCheckout?.(),(()=>{if("function"!=typeof window.gtag)return;const{action_type:e,amount:o="",currency:c,price:a="",product_id:r,product_type:i,recurrence:s,referrer:l,variation_id:d=""}=(e=>{const t=document.getElementById("newspack_modal_checkout"),n=!!t&&t.getAttribute("data-order-details");return!!n&&JSON.parse(n)||{}})(),u={action_type:e,currency:c,product_id:r,product_type:i,recurrence:s,referrer:l};(o||a)&&(u.amount=o||a),d&&(u.variation_id=d);const p=t("dismissed",u);n(p)})(),document.getElementById("newspack_modal_checkout").removeAttribute("data-order-details")},S=()=>{m.style.display="flex",q(u),p.appendChild(h),u.addEventListener("click",(e=>{e.target===u&&b()})),e(u,h),function(e){h._readyTimer&&clearTimeout(h._readyTimer);let t=!1;function n(){t||(t=!0,clearTimeout(h._readyTimer),e.call(this))}function o(){"complete"===this.readyState&&n.call(this)}!function e(){if(h._ready)return void clearTimeout(h._readyTimer);const t=h.contentDocument||h.contentWindow?.document;t&&0!==t.URL.indexOf("about:")?"complete"===t?.readyState?n.call(t):(t.addEventListener("DOMContentLoaded",n),t.addEventListener("readystatechange",o)):h._readyTimer=setTimeout(e,10)}()}(w)},E=e=>{e.overlayId&&window.newspackReaderActivation?.overlays&&window.newspackReaderActivation?.overlays.remove(e.overlayId),e.setAttribute("data-state","closed"),document.body.style.overflow="auto"},q=e=>{window.newspackReaderActivation?.overlays&&(u.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},A=e=>{const t=u.querySelector(`.${s}__header h2`);t&&(t.innerText=e)},$=(e="default")=>{const t=u.querySelector(`.${s}`);t&&("small"===e?t.classList.add(`${s}--small`):t.classList.remove(`${s}--small`))};window.newspackCloseModalCheckout=b,u.querySelectorAll(`.${s}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),b()}))})),document.querySelectorAll(".newspack-blocks__modal-variation").forEach((e=>{e.addEventListener("click",(t=>{t.target===e&&b()})),e.querySelectorAll(`.${s}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),b()}))}))})),document.addEventListener("keydown",(function(e){"Escape"===e.key&&b()})),document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation").forEach((e=>{e.querySelectorAll("form").forEach((e=>{e.appendChild(_.cloneNode()),e.target=r,e.addEventListener("submit",k)}))}));const L=e=>{e.requestSubmit(e.querySelector('button[type="submit"]'))};(()=>{const e=new URLSearchParams(window.location.search);if(!e.has("checkout"))return;const t=e.get("type");if("donate"===t){const t=e.get("layout"),n=e.get("frequency"),o=e.get("amount"),c=e.get("other");t&&n&&o&&((e,t,n,o=null)=>{let c;document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc form").forEach((a=>{const r=a.querySelector(`input[name="donation_frequency"][value="${t}"]`);if(r)if("tiered"===e){const e=document.querySelector(`button[data-frequency-slug="${t}"]`);if(!e)return;e.click();const o=a.querySelector(`button[type="submit"][name="donation_value_${t}"][value="${n}"]`);if(!o)return;o.click()}else{const i="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${n}"]`);if(r&&i){if(r.checked=!0,"untiered"===e)i.value=n;else if("other"===n){i.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&o&&(e.value=o)}else i.checked=!0;c=a}}})),c&&L(c)})(t,n,o,c)}else if("checkout_button"===t){const t=e.get("product_id"),n=e.get("variation_id");t&&((e,t=null)=>{let n;if(t&&t!==e){const o=[...document.querySelectorAll(`.${l}`)].find((t=>t.dataset.productId===e));o&&o.querySelectorAll(`form[target="${r}"]`).forEach((e=>{const o=JSON.parse(e.dataset.product);o?.variation_id===Number(t)&&(n=e)}))}else document.querySelectorAll(".wp-block-newspack-blocks-checkout-button").forEach((t=>{const o=t.querySelector("form");if(!o)return;const c=JSON.parse(o.dataset.product);c?.product_id===e&&(n=o)}));n&&L(n)})(t,n)}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();if(e){const t=v(e);L(t)}}window.history.replaceState(null,null,window.location.pathname)})()},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",u):u())})(); | ||
(()=>{"use strict";function e(e,t=!1){const n=e.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');if(0===n.length)return!1;const o=n?.[0];let c;o.focus(),t?(document.addEventListener("keydown",(function(e){if(("Tab"===e.key||9===e.keyCode)&&e.shiftKey&&document.activeElement===o){const n=t.contentWindow.document,o=n.getElementById("customer_details"),a=n.getElementById("after_customer_details"),r=n.getElementById("checkout-after-success");null!==r?c=r:null!==o.offsetParent?c=n.getElementById("checkout_continue"):null!==a.offsetParent&&(c=n.getElementById("checkout_back")),c.focus(),e.preventDefault()}})),document.getElementById("newspack-a11y-last-element").addEventListener("focus",(()=>{o.focus()}))):(c=n[n.length-1],document.addEventListener("keydown",(function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement===o&&(c.focus(),e.preventDefault()):document.activeElement===c&&(o.focus(),e.preventDefault()))})))}const t=(e,t={})=>({...t,action:e}),n=(e,t="np_modal_checkout_interaction")=>{"function"==typeof window.gtag&&e&&window.gtag("event",t,e)},o=e=>{if("function"!=typeof window.gtag)return;let o="opened";const{action_type:c,amount:a="",currency:r,is_variable:i="",price:s="",product_id:d,product_type:l,recurrence:u,referrer:p,variation_id:_=""}=e,m={action_type:c,currency:r,product_id:d,product_type:l,referrer:p};(a||s)&&(m.amount=a||s),i&&(m.is_variable=i),_&&(m.variation_id=_),u&&(m.recurrence=u),i&&!_&&(o="opened_variations");const y=t(o,m);n(y)},c=e=>{if("function"!=typeof window.gtag)return;e=e||(e=>{const t=document.getElementById("newspack_modal_checkout"),n=!!t&&t.getAttribute("data-order-details");return!!n&&JSON.parse(n)||{}})();const{action_type:o,amount:c="",currency:a,price:r="",product_id:i,product_type:s,recurrence:d,referrer:l,variation_id:u=""}=e,p={action_type:o,currency:a,product_id:i,product_type:s,recurrence:d,referrer:l};(c||r)&&(p.amount=c||r),u&&(p.variation_id=u);const _=t("dismissed",p);n(_)};function a(e,t=null){const n=document.createElement("input");return n.type="hidden",n.name=e,t&&(n.value=t),n}const r=newspackBlocksModal.newspack_class_prefix,i="newspack_modal_checkout_iframe",s="newspack_modal_checkout_container",d=`${r}__modal`,l="newspack-blocks__modal-variation";let u={},p=!1;var _;_=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const n=t.querySelector(`.${d}__content`),_=a("modal_checkout","1"),m=n.querySelector(`.${r}__spinner`);let y=document.querySelector(".newspack-reader__account-link")?.[0];const f="600px",h=document.createElement("iframe");function w(){const n=h.contentWindow.location;if(window.newspackReaderActivation&&n.href.indexOf("order-received")>-1){const e=window.newspackReaderActivation,t=new Proxy(new URLSearchParams(n.search),{get:(e,t)=>e.get(t)});t.email&&(e.setReaderEmail(t.email),e.setAuthenticated(!0))}const o=h?.contentDocument?.querySelector(`#${s}`),c=()=>{g.observe(o),"none"!==m.style.display&&(m.style.display="none"),"visible"!==h.style.visibility&&(h.style.visibility="visible"),h._ready=!0};o&&(o.checkoutComplete?($("small"),A(newspackBlocksModal.labels.thankyou_modal_title),c(),e(t.querySelector(`.${d}`))):($(),A(newspackBlocksModal.labels.checkout_modal_title)),o.checkoutReady?c():o.addEventListener("checkout-ready",c))}h.name=i,h.style.height=f,h.style.visibility="hidden",h.addEventListener("load",w);const k=t=>{const n=t.target;n.classList.add("modal-processing");const s=n.dataset.product;if(s){const e=JSON.parse(s);Object.keys(e).forEach((t=>{0===n.querySelectorAll('input[name="'+t+'"]').length&&n.appendChild(a(t,e[t]))}))}const d=new FormData(n);d.get("variation_id")||(y=t.submitter);const _=document.querySelectorAll(`.${l}`);if(_.forEach((e=>{E(e)})),d.get("is_variable")&&!d.get("variation_id")){const c=[..._].find((e=>e.dataset.productId===d.get("product_id")));if(c){c.querySelectorAll(`form[target="${i}"]`).forEach((e=>{["after_success_behavior","after_success_url","after_success_button_label"].forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.appendChild(a(t,d.get(t)))}));const t=e.dataset.product;if(t){const n=JSON.parse(t);Object.keys(n).forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.appendChild(a(t,n[t]))}))}})),t.preventDefault(),n.classList.remove("modal-processing"),q(c),e(c,!1);const r=n.getAttribute("data-product");return u=r?JSON.parse(r):{},p||o(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-order-details",JSON.stringify(u))}}n.classList.remove("modal-processing");const m=d.get("newspack_donate"),f=d.get("newspack_checkout");if(f){const e=n.getAttribute("data-product");u=e?JSON.parse(e):{}}else if(m){const e=d.get("donation_frequency");let t="",n="";for(const n of d.keys())n.indexOf("donation_value_"+e)>=0&&"other"!==d.get(n)&&""!==d.get(n)&&(t=d.get(n));const o=JSON.parse(d.get("frequency_ids"));for(const t in o)t===e&&(n=o[t].toString());u={amount:t,action_type:"donation",currency:d.get("donation_currency"),product_id:n,product_type:"donation",recurrence:e,referrer:d.get("_wp_http_referer")}}if(p||o(u),p=!0,"undefined"==typeof newspack_ras_config||newspack_ras_config?.is_logged_in||window?.newspackReaderActivation?.getReader?.()?.authenticated||!window?.newspackReaderActivation?.openAuthModal)S(),document.getElementById("newspack_modal_checkout").setAttribute("data-order-details",JSON.stringify(u));else{t.preventDefault();let e="",o="0",a="";if(m){const e=d.get("donation_frequency"),t=n.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`);if(t?.length){const c=n.querySelectorAll(`input[name="donation_value_${e}"], input[name="donation_value_${e}_untiered"]`);if(c?.length)c.forEach((e=>{e.checked&&"other"!==e.value&&(o=e.value)})),t.forEach((t=>{const n=JSON.parse(t.dataset.product);if(n.hasOwnProperty(`donation_price_summary_${e}`)&&n?.[`donation_price_summary_${e}`].includes(o)&&(a=n[`donation_price_summary_${e}`]),"0"===o&&a){let t=d.get(`donation_value_${e}_other`);t||(t=d.get(`donation_value_${e}_untiered`)),t&&(a=a.replace("0",t))}}));else{const n=d.get("donation_tier_index");if(n){const o=JSON.parse(t?.[n].dataset.product);o.hasOwnProperty(`donation_price_summary_${e}`)&&(a=o[`donation_price_summary_${e}`])}}}}else if(f){const e=n.querySelector('input[name="product_price_summary"]');e&&(a=e.value)}a&&(e=`<div class="order-details-summary ${r}__box ${r}__box--text-center"><p><strong>${a}</strong></p></div>`);const i=(e=>new Promise(((t,n)=>{const o=new URLSearchParams(e);o.append("action","modal_checkout_request"),fetch(newspackBlocksModal.ajax_url+"?"+o.toString()).then((e=>{e.ok||n(e),e.json().then((e=>{t(e.url)})).catch(n)})).catch(n)})))(d);i.then((e=>{window.newspackReaderActivation?.setPendingCheckout?.(e)})),window.newspackReaderActivation.openAuthModal({title:newspackBlocksModal.labels.auth_modal_title,onSuccess:(e,t)=>{i.then((e=>{t?.registered&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`);const n=v(e);L(n)})).catch((e=>{console.warn("Unable to generate cart:",e),b()}))},onError:()=>{b()},onDismiss:()=>{c(u),p=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-order-details")},skipSuccess:!0,skipNewslettersSignup:!0,labels:{signin:{title:newspackBlocksModal.labels.signin_modal_title},register:{title:newspackBlocksModal.labels.register_modal_title}},content:e,trigger:t.submitter})}},v=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=i,t.style.display="none";const n=document.createElement("button");return n.setAttribute("type","submit"),t.appendChild(n),document.body.appendChild(t),t.addEventListener("submit",k),t},g=new ResizeObserver((e=>{if(!e||!e.length)return;const t=e[0].contentRect;if(t){const e=t.top+t.bottom;if(0===e)return void(h.style.visibility="hidden");n.style.height=e+"px",h.style.height=e+"px"}})),b=()=>{const e=h?.contentDocument?.querySelector(`#${s}`),t=e?.querySelector('input[name="after_success_url"]'),o=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal"),r=!t||!o||!e?.checkoutComplete;if((r||a)&&(m.style.display="flex",h&&n.contains(h)&&(h._ready=!1,h.src="about:blank",h.style.height=f,h.style.visibility="hidden",n.style.height=f,n.removeChild(h)),g&&g.disconnect(),document.querySelectorAll(`.${d}-container`).forEach((e=>E(e))),y&&y.focus()),e?.checkoutComplete){const e=()=>{if(t&&o){const e=t.getAttribute("value"),n=o.getAttribute("value");"custom"===n?window.location.href=e:"referrer"===n&&window.history.back()}window?.newspackReaderActivation?.setPendingCheckout?.(),p=!1};window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:r}):e(),r&&($(),A(newspackBlocksModal.labels.checkout_modal_title))}else window?.newspackReaderActivation?.setPendingCheckout?.(),c(),p=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-order-details")},S=()=>{m.style.display="flex",q(t),n.appendChild(h),t.addEventListener("click",(e=>{e.target===t&&b()})),e(t,h),function(e){h._readyTimer&&clearTimeout(h._readyTimer);let t=!1;function n(){t||(t=!0,clearTimeout(h._readyTimer),e.call(this))}function o(){"complete"===this.readyState&&n.call(this)}!function e(){if(h._ready)return void clearTimeout(h._readyTimer);const t=h.contentDocument||h.contentWindow?.document;t&&0!==t.URL.indexOf("about:")?"complete"===t?.readyState?n.call(t):(t.addEventListener("DOMContentLoaded",n),t.addEventListener("readystatechange",o)):h._readyTimer=setTimeout(e,10)}()}(w)},E=e=>{e.overlayId&&window.newspackReaderActivation?.overlays&&window.newspackReaderActivation?.overlays.remove(e.overlayId),e.setAttribute("data-state","closed"),document.body.style.overflow="auto"},q=e=>{window.newspackReaderActivation?.overlays&&(t.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},A=e=>{const n=t.querySelector(`.${d}__header h2`);n&&(n.innerText=e)},$=(e="default")=>{const n=t.querySelector(`.${d}`);n&&("small"===e?n.classList.add(`${d}--small`):n.classList.remove(`${d}--small`))};window.newspackCloseModalCheckout=b,t.querySelectorAll(`.${d}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),b()}))})),document.querySelectorAll(".newspack-blocks__modal-variation").forEach((e=>{e.addEventListener("click",(t=>{t.target===e&&b()})),e.querySelectorAll(`.${d}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),b()}))}))})),document.addEventListener("keydown",(function(e){"Escape"===e.key&&b()})),document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation").forEach((e=>{e.querySelectorAll("form").forEach((e=>{e.appendChild(_.cloneNode()),e.target=i,e.addEventListener("submit",k)}))}));const L=e=>{e.requestSubmit(e.querySelector('button[type="submit"]'))};(()=>{const e=new URLSearchParams(window.location.search);if(!e.has("checkout"))return;const t=e.get("type");if("donate"===t){const t=e.get("layout"),n=e.get("frequency"),o=e.get("amount"),c=e.get("other");t&&n&&o&&((e,t,n,o=null)=>{let c;document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc form").forEach((a=>{const r=a.querySelector(`input[name="donation_frequency"][value="${t}"]`);if(r)if("tiered"===e){const e=document.querySelector(`button[data-frequency-slug="${t}"]`);if(!e)return;e.click();const o=a.querySelector(`button[type="submit"][name="donation_value_${t}"][value="${n}"]`);if(!o)return;o.click()}else{const i="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${n}"]`);if(r&&i){if(r.checked=!0,"untiered"===e)i.value=n;else if("other"===n){i.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&o&&(e.value=o)}else i.checked=!0;c=a}}})),c&&L(c)})(t,n,o,c)}else if("checkout_button"===t){const t=e.get("product_id"),n=e.get("variation_id");t&&((e,t=null)=>{let n;if(t&&t!==e){const o=[...document.querySelectorAll(`.${l}`)].find((t=>t.dataset.productId===e));o&&o.querySelectorAll(`form[target="${i}"]`).forEach((e=>{const o=JSON.parse(e.dataset.product);o?.variation_id===Number(t)&&(n=e)}))}else document.querySelectorAll(".wp-block-newspack-blocks-checkout-button").forEach((t=>{const o=t.querySelector("form");if(!o)return;const c=JSON.parse(o.dataset.product);c?.product_id===e&&(n=o)}));n&&L(n)})(t,n)}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();if(e){const t=v(e);L(t)}}window.history.replaceState(null,null,window.location.pathname)})()},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",_):_())})(); |
{ | ||
"name": "@automattic/newspack-blocks", | ||
"version": "4.3.0-epic-ras-acc.9", | ||
"version": "4.3.0-epic-ras-acc.10", | ||
"author": "Automattic", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
@@ -5,4 +5,6 @@ import { getEventPayload, getProductDetails, sendEvent } from './utils'; | ||
* Event fired when a checkout modal is dismissed (not when closed automatically due to a completed checkout). | ||
* | ||
* @param {Object} data The data to send with the event. | ||
*/ | ||
export const manageDismissed = () => { | ||
export const manageDismissed = ( data ) => { | ||
if ( 'function' !== typeof window.gtag ) { | ||
@@ -12,4 +14,6 @@ return; | ||
const { action_type, amount = '', currency, price = '', product_id, product_type, recurrence, referrer, variation_id = '' } = getProductDetails( 'newspack_modal_checkout' ); | ||
data = data || getProductDetails( 'newspack_modal_checkout' ); | ||
const { action_type, amount = '', currency, price = '', product_id, product_type, recurrence, referrer, variation_id = '' } = data; | ||
const params = { | ||
@@ -16,0 +20,0 @@ action_type, |
@@ -6,5 +6,5 @@ import { getEventPayload, sendEvent } from './utils'; | ||
* | ||
* @param {Object} getProductDataModal Information about the purchase being made. | ||
* @param {Object} data Information about the purchase being made. | ||
*/ | ||
export const manageOpened = ( getProductDataModal = '' ) => { | ||
export const manageOpened = ( data ) => { | ||
if ( 'function' !== typeof window.gtag ) { | ||
@@ -27,3 +27,3 @@ return; | ||
variation_id = '', | ||
} = getProductDataModal; | ||
} = data; | ||
@@ -30,0 +30,0 @@ const params = { |
@@ -22,3 +22,6 @@ /* globals newspackBlocksModal, newspack_ras_config */ | ||
let getProductDataModal = {}; | ||
// Track the checkout state for analytics. | ||
let analyticsData = {}; | ||
// Track the checkout intent to avoid multiple analytics events. | ||
let inCheckoutIntent = false; | ||
@@ -232,10 +235,16 @@ domReady( () => { | ||
// Set up some GA4 information. | ||
const getDataProduct = form.getAttribute( 'data-product' ); | ||
getProductDataModal = getDataProduct ? JSON.parse( getDataProduct ) : {}; | ||
manageOpened( getProductDataModal ); | ||
const formAnalyticsData = form.getAttribute( 'data-product' ); | ||
analyticsData = formAnalyticsData ? JSON.parse( formAnalyticsData ) : {}; | ||
// For the variation modal we will not set `inCheckoutIntent = true` and | ||
// let the `opened` event get triggered once the user selects a | ||
// variation so we track the selection. | ||
if ( ! inCheckoutIntent ) { | ||
manageOpened( analyticsData ); | ||
} | ||
// Append product data info to the modal itself, so we can grab it for manageDismissed: | ||
document | ||
.getElementById( 'newspack_modal_checkout' ) | ||
.setAttribute( 'data-order-details', JSON.stringify( getProductDataModal ) ); | ||
.setAttribute( 'data-order-details', JSON.stringify( analyticsData ) ); | ||
return; | ||
@@ -252,4 +261,4 @@ } | ||
if ( isCheckoutButtonBlock ) { // this fires on the second in-modal variations screen, too | ||
const getDataProduct = form.getAttribute( 'data-product' ); | ||
getProductDataModal = getDataProduct ? JSON.parse( getDataProduct ) : {}; | ||
const formAnalyticsData = form.getAttribute( 'data-product' ); | ||
analyticsData = formAnalyticsData ? JSON.parse( formAnalyticsData ) : {}; | ||
} else if ( isDonateBlock ) { | ||
@@ -281,3 +290,3 @@ // Get donation information and append to the modal checkout for GA4: | ||
// Get product information together to be appended to the modal for GA4 events outside of the iframe. | ||
getProductDataModal = { | ||
analyticsData = { | ||
amount: donationValue, | ||
@@ -293,2 +302,8 @@ action_type: 'donation', | ||
// Analytics. | ||
if ( ! inCheckoutIntent ) { | ||
manageOpened( analyticsData ); | ||
} | ||
inCheckoutIntent = true; | ||
if ( | ||
@@ -381,3 +396,3 @@ typeof newspack_ras_config !== 'undefined' && | ||
title: newspackBlocksModal.labels.auth_modal_title, | ||
callback: ( message, authData ) => { | ||
onSuccess: ( message, authData ) => { | ||
cartReq.then( url => { | ||
@@ -396,2 +411,11 @@ // If registered, append the registration flag query param to the url. | ||
}, | ||
onError: () => { | ||
closeCheckout(); | ||
}, | ||
onDismiss: () => { | ||
// Analytics: Track a dismissal event (modal has been manually closed without completing the checkout). | ||
manageDismissed( analyticsData ); | ||
inCheckoutIntent = false; | ||
document.getElementById( 'newspack_modal_checkout' ).removeAttribute( 'data-order-details' ); | ||
}, | ||
skipSuccess: true, | ||
@@ -413,7 +437,6 @@ skipNewslettersSignup: true, | ||
openCheckout(); | ||
manageOpened( getProductDataModal ); | ||
// Append product data info to the modal, so we can grab it for GA4 events outside of the iframe. | ||
document | ||
.getElementById( 'newspack_modal_checkout' ) | ||
.setAttribute( 'data-order-details', JSON.stringify( getProductDataModal ) ); | ||
.setAttribute( 'data-order-details', JSON.stringify( analyticsData ) ); | ||
} | ||
@@ -510,2 +533,3 @@ }; | ||
window?.newspackReaderActivation?.setPendingCheckout?.(); | ||
inCheckoutIntent = false; | ||
}; | ||
@@ -515,3 +539,4 @@ | ||
window.newspackReaderActivation.openNewslettersSignupModal( { | ||
callback: handleCheckoutComplete, | ||
onSuccess: handleCheckoutComplete, | ||
onError: handleCheckoutComplete, | ||
closeOnSuccess: shouldCloseModal, | ||
@@ -531,4 +556,5 @@ } ); | ||
// Track a dismissal event (modal has been manually closed without completing the checkout). | ||
// Analytics: Track a dismissal event (modal has been manually closed without completing the checkout). | ||
manageDismissed(); | ||
inCheckoutIntent = false; | ||
document.getElementById( 'newspack_modal_checkout' ).removeAttribute( 'data-order-details' ); | ||
@@ -535,0 +561,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4056627
15619