@automattic/newspack-blocks 4.15.2 → 4.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.15.3](https://github.com/Automattic/newspack-blocks/compare/v4.15.2...v4.15.3) (2025-09-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **modal-checkout:** handling of tiered donation block ([#2216](https://github.com/Automattic/newspack-blocks/issues/2216)) ([5f74453](https://github.com/Automattic/newspack-blocks/commit/5f744533f6a1f14a8adc4fe1304f5912cb691905))
|
|
7
|
+
|
|
1
8
|
## [4.15.2](https://github.com/Automattic/newspack-blocks/compare/v4.15.1...v4.15.2) (2025-09-22)
|
|
2
9
|
|
|
3
10
|
|
package/dist/modal.asset.php
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<?php return array('dependencies' => array(), 'version' => '
|
|
1
|
+
<?php return array('dependencies' => array(), 'version' => 'fae0eee76bb95fdcb360');
|
package/dist/modal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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=["action","action_type","amount","currency","product_id","product_type","variation_id","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],o=(e,t="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const o={};for(const t of n)e[t]&&(o[t]=e[t].toString());window.gtag("event",t,o)}},c=e=>{if("function"!=typeof window.gtag)return;let n="opened";const{amount:c="",is_variable:a="",price:r="",variation_id:s=""}=e,i={...e};(c||r)&&(i.amount=c||r),a&&!s&&(n="opened_variations");const l=t(n,i);o(l)};function a(e,t=null){const n=document.createElement("input");return n.type="hidden",n.name=e,t&&(n.value=t),n}function r(e){e.requestSubmit(e.querySelector('button[type="submit"]'))}function s(e){const t="string"==typeof e?document.getElementById(e):e;if(!t)return console.warn("No container found for checkout data"),{};let n={};if("FORM"===t.tagName){const e=new FormData(t);n=Object.fromEntries(e)}const o=t.dataset.checkout;if(!o)return console.warn("No checkout data found"),n;try{n={...n,...JSON.parse(o)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(n.action_type=c.searchParams.get("action_type")),n.memberships_content_gate&&(n.gate_post_id=n.memberships_content_gate,delete n.memberships_content_gate),n}const i=e=>{if("function"!=typeof window.gtag)return;e=e||s("newspack_modal_checkout");const n=t("dismissed",e);o(n)},l=newspackBlocksModal.newspack_class_prefix,d="newspack_modal_checkout_iframe",u="newspack_modal_checkout_container",m=`${l}__modal`,p="newspack-blocks__modal-variation";let _=!1,h=newspackBlocksModal.labels.checkout_modal_title;const w=e=>{e.overlayId&&window.newspackReaderActivation?.overlays&&window.newspackReaderActivation?.overlays.remove(e.overlayId),e.setAttribute("data-state","closed"),document.body.style.overflow="auto"};window.onpageshow=e=>{e.persisted&&(document.querySelectorAll(".modal-processing").forEach((e=>e.classList.remove("modal-processing"))),document.querySelectorAll(".non-modal-checkout-loading").forEach((e=>e.classList.remove("non-modal-checkout-loading"))),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))))};const k=new CustomEvent("checkout-closed");var y;window.newspackRAS=window.newspackRAS||[],y=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const n=t.querySelector(`.${m}__content`),o=a("modal_checkout","1"),y=n.querySelector(`.${l}__spinner`);let f=document.querySelector(".newspack-reader__account-link")?.[0];const v="600px",g=document.createElement("iframe");g.name=d,g.style.height=v,g.style.visibility="hidden";const b=e=>{L.observe(e),"none"!==y.style.display&&(y.style.display="none"),"visible"!==g.style.visibility&&(g.style.visibility="visible"),g._ready=!0};!function(e,t,n){e._ready=!1,e._readyTimer&&clearTimeout(e._readyTimer);let o=!1,c="";function a(){o||(o=!0,clearTimeout(e._readyTimer),t.call(this))}function r(){"complete"===this.readyState&&a.call(this)}function s(){e._ready=!1,n&&n(),e._readyTimer&&clearTimeout(e._readyTimer);const t=e.contentDocument||e.contentWindow?.document;t&&(t.removeEventListener("DOMContentLoaded",a),t.removeEventListener("readystatechange",r))}function i(){if(e._ready)return void s();const t=e.contentDocument||e.contentWindow?.document;t&&0!==t.URL.indexOf("about:")?"complete"===t?.readyState?a.call(t):(t.addEventListener("DOMContentLoaded",a),t.addEventListener("readystatechange",r)):e._readyTimer=setTimeout(i,10)}e._observer||(e._observer=new MutationObserver((e=>{e.forEach((e=>{"attributes"===e.type&&"src"===e.attributeName&&(o=!1,s(),i())}))})),e._observer.observe(e,{attributes:!0})),e._locationObserver||(e._locationObserver=setInterval((function(){const t=e.contentDocument||e.contentWindow?.document;t&&t.URL!==c&&(c=t.URL,o=!1,s(),i())}),50)),i()}(g,(function(){const n=g.contentWindow?.location;if(window.newspackReaderActivation&&n?.href?.includes("order-received")){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=g?.contentDocument?.querySelector(`#${u}`);if(!o)return;const c=o.querySelector("#modal-checkout-product-details"),a=s(c);!function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(o,(()=>{const e=c?.querySelector("strong");e&&(e.textContent=a.price_summary),B(),C(h),g.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce&&(t.checkout_nonce=g.contentWindow.newspackBlocksModalCheckout.checkout_nonce),b(o)})),function(e,t){e.checkoutComplete?t():e.addEventListener("checkout-complete",t)}(o,(()=>{window.newspackRAS.push(["checkout_completed",a]),window?.newspackReaderActivation?.refreshNewslettersSignupModal&&window?.newspackReaderActivation?.getReader()?.email&&window.newspackReaderActivation.refreshNewslettersSignupModal(window.newspackReaderActivation.getReader().email),B("small"),C(newspackBlocksModal.labels.thankyou_modal_title),b(o),e(t.querySelector(`.${m}`))}))}),(()=>{y.style.display="flex"}));const S=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)})),E=()=>"undefined"!=typeof newspack_ras_config&&!newspack_ras_config?.is_logged_in&&!window?.newspackReaderActivation?.getReader?.()?.authenticated&&newspackBlocksModal?.is_registration_required&&window?.newspackReaderActivation?.openAuthModal,A=t=>{const n=!newspackBlocksModal.has_unsupported_payment_gateway;n||t.preventDefault();const o=t.target;o.classList.add("modal-processing");const u=s(o);if(u.newspack_donate){const e=u.donation_frequency,t=[...o.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`)],n=u.donation_tier_index;let c,a;n?(c=t[n],a=u[`donation_value_${e}`]):(c=t[0],a=u[`donation_value_${e}_untiered`]);const r=s(c);for(const e in r)u[e]=r[e];u.amount=a,u.price_summary=u.summary_template.replace("{{PRICE}}",function(e,t="USD"){return parseFloat(e).toLocaleString(document.documentElement.lang,{style:"currency",currency:t,currencyDisplay:"narrowSymbol"})}(u.amount,u.currency))}u&&Object.keys(u).forEach((e=>{0===o.querySelectorAll('input[name="'+e+'"]').length&&o.appendChild(a(e,u[e]))})),u.variation_id||(f=t.submitter);const m=document.querySelectorAll(`.${p}`);if(m.forEach((e=>{(E()||n)&&w(e)})),u.is_variable&&!u.variation_id){const n=[...m].find((e=>e.dataset.productId===u.product_id));if(n)return n.querySelectorAll(`form[target="${d}"]`).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,u[t]))}));const t=e.dataset.checkout;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(),o.classList.remove("modal-processing"),$(n),e(n,!1),_||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(n||E())if(o.classList.remove("modal-processing"),_||c(u),_=!0,E()){t.preventDefault();const e=u.price_summary,o=e?`<div class="order-details-summary ${l}__box ${l}__box--text-center"><p><strong>${e}</strong></p></div>`:"",c=S(u);c.then((e=>{window.newspackReaderActivation?.setPendingCheckout?.(e)})),window.newspackReaderActivation.openAuthModal({title:newspackBlocksModal.labels.auth_modal_title,onSuccess:(e,t)=>{c.then((e=>{t?.registered&&n&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`),n?r(q(e)):S(u).then(window.location.href=e)})).catch((e=>{console.warn("Unable to generate cart:",e),R()}))},onError:()=>{R()},onDismiss:()=>{i(u),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout")},skipSuccess:!0,skipNewslettersSignup:!0,labels:{signin:{title:newspackBlocksModal.labels.signin_modal_title},register:{title:newspackBlocksModal.labels.register_modal_title}},content:o,trigger:t.submitter,closeOnSuccess:n})}else M(),document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u));else S(u).then((e=>{window.location.href=e})),(!u.is_variable||u.variation_id)&&o.querySelectorAll("button[type=submit]:focus").forEach((e=>{e.classList.add("non-modal-checkout-loading");const t=e.innerHTML;e.innerHTML="<span>"+t+"</span>"}))},q=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=d,t.style.display="none";const n=document.createElement("button");return n.setAttribute("type","submit"),t.appendChild(n),document.body.appendChild(t),t.addEventListener("submit",A),t},L=new ResizeObserver((e=>{if(!e||!e.length)return;if(!g.contentDocument)return;const o=e[0].contentRect;if(o){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${m}__header`)?.offsetHeight||0),c=o.top+o.bottom,a=Math.min(c,e);if(0===a)return void(g.style.visibility="hidden");n.style.height=a+"px",g.style.height=a+"px"}})),R=()=>{const e=g?.contentDocument?.querySelector(`#${u}`),o=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal");e?.checkoutComplete||(async()=>{const e=new FormData;newspackBlocksModal.has_unsupported_payment_gateway||e.append("modal_checkout","1"),e.append("action","abandon_modal_checkout"),e.append("_wpnonce",t.checkout_nonce),t.checkout_nonce=null;try{await fetch(newspackBlocksModal.ajax_url,{method:"POST",body:e})}catch(e){console.warn("Unable to empty cart:",e)}})();const r=!(g.contentDocument&&o&&c&&e?.checkoutComplete);if((r||a)&&(y.style.display="flex",g&&n.contains(g)&&(g._ready=!1,g.src="about:blank",g.style.height=v,g.style.visibility="hidden",n.style.height=v,n.removeChild(g)),L&&L.disconnect(),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))),f&&f.focus(),document.dispatchEvent(k)),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?.(),_=!1};window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:r}):e(),r&&(h=newspackBlocksModal.labels.checkout_modal_title,B(),C(h))}else window?.newspackReaderActivation?.setPendingCheckout?.(),i(),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout");document.removeEventListener("keydown",D)},M=o=>{o&&(g.src=o),y.style.display="flex",$(t),n.appendChild(g),t.addEventListener("click",(e=>{e.target===t&&R()})),e(t,g),document.addEventListener("keydown",D)},$=e=>{window.newspackReaderActivation?.overlays&&(e.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},C=e=>{const n=t.querySelector(`.${m}__header h2`);n&&(n.innerText=e)},B=(e="default")=>{const n=t.querySelector(`.${m}`);n&&("small"===e?n.classList.add(`${m}--small`):n.classList.remove(`${m}--small`))};t.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))})),document.querySelectorAll(".newspack-blocks__modal-variation").forEach((e=>{e.addEventListener("click",(t=>{t.target===e&&R()})),e.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))}))}));const D=e=>{"Escape"===e.key&&R()};document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation").forEach((e=>{e.querySelectorAll("form").forEach((e=>{newspackBlocksModal.has_unsupported_payment_gateway||e.appendChild(o.cloneNode()),e.target=d,e.addEventListener("submit",A)}))})),(()=>{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 s="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${n}"]`);if(r&&s){if(r.checked=!0,"untiered"===e)s.value=n;else if("other"===n){s.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&o&&(e.value=o)}else s.checked=!0;c=a}}})),c&&r(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(`.${p}`)].find((t=>t.dataset.productId===e));o&&o.querySelectorAll(`form[target="${d}"]`).forEach((e=>{const o=JSON.parse(e.dataset.checkout);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.checkout);c?.product_id===e&&(n=o)}));n&&r(n)})(t,n)}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();e&&r(q(e))}window.history.replaceState(null,null,window.location.pathname)})(),window.newspackOpenModalCheckout=({url:e=null,title:t=null,actionType:n=null,afterSuccess:o={},onCheckoutComplete:c=null,onClose:a=null})=>{if(h=t||newspackBlocksModal.labels.checkout_modal_title,C(h),(e=new URL(e||newspackBlocksModal.checkout_url)).searchParams.has("my_account_checkout")&&e.searchParams.delete("my_account_checkout"),e.searchParams.has("modal_checkout")||e.searchParams.set("modal_checkout","1"),n&&e.searchParams.set("action_type",n),o?.url&&e.searchParams.set("after_success_url",o.url),(o?.behavior||o?.url)&&e.searchParams.set("after_success_behavior",o.behavior||"custom"),o?.buttonLabel&&e.searchParams.set("after_success_button_label",o.buttonLabel),c){const e=({detail:{action:e,data:t}})=>{"checkout_completed"===e&&c(t)};window.newspackRAS.push((t=>{t.on("activity",e);const n=()=>{t.off("activity",e),document.removeEventListener("checkout-closed",n)};document.addEventListener("checkout-closed",n)}))}if(a){const e=()=>{a(),document.removeEventListener("checkout-closed",e)};document.addEventListener("checkout-closed",e)}M(e.toString())},window.newspackCloseModalCheckout=R},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",y):y())})();
|
|
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=["action","action_type","amount","currency","product_id","product_type","variation_id","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],o=(e,t="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const o={};for(const t of n)e[t]&&(o[t]=e[t].toString());window.gtag("event",t,o)}},c=e=>{if("function"!=typeof window.gtag)return;let n="opened";const{amount:c="",is_variable:a="",price:r="",variation_id:s=""}=e,i={...e};(c||r)&&(i.amount=c||r),a&&!s&&(n="opened_variations");const l=t(n,i);o(l)};function a(e,t=null){const n=document.createElement("input");return n.type="hidden",n.name=e,t&&(n.value=t),n}function r(e){e.requestSubmit(e.querySelector('button[type="submit"]'))}function s(e){const t="string"==typeof e?document.getElementById(e):e;if(!t)return console.warn("No container found for checkout data"),{};let n={};if("FORM"===t.tagName){const e=new FormData(t);n=Object.fromEntries(e)}const o=t.dataset.checkout;if(!o)return console.warn("No checkout data found"),n;try{n={...n,...JSON.parse(o)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(n.action_type=c.searchParams.get("action_type")),n.memberships_content_gate&&(n.gate_post_id=n.memberships_content_gate,delete n.memberships_content_gate),n}const i=e=>{if("function"!=typeof window.gtag)return;e=e||s("newspack_modal_checkout");const n=t("dismissed",e);o(n)},l=newspackBlocksModal.newspack_class_prefix,d="newspack_modal_checkout_iframe",u="newspack_modal_checkout_container",m=`${l}__modal`,p="newspack-blocks__modal-variation";let _=!1,h=newspackBlocksModal.labels.checkout_modal_title;const w=e=>{e.overlayId&&window.newspackReaderActivation?.overlays&&window.newspackReaderActivation?.overlays.remove(e.overlayId),e.setAttribute("data-state","closed"),document.body.style.overflow="auto"};window.onpageshow=e=>{e.persisted&&(document.querySelectorAll(".modal-processing").forEach((e=>e.classList.remove("modal-processing"))),document.querySelectorAll(".non-modal-checkout-loading").forEach((e=>e.classList.remove("non-modal-checkout-loading"))),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))))};const k=new CustomEvent("checkout-closed");var y;window.newspackRAS=window.newspackRAS||[],y=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const n=t.querySelector(`.${m}__content`),o=a("modal_checkout","1"),y=n.querySelector(`.${l}__spinner`);let f=document.querySelector(".newspack-reader__account-link")?.[0];const v="600px",g=document.createElement("iframe");g.name=d,g.style.height=v,g.style.visibility="hidden";const b=e=>{L.observe(e),"none"!==y.style.display&&(y.style.display="none"),"visible"!==g.style.visibility&&(g.style.visibility="visible"),g._ready=!0};!function(e,t,n){e._ready=!1,e._readyTimer&&clearTimeout(e._readyTimer);let o=!1,c="";function a(){o||(o=!0,clearTimeout(e._readyTimer),t.call(this))}function r(){"complete"===this.readyState&&a.call(this)}function s(){e._ready=!1,n&&n(),e._readyTimer&&clearTimeout(e._readyTimer);const t=e.contentDocument||e.contentWindow?.document;t&&(t.removeEventListener("DOMContentLoaded",a),t.removeEventListener("readystatechange",r))}function i(){if(e._ready)return void s();const t=e.contentDocument||e.contentWindow?.document;t&&0!==t.URL.indexOf("about:")?"complete"===t?.readyState?a.call(t):(t.addEventListener("DOMContentLoaded",a),t.addEventListener("readystatechange",r)):e._readyTimer=setTimeout(i,10)}e._observer||(e._observer=new MutationObserver((e=>{e.forEach((e=>{"attributes"===e.type&&"src"===e.attributeName&&(o=!1,s(),i())}))})),e._observer.observe(e,{attributes:!0})),e._locationObserver||(e._locationObserver=setInterval((function(){const t=e.contentDocument||e.contentWindow?.document;t&&t.URL!==c&&(c=t.URL,o=!1,s(),i())}),50)),i()}(g,(function(){const n=g.contentWindow?.location;if(window.newspackReaderActivation&&n?.href?.includes("order-received")){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=g?.contentDocument?.querySelector(`#${u}`);if(!o)return;const c=o.querySelector("#modal-checkout-product-details"),a=s(c);!function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(o,(()=>{const e=c?.querySelector("strong");e&&(e.textContent=a.price_summary),B(),C(h),g.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce&&(t.checkout_nonce=g.contentWindow.newspackBlocksModalCheckout.checkout_nonce),b(o)})),function(e,t){e.checkoutComplete?t():e.addEventListener("checkout-complete",t)}(o,(()=>{window.newspackRAS.push(["checkout_completed",a]),window?.newspackReaderActivation?.refreshNewslettersSignupModal&&window?.newspackReaderActivation?.getReader()?.email&&window.newspackReaderActivation.refreshNewslettersSignupModal(window.newspackReaderActivation.getReader().email),B("small"),C(newspackBlocksModal.labels.thankyou_modal_title),b(o),e(t.querySelector(`.${m}`))}))}),(()=>{y.style.display="flex"}));const S=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)})),E=()=>"undefined"!=typeof newspack_ras_config&&!newspack_ras_config?.is_logged_in&&!window?.newspackReaderActivation?.getReader?.()?.authenticated&&newspackBlocksModal?.is_registration_required&&window?.newspackReaderActivation?.openAuthModal,A=t=>{const n=!newspackBlocksModal.has_unsupported_payment_gateway;n||t.preventDefault();const o=t.target;o.classList.add("modal-processing");const u=s(o);if(u.newspack_donate){const e=u.donation_frequency,t=[...o.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`)],n=u.donation_tier_index;let c,a;n?(c=t[n],a=u[`donation_value_${e}`]):(c=t[0],u[`donation_value_${e}_untiered`]?a=u[`donation_value_${e}_untiered`]:(a=u[`donation_value_${e}`],"other"===a&&(a=u[`donation_value_${e}_other`])));const r=s(c);for(const e in r)u[e]=r[e];u.amount=a,u.price_summary=u.summary_template.replace("{{PRICE}}",function(e,t="USD"){return parseFloat(e).toLocaleString(document.documentElement.lang,{style:"currency",currency:t,currencyDisplay:"narrowSymbol"})}(u.amount,u.currency))}u&&Object.keys(u).forEach((e=>{0===o.querySelectorAll('input[name="'+e+'"]').length&&o.appendChild(a(e,u[e]))})),u.variation_id||(f=t.submitter);const m=document.querySelectorAll(`.${p}`);if(m.forEach((e=>{(E()||n)&&w(e)})),u.is_variable&&!u.variation_id){const n=[...m].find((e=>e.dataset.productId===u.product_id));if(n)return n.querySelectorAll(`form[target="${d}"]`).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,u[t]))}));const t=e.dataset.checkout;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(),o.classList.remove("modal-processing"),M(n),e(n,!1),_||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(n||E())if(o.classList.remove("modal-processing"),_||c(u),_=!0,E()){t.preventDefault();const e=u.price_summary,o=e?`<div class="order-details-summary ${l}__box ${l}__box--text-center"><p><strong>${e}</strong></p></div>`:"",c=S(u);c.then((e=>{window.newspackReaderActivation?.setPendingCheckout?.(e)})),window.newspackReaderActivation.openAuthModal({title:newspackBlocksModal.labels.auth_modal_title,onSuccess:(e,t)=>{c.then((e=>{t?.registered&&n&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`),n?r(q(e)):S(u).then(window.location.href=e)})).catch((e=>{console.warn("Unable to generate cart:",e),R()}))},onError:()=>{R()},onDismiss:()=>{i(u),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout")},skipSuccess:!0,skipNewslettersSignup:!0,labels:{signin:{title:newspackBlocksModal.labels.signin_modal_title},register:{title:newspackBlocksModal.labels.register_modal_title}},content:o,trigger:t.submitter,closeOnSuccess:n})}else $(),document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u));else S(u).then((e=>{window.location.href=e})),(!u.is_variable||u.variation_id)&&o.querySelectorAll("button[type=submit]:focus").forEach((e=>{e.classList.add("non-modal-checkout-loading");const t=e.innerHTML;e.innerHTML="<span>"+t+"</span>"}))},q=e=>{const t=document.createElement("form");t.method="POST",t.action=e,t.target=d,t.style.display="none";const n=document.createElement("button");return n.setAttribute("type","submit"),t.appendChild(n),document.body.appendChild(t),t.addEventListener("submit",A),t},L=new ResizeObserver((e=>{if(!e||!e.length)return;if(!g.contentDocument)return;const o=e[0].contentRect;if(o){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${m}__header`)?.offsetHeight||0),c=o.top+o.bottom,a=Math.min(c,e);if(0===a)return void(g.style.visibility="hidden");n.style.height=a+"px",g.style.height=a+"px"}})),R=()=>{const e=g?.contentDocument?.querySelector(`#${u}`),o=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal");e?.checkoutComplete||(async()=>{const e=new FormData;newspackBlocksModal.has_unsupported_payment_gateway||e.append("modal_checkout","1"),e.append("action","abandon_modal_checkout"),e.append("_wpnonce",t.checkout_nonce),t.checkout_nonce=null;try{await fetch(newspackBlocksModal.ajax_url,{method:"POST",body:e})}catch(e){console.warn("Unable to empty cart:",e)}})();const r=!(g.contentDocument&&o&&c&&e?.checkoutComplete);if((r||a)&&(y.style.display="flex",g&&n.contains(g)&&(g._ready=!1,g.src="about:blank",g.style.height=v,g.style.visibility="hidden",n.style.height=v,n.removeChild(g)),L&&L.disconnect(),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))),f&&f.focus(),document.dispatchEvent(k)),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?.(),_=!1};window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:r}):e(),r&&(h=newspackBlocksModal.labels.checkout_modal_title,B(),C(h))}else window?.newspackReaderActivation?.setPendingCheckout?.(),i(),_=!1,document.getElementById("newspack_modal_checkout").removeAttribute("data-checkout");document.removeEventListener("keydown",D)},$=o=>{o&&(g.src=o),y.style.display="flex",M(t),n.appendChild(g),t.addEventListener("click",(e=>{e.target===t&&R()})),e(t,g),document.addEventListener("keydown",D)},M=e=>{window.newspackReaderActivation?.overlays&&(e.overlayId=window.newspackReaderActivation?.overlays.add()),e.setAttribute("data-state","open"),document.body.style.overflow="hidden"},C=e=>{const n=t.querySelector(`.${m}__header h2`);n&&(n.innerText=e)},B=(e="default")=>{const n=t.querySelector(`.${m}`);n&&("small"===e?n.classList.add(`${m}--small`):n.classList.remove(`${m}--small`))};t.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))})),document.querySelectorAll(".newspack-blocks__modal-variation").forEach((e=>{e.addEventListener("click",(t=>{t.target===e&&R()})),e.querySelectorAll(`.${m}__close`).forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),R()}))}))}));const D=e=>{"Escape"===e.key&&R()};document.querySelectorAll(".wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation").forEach((e=>{e.querySelectorAll("form").forEach((e=>{newspackBlocksModal.has_unsupported_payment_gateway||e.appendChild(o.cloneNode()),e.target=d,e.addEventListener("submit",A)}))})),(()=>{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 s="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${n}"]`);if(r&&s){if(r.checked=!0,"untiered"===e)s.value=n;else if("other"===n){s.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&o&&(e.value=o)}else s.checked=!0;c=a}}})),c&&r(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(`.${p}`)].find((t=>t.dataset.productId===e));o&&o.querySelectorAll(`form[target="${d}"]`).forEach((e=>{const o=JSON.parse(e.dataset.checkout);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.checkout);c?.product_id===e&&(n=o)}));n&&r(n)})(t,n)}else{const e=window.newspackReaderActivation?.getPendingCheckout?.();e&&r(q(e))}window.history.replaceState(null,null,window.location.pathname)})(),window.newspackOpenModalCheckout=({url:e=null,title:t=null,actionType:n=null,afterSuccess:o={},onCheckoutComplete:c=null,onClose:a=null})=>{if(h=t||newspackBlocksModal.labels.checkout_modal_title,C(h),(e=new URL(e||newspackBlocksModal.checkout_url)).searchParams.has("my_account_checkout")&&e.searchParams.delete("my_account_checkout"),e.searchParams.has("modal_checkout")||e.searchParams.set("modal_checkout","1"),n&&e.searchParams.set("action_type",n),o?.url&&e.searchParams.set("after_success_url",o.url),(o?.behavior||o?.url)&&e.searchParams.set("after_success_behavior",o.behavior||"custom"),o?.buttonLabel&&e.searchParams.set("after_success_button_label",o.buttonLabel),c){const e=({detail:{action:e,data:t}})=>{"checkout_completed"===e&&c(t)};window.newspackRAS.push((t=>{t.on("activity",e);const n=()=>{t.off("activity",e),document.removeEventListener("checkout-closed",n)};document.addEventListener("checkout-closed",n)}))}if(a){const e=()=>{a(),document.removeEventListener("checkout-closed",e)};document.addEventListener("checkout-closed",e)}$(e.toString())},window.newspackCloseModalCheckout=R},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",y):y())})();
|
package/newspack-blocks.php
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Author URI: https://newspack.com/
|
|
8
8
|
* Text Domain: newspack-blocks
|
|
9
9
|
* Domain Path: /languages
|
|
10
|
-
* Version: 4.15.
|
|
10
|
+
* Version: 4.15.3
|
|
11
11
|
*
|
|
12
12
|
* @package Newspack_Blocks
|
|
13
13
|
*/
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
define( 'NEWSPACK_BLOCKS__PLUGIN_FILE', __FILE__ );
|
|
16
16
|
define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
|
|
17
17
|
define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( NEWSPACK_BLOCKS__PLUGIN_FILE ) );
|
|
18
|
-
define( 'NEWSPACK_BLOCKS__VERSION', '4.15.
|
|
18
|
+
define( 'NEWSPACK_BLOCKS__VERSION', '4.15.3' );
|
|
19
19
|
|
|
20
20
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks.php';
|
|
21
21
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-api.php';
|
package/package.json
CHANGED
|
@@ -249,7 +249,14 @@ domReady( () => {
|
|
|
249
249
|
customAmount = checkoutData[ `donation_value_${ frequency }` ];
|
|
250
250
|
} else {
|
|
251
251
|
donationContainer = donationTiers[ 0 ];
|
|
252
|
-
|
|
252
|
+
if ( checkoutData[ `donation_value_${ frequency }_untiered` ] ) {
|
|
253
|
+
customAmount = checkoutData[ `donation_value_${ frequency }_untiered` ];
|
|
254
|
+
} else {
|
|
255
|
+
customAmount = checkoutData[ `donation_value_${ frequency }` ];
|
|
256
|
+
if ( customAmount === 'other' ) {
|
|
257
|
+
customAmount = checkoutData[ `donation_value_${ frequency }_other` ];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
253
260
|
}
|
|
254
261
|
const donationData = getCheckoutData( donationContainer );
|
|
255
262
|
for( const key in donationData ) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
'name' => 'automattic/newspack-blocks',
|
|
4
4
|
'pretty_version' => 'dev-trunk',
|
|
5
5
|
'version' => 'dev-trunk',
|
|
6
|
-
'reference' => '
|
|
6
|
+
'reference' => '5f744533f6a1f14a8adc4fe1304f5912cb691905',
|
|
7
7
|
'type' => 'wordpress-plugin',
|
|
8
8
|
'install_path' => __DIR__ . '/../../',
|
|
9
9
|
'aliases' => array(),
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
'automattic/newspack-blocks' => array(
|
|
14
14
|
'pretty_version' => 'dev-trunk',
|
|
15
15
|
'version' => 'dev-trunk',
|
|
16
|
-
'reference' => '
|
|
16
|
+
'reference' => '5f744533f6a1f14a8adc4fe1304f5912cb691905',
|
|
17
17
|
'type' => 'wordpress-plugin',
|
|
18
18
|
'install_path' => __DIR__ . '/../../',
|
|
19
19
|
'aliases' => array(),
|