@automattic/newspack-blocks 4.17.3 → 4.17.4
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 +8 -0
- package/dist/modal.asset.php +1 -1
- package/dist/modal.js +1 -1
- package/dist/modalCheckout.asset.php +1 -1
- package/dist/modalCheckout.js +1 -1
- package/includes/class-modal-checkout.php +10 -1
- package/includes/modal-checkout/class-checkout-data.php +3 -3
- package/newspack-blocks.php +2 -2
- package/package.json +1 -1
- package/src/modal-checkout/modal.js +6 -4
- package/src/modal-checkout/utils.js +0 -6
- package/vendor/composer/installed.php +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [4.17.4](https://github.com/Automattic/newspack-blocks/compare/v4.17.3...v4.17.4) (2025-11-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* content gate metadata methods and params ([163e07f](https://github.com/Automattic/newspack-blocks/commit/163e07f56653b39eee68145659419d917606693d))
|
|
7
|
+
* content gate metadata methods and params ([#2249](https://github.com/Automattic/newspack-blocks/issues/2249)) ([fe6cc18](https://github.com/Automattic/newspack-blocks/commit/fe6cc18898349d978af8f0dd9d62b65ed92df652))
|
|
8
|
+
|
|
1
9
|
## [4.17.3](https://github.com/Automattic/newspack-blocks/compare/v4.17.2...v4.17.3) (2025-11-11)
|
|
2
10
|
|
|
3
11
|
|
package/dist/modal.asset.php
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<?php return array('dependencies' => array(), 'version' => '
|
|
1
|
+
<?php return array('dependencies' => array(), 'version' => '8b020f0be6182d59dc2f');
|
package/dist/modal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";function e(e,t=!1){const o=e.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');if(0===o.length)return!1;const n=o?.[0];let c;n.focus(),t?(document.addEventListener("keydown",(function(e){if(("Tab"===e.key||9===e.keyCode)&&e.shiftKey&&document.activeElement===n){const o=t.contentWindow.document,n=o.getElementById("checkout-after-success");c=null!==n?n:o.getElementById("checkout_cancel"),c.focus(),e.preventDefault()}})),document.getElementById("newspack-a11y-last-element").addEventListener("focus",(()=>{n.focus()}))):(c=o[o.length-1],document.addEventListener("keydown",(function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement===n&&(c.focus(),e.preventDefault()):document.activeElement===c&&(n.focus(),e.preventDefault()))})))}const t=(e,t={})=>({...t,action:e}),o=["action","action_type","amount","currency","product_id","product_type","variation_id","variation_ids","is_variable","is_grouped","child_ids","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],n=(e,t="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const n={};for(const t of o)e[t]&&("boolean"==typeof e[t]?e[t]=e[t]?"yes":"no":"true"===e[t]?e[t]="yes":"false"===e[t]&&(e[t]="no"),n[t]=e[t].toString());window.gtag("event",t,n)}},c=e=>{if("function"!=typeof window.gtag)return;let o="opened";const{amount:c="",is_variable:a="",is_grouped:r="",price:s="",variation_id:i=""}=e,l={...e};(c||s)&&(l.amount=c||s),a&&!i&&(o="opened_variations"),r&&(o="opened_grouped");const d=t(o,l);n(d)};function a(e,t=null){const o=document.createElement("input");return o.type="hidden",o.name=e,t&&(o.value=t),o}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 o={};if("FORM"===t.tagName){const e=new FormData(t);o=Object.fromEntries(e)}const n=t.dataset.checkout;if(!n)return console.warn("No checkout data found"),o;try{o={...o,...JSON.parse(n)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(o.action_type=c.searchParams.get("action_type")),o.memberships_content_gate&&(o.gate_post_id=o.memberships_content_gate,delete o.memberships_content_gate),o}const i=e=>{if("function"!=typeof window.gtag)return;e=e||s("newspack_modal_checkout");const o=t("dismissed",e);n(o)},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 y=new CustomEvent("checkout-closed");var k;window.newspackRAS=window.newspackRAS||[],k=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const o=t.querySelector(`.${m}__content`),n=a("modal_checkout","1"),k=o.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"!==k.style.display&&(k.style.display="none"),"visible"!==g.style.visibility&&(g.style.visibility="visible"),g._ready=!0};!function(e,t,o){e._ready=!1,e._readyTimer&&clearTimeout(e._readyTimer);let n=!1,c="";function a(){n||(n=!0,clearTimeout(e._readyTimer),t.call(this))}function r(){"complete"===this.readyState&&a.call(this)}function s(){e._ready=!1,o&&o(),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&&(n=!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,n=!1,s(),i())}),50)),i()}(g,(function(){const o=g.contentWindow?.location;if(window.newspackReaderActivation&&o?.href?.includes("order-received")){const e=window.newspackReaderActivation,t=new Proxy(new URLSearchParams(o.search),{get:(e,t)=>e.get(t)});t.email&&(e.setReaderEmail(t.email),e.setAuthenticated(!0))}const n=g?.contentDocument?.querySelector(`#${u}`);if(!n)return;const c=n.querySelector("#modal-checkout-product-details"),a=s(c);n.addEventListener("checkout-cancel",(()=>{R()})),function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(n,(()=>{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(n)})),function(e,t){e.checkoutComplete?t():e.addEventListener("checkout-complete",t)}(n,(()=>{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(n),e(t.querySelector(`.${m}`))}))}),(()=>{k.style.display="flex"}));const S=e=>new Promise(((t,o)=>{const n=new URLSearchParams(e);n.append("action","modal_checkout_request"),fetch(newspackBlocksModal.ajax_url+"?"+n.toString()).then((e=>{e.ok||o(e),e.json().then((e=>{t(e.url)})).catch(o)})).catch(o)})),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 o=newspackBlocksModal.has_supported_payment_gateway;o||t.preventDefault();const n=t.target;n.classList.add("modal-processing");const u=s(n);if(u.newspack_donate){const e=u.donation_frequency,t=[...n.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`)],o=u.donation_tier_index;let c,a;o?(c=t[o],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===n.querySelectorAll('input[name="'+e+'"]').length&&n.prepend(a(e,u[e]))})),u.variation_id||(f=t.submitter);const m=document.querySelectorAll(`.${p}`);if(m.forEach((e=>{(E()||o)&&w(e)})),u.is_grouped||u.is_variable&&!u.variation_id){const o=[...m].find((e=>e.dataset.productId===u.product_id));if(o)return o.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.prepend(a(t,u[t]))}));const t=e.dataset.checkout;if(t){const o=JSON.parse(t);Object.keys(o).forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,o[t]))}))}})),t.preventDefault(),n.classList.remove("modal-processing"),M(o),e(o,!1),_||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(o||E())if(n.classList.remove("modal-processing"),_||c(u),_=!0,E()){t.preventDefault();const e=u.price_summary,n=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&&o&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`),o?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:n,trigger:t.submitter,closeOnSuccess:o})}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)&&n.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 o=document.createElement("button");return o.setAttribute("type","submit"),t.appendChild(o),document.body.appendChild(t),t.addEventListener("submit",A),t},L=new ResizeObserver((e=>{if(!e||!e.length)return;if(!g.contentDocument)return;const n=e[0].contentRect;if(n){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${m}__header`)?.offsetHeight||0),c=n.top+n.bottom,a=Math.min(c,e);if(0===a)return void(g.style.visibility="hidden");o.style.height=a+"px",g.style.height=a+"px"}})),R=()=>{const e=g?.contentDocument?.querySelector(`#${u}`),n=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal"),r=s(e?.querySelector("#modal-checkout-product-details"));e?.checkoutComplete||(async()=>{const e=new FormData;newspackBlocksModal.has_supported_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 l=!(g.contentDocument&&n&&c&&e?.checkoutComplete);if((l||a)&&(k.style.display="flex",g&&o.contains(g)&&(g._ready=!1,g.src="about:blank",g.style.height=v,g.style.visibility="hidden",o.style.height=v,o.removeChild(g)),L&&L.disconnect(),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))),f&&f.focus(),document.dispatchEvent(y)),e?.checkoutComplete){const e=()=>{if(n&&c){const e=n.getAttribute("value"),t=c.getAttribute("value");"custom"===t?window.location.href=e:"referrer"===t&&window.history.back()}window?.newspackReaderActivation?.setPendingCheckout?.(),_=!1};"subscription_switch"!==r.action_type&&window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:l}):e(),l&&(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)},$=n=>{n&&(g.src=n),k.style.display="flex",M(t),o.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 o=t.querySelector(`.${m}__header h2`);o&&(o.innerText=e)},B=(e="default")=>{const o=t.querySelector(`.${m}`);o&&("small"===e?o.classList.add(`${m}--small`):o.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_supported_payment_gateway&&e.prepend(n.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"),o=e.get("frequency"),n=e.get("amount"),c=e.get("other");t&&o&&n&&((e,t,o,n=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 n=a.querySelector(`button[type="submit"][name="donation_value_${t}"][value="${o}"]`);if(!n)return;n.click()}else{const s="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${o}"]`);if(r&&s){if(r.checked=!0,"untiered"===e)s.value=o;else if("other"===o){s.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&n&&(e.value=n)}else s.checked=!0;c=a}}})),c&&r(c)})(t,o,n,c)}else if("checkout_button"===t){const t=e.get("product_id"),o=e.get("variation_id");t&&((e,t=null)=>{let o;if(t&&t!==e){const n=[...document.querySelectorAll(`.${p}`)].find((t=>t.dataset.productId===e));n&&n.querySelectorAll(`form[target="${d}"]`).forEach((e=>{const n=JSON.parse(e.dataset.checkout);n?.variation_id===Number(t)&&(o=e)}))}else document.querySelectorAll(".wp-block-newspack-blocks-checkout-button").forEach((t=>{const n=t.querySelector("form");if(!n)return;const c=JSON.parse(n.dataset.checkout);c?.product_id===e&&(o=n)}));o&&r(o)})(t,o)}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:o=null,afterSuccess:n={},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"),o&&e.searchParams.set("action_type",o),n?.url&&e.searchParams.set("after_success_url",n.url),(n?.behavior||n?.url)&&e.searchParams.set("after_success_behavior",n.behavior||"custom"),n?.buttonLabel&&e.searchParams.set("after_success_button_label",n.buttonLabel),c){const e=({detail:{action:e,data:t}})=>{"checkout_completed"===e&&c(t)};window.newspackRAS.push((t=>{t.on("activity",e);const o=()=>{t.off("activity",e),document.removeEventListener("checkout-closed",o)};document.addEventListener("checkout-closed",o)}))}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",k):k())})();
|
|
1
|
+
(()=>{"use strict";function e(e,t=!1){const o=e.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');if(0===o.length)return!1;const n=o?.[0];let c;n.focus(),t?(document.addEventListener("keydown",(function(e){if(("Tab"===e.key||9===e.keyCode)&&e.shiftKey&&document.activeElement===n){const o=t.contentWindow.document,n=o.getElementById("checkout-after-success");c=null!==n?n:o.getElementById("checkout_cancel"),c.focus(),e.preventDefault()}})),document.getElementById("newspack-a11y-last-element").addEventListener("focus",(()=>{n.focus()}))):(c=o[o.length-1],document.addEventListener("keydown",(function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement===n&&(c.focus(),e.preventDefault()):document.activeElement===c&&(n.focus(),e.preventDefault()))})))}const t=(e,t={})=>({...t,action:e}),o=["action","action_type","amount","currency","product_id","product_type","variation_id","variation_ids","is_variable","is_grouped","child_ids","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],n=(e,t="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const n={};for(const t of o)e[t]&&("boolean"==typeof e[t]?e[t]=e[t]?"yes":"no":"true"===e[t]?e[t]="yes":"false"===e[t]&&(e[t]="no"),n[t]=e[t].toString());window.gtag("event",t,n)}},c=e=>{if("function"!=typeof window.gtag)return;let o="opened";const{amount:c="",is_variable:a="",is_grouped:r="",price:s="",variation_id:i=""}=e,l={...e};(c||s)&&(l.amount=c||s),a&&!i&&(o="opened_variations"),r&&(o="opened_grouped");const d=t(o,l);n(d)};function a(e,t=null){const o=document.createElement("input");return o.type="hidden",o.name=e,t&&(o.value=t),o}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 o={};if("FORM"===t.tagName){const e=new FormData(t);o=Object.fromEntries(e)}const n=t.dataset.checkout;if(!n)return console.warn("No checkout data found"),o;try{o={...o,...JSON.parse(n)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(o.action_type=c.searchParams.get("action_type")),o}const i=e=>{if("function"!=typeof window.gtag)return;e=e||s("newspack_modal_checkout");const o=t("dismissed",e);n(o)},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 y=new CustomEvent("checkout-closed");var k;window.newspackRAS=window.newspackRAS||[],k=()=>{const t=document.querySelector("#newspack_modal_checkout");if(!t)return;const o=t.querySelector(`.${m}__content`),n=a("modal_checkout","1"),k=o.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"!==k.style.display&&(k.style.display="none"),"visible"!==g.style.visibility&&(g.style.visibility="visible"),g._ready=!0};!function(e,t,o){e._ready=!1,e._readyTimer&&clearTimeout(e._readyTimer);let n=!1,c="";function a(){n||(n=!0,clearTimeout(e._readyTimer),t.call(this))}function r(){"complete"===this.readyState&&a.call(this)}function s(){e._ready=!1,o&&o(),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&&(n=!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,n=!1,s(),i())}),50)),i()}(g,(function(){const o=g.contentWindow?.location;if(window.newspackReaderActivation&&o?.href?.includes("order-received")){const e=window.newspackReaderActivation,t=new Proxy(new URLSearchParams(o.search),{get:(e,t)=>e.get(t)});t.email&&(e.setReaderEmail(t.email),e.setAuthenticated(!0))}const n=g?.contentDocument?.querySelector(`#${u}`);if(!n)return;const c=n.querySelector("#modal-checkout-product-details"),a=s(c);n.addEventListener("checkout-cancel",(()=>{R()})),function(e,t){e.checkoutReady?t():e.addEventListener("checkout-ready",t)}(n,(()=>{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(n)})),function(e,t){e.checkoutComplete?t():e.addEventListener("checkout-complete",t)}(n,(()=>{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(n),e(t.querySelector(`.${m}`))}))}),(()=>{k.style.display="flex"}));const S=e=>new Promise(((t,o)=>{const n=new URLSearchParams(e);n.append("action","modal_checkout_request"),fetch(newspackBlocksModal.ajax_url+"?"+n.toString()).then((e=>{e.ok||o(e),e.json().then((e=>{t(e.url)})).catch(o)})).catch(o)})),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 o=newspackBlocksModal.has_supported_payment_gateway;o||t.preventDefault();const n=t.target;n.classList.add("modal-processing");const u=s(n);if(u.newspack_donate){const e=u.donation_frequency,t=[...n.querySelectorAll(`.donation-tier__${e}, .donation-frequency__${e}`)],o=u.donation_tier_index;let c,a;o?(c=t[o],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===n.querySelectorAll('input[name="'+e+'"]').length&&n.prepend(a(e,u[e]))})),u.variation_id||(f=t.submitter);const m=document.querySelectorAll(`.${p}`);if(m.forEach((e=>{(E()||o)&&w(e)})),u.is_grouped||u.is_variable&&!u.variation_id){const o=[...m].find((e=>e.dataset.productId===u.product_id));if(o)return o.querySelectorAll(`form[target="${d}"]`).forEach((e=>{["after_success_behavior","after_success_url","after_success_button_label","gate_post_id","newspack_popup_id"].forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,u[t]))}));const t=e.dataset.checkout;if(t){const o=JSON.parse(t);Object.keys(o).forEach((t=>{0===e.querySelectorAll('input[name="'+t+'"]').length&&e.prepend(a(t,o[t]))}))}})),t.preventDefault(),n.classList.remove("modal-processing"),M(o),e(o,!1),_||c(u),void document.getElementById("newspack_modal_checkout").setAttribute("data-checkout",JSON.stringify(u))}if(o||E())if(n.classList.remove("modal-processing"),_||c(u),_=!0,E()){t.preventDefault();const e=u.price_summary,n=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&&o&&(e+=`&${newspackBlocksModal.checkout_registration_flag}=1`),o?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:n,trigger:t.submitter,closeOnSuccess:o})}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)&&n.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 o=document.createElement("button");return o.setAttribute("type","submit"),t.appendChild(o),document.body.appendChild(t),t.addEventListener("submit",A),t},L=new ResizeObserver((e=>{if(!e||!e.length)return;if(!g.contentDocument)return;const n=e[0].contentRect;if(n){const e=.01*Math.max(document.documentElement.clientHeight,window.innerHeight||0)*90-(t.querySelector(`.${m}__header`)?.offsetHeight||0),c=n.top+n.bottom,a=Math.min(c,e);if(0===a)return void(g.style.visibility="hidden");o.style.height=a+"px",g.style.height=a+"px"}})),R=()=>{const e=g?.contentDocument?.querySelector(`#${u}`),n=e?.querySelector('input[name="after_success_url"]'),c=e?.querySelector('input[name="after_success_behavior"]'),a=document?.querySelector(".newspack-newsletters-signup-modal"),r=s(e?.querySelector("#modal-checkout-product-details"));e?.checkoutComplete||(async()=>{const e=new FormData;newspackBlocksModal.has_supported_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 l=!(g.contentDocument&&n&&c&&e?.checkoutComplete);if((l||a)&&(k.style.display="flex",g&&o.contains(g)&&(g._ready=!1,g.src="about:blank",g.style.height=v,g.style.visibility="hidden",o.style.height=v,o.removeChild(g)),L&&L.disconnect(),document.querySelectorAll(`.${m}-container`).forEach((e=>w(e))),f&&f.focus(),document.dispatchEvent(y)),e?.checkoutComplete){const e=()=>{if(n&&c){const e=n.getAttribute("value"),t=c.getAttribute("value");"custom"===t?window.location.href=e:"referrer"===t&&window.history.back()}window?.newspackReaderActivation?.setPendingCheckout?.(),_=!1};"subscription_switch"!==r.action_type&&window?.newspackReaderActivation?.openNewslettersSignupModal?window.newspackReaderActivation.openNewslettersSignupModal({onSuccess:e,onError:e,closeOnSuccess:l}):e(),l&&(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)},$=n=>{n&&(g.src=n),k.style.display="flex",M(t),o.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 o=t.querySelector(`.${m}__header h2`);o&&(o.innerText=e)},B=(e="default")=>{const o=t.querySelector(`.${m}`);o&&("small"===e?o.classList.add(`${m}--small`):o.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_supported_payment_gateway&&e.prepend(n.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"),o=e.get("frequency"),n=e.get("amount"),c=e.get("other");t&&o&&n&&((e,t,o,n=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 n=a.querySelector(`button[type="submit"][name="donation_value_${t}"][value="${o}"]`);if(!n)return;n.click()}else{const s="untiered"===e?a.querySelector(`input[name="donation_value_${t}_untiered"]`):a.querySelector(`input[name="donation_value_${t}"][value="${o}"]`);if(r&&s){if(r.checked=!0,"untiered"===e)s.value=o;else if("other"===o){s.click();const e=a.querySelector(`input[name="donation_value_${t}_other"]`);e&&n&&(e.value=n)}else s.checked=!0;c=a}}})),c&&r(c)})(t,o,n,c)}else if("checkout_button"===t){const t=e.get("product_id"),o=e.get("variation_id");t&&((e,t=null)=>{let o;if(t&&t!==e){const n=[...document.querySelectorAll(`.${p}`)].find((t=>t.dataset.productId===e));n&&n.querySelectorAll(`form[target="${d}"]`).forEach((e=>{const n=JSON.parse(e.dataset.checkout);n?.variation_id===Number(t)&&(o=e)}))}else document.querySelectorAll(".wp-block-newspack-blocks-checkout-button").forEach((t=>{const n=t.querySelector("form");if(!n)return;const c=JSON.parse(n.dataset.checkout);c?.product_id===e&&(o=n)}));o&&r(o)})(t,o)}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:o=null,afterSuccess:n={},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"),o&&e.searchParams.set("action_type",o),n?.url&&e.searchParams.set("after_success_url",n.url),(n?.behavior||n?.url)&&e.searchParams.set("after_success_behavior",n.behavior||"custom"),n?.buttonLabel&&e.searchParams.set("after_success_button_label",n.buttonLabel),c){const e=({detail:{action:e,data:t}})=>{"checkout_completed"===e&&c(t)};window.newspackRAS.push((t=>{t.on("activity",e);const o=()=>{t.off("activity",e),document.removeEventListener("checkout-closed",o)};document.addEventListener("checkout-closed",o)}))}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",k):k())})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<?php return array('dependencies' => array(), 'version' => '
|
|
1
|
+
<?php return array('dependencies' => array(), 'version' => 'e9b754d860d41de98168');
|
package/dist/modalCheckout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e=(e,t={})=>({...t,action:e}),t=["action","action_type","amount","currency","product_id","product_type","variation_id","variation_ids","is_variable","is_grouped","child_ids","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],o=(e,o="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const n={};for(const o of t)e[o]&&("boolean"==typeof e[o]?e[o]=e[o]?"yes":"no":"true"===e[o]?e[o]="yes":"false"===e[o]&&(e[o]="no"),n[o]=e[o].toString());window.gtag("event",o,n)}};function n(e){"undefined"!=typeof document&&"function"==typeof e&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}function c(e){const t="string"==typeof e?document.getElementById(e):e;if(!t)return console.warn("No container found for checkout data"),{};let o={};if("FORM"===t.tagName){const e=new FormData(t);o=Object.fromEntries(e)}const n=t.dataset.checkout;if(!n)return console.warn("No checkout data found"),o;try{o={...o,...JSON.parse(n)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(o.action_type=c.searchParams.get("action_type")),o.memberships_content_gate&&(o.gate_post_id=o.memberships_content_gate,delete o.memberships_content_gate),o}const i=(t="continue")=>{if("function"!=typeof window.gtag)return;const{action_type:n,amount:i,currency:a,product_id:r,product_type:s,recurrence:d,referrer:l,variation_id:u="",gate_post_id:p="",newspack_popup_id:_=""}=c("modal-checkout-product-details"),m={action_type:n,amount:i,currency:a,product_id:r,product_type:s,recurrence:d,referrer:l};u&&(m.variation_id=u),p&&(m.gate_post_id=p),_&&(m.newspack_popup_id=_);const h=e(t,m);o(h)};var a;a=jQuery,n((()=>{if(!a)return void console.warn("jQuery is not available.");const t=document.querySelector("#newspack_modal_checkout_container"),r=newspackBlocksModalCheckout.newspack_class_prefix,s=new CustomEvent("checkout-ready"),d=new CustomEvent("checkout-complete"),l=new CustomEvent("checkout-cancel");function u(){a(`.woocommerce-NoticeGroup-checkout, .${r}__inline-error, .woocommerce-error, .woocommerce-message, .wc-block-components-notice-banner, .woocommerce-notices-wrapper`).remove()}function p(i=!0){t.checkoutReady=!0,t.dispatchEvent(s),i&&n((function(){if("function"!=typeof window.gtag)return;const t=c("modal-checkout-product-details"),n=e("loaded",t);o(n)}))}if(newspackBlocksModalCheckout.is_checkout_complete)(()=>{if("function"!=typeof window.gtag)return;const t=c("modal-checkout-product-details"),n=e("form_submission_success",t);o(n)})(),t&&(t.checkoutComplete=!0,t.dispatchEvent(d));else{function m(){a("#wcpay-express-checkout-button-separator, #wc-stripe-payment-request-button-separator, #wc-stripe-express-checkout-button-separator").after('<div class="newspack-ui__word-divider">'+newspackBlocksModalCheckout.divider_text+"</div>");let n=[];const s=a("form.checkout"),d=a("#checkout_cancel");if(d.length&&d.on("click",(function(){t.dispatchEvent(l)})),!s.length)return console.warn("Checkout form is not available"),void p();const m=a("form.modal_checkout_coupon"),h=a("form.modal_checkout_nyp"),f=a("#checkout_continue"),g=a("#customer_details"),k=a("#after_customer_details"),w=a(".newspack-wcsg--wrapper");function y(){const e=a('input[name="payment_method"]:checked').val();a(".wc_payment_method").removeClass("selected"),a(".wc_payment_method.payment_method_"+e).addClass("selected")}function b(){let e;if(a.ajax({url:newspackBlocksModalCheckout.ajax_url,method:"POST",async:!1,data:{action:"get_cart_total"},success:t=>{e=t}}),e)return e}if(a('input[name="payment_method"]').change(y),a(document).on("payment_method_selected",y),a(document).on("updated_checkout",y),y(),a(document).on("updated_checkout",(function(){a("#payment .wc_payment_methods").length?a("#after_customer_details > h3").show():a("#after_customer_details > h3").hide()})),a(document).on("updated_checkout",(function(){const e=a(".order-review-wrapper");if(!e.length)return;const t=e.find("table");t.is(".empty")?e.addClass("hidden"):(t.unblock(),e.removeClass("hidden"));const o=a("#after_customer_details").hasClass("transaction-details-expanded"),n=a(".payment_methods");if(n.length){const t=e.clone();o&&a('[id="order_review_heading"]',t).attr("aria-expanded","true"),a(".order-review-wrapper").remove(),n.after(t)}else o||e.find("#order_review_heading").trigger("click")})),a(document).on("click","#order_review_heading",(function(){a(this).attr("aria-expanded",(function(e,t){return"false"===t?"true":"false"})),a("#after_customer_details").toggleClass("transaction-details-expanded")})),a(document).on("updated_checkout",(function(){let e=newspackBlocksModalCheckout.labels.complete_button;if(e){if(a("#place_order").has(a("span.cart-price"))){const t=a("<div>"+e+"</div>");t.find(".cart-price").html(b,(function(){return this.childNodes})),e=t.html()}a("#place_order").html(e),a("#place_order_clone").html(e)}})),w.length){const e=w.find(".newspack-wcsg--gift-toggle input"),t=w.find(".newspack-wcsg--gift-email");e.on("change",(function(){e.is(":checked")?t.addClass("visible"):t.removeClass("visible")}))}function v(e){s.find(".input-text, select, input:checkbox").trigger("validate").trigger("blur");let t=!1;const o=[],n=e=>{const n=a("#"+e.data("id")+"_field");if(n?.length){t||(t=n);const o=n.find(".woocommerce-error");o.length&&o.remove(),n.addClass("woocommerce-invalid").removeClass("woocommerce-valid"),n.append(`<span class="${r}__inline-error">`+e.text()+"</span>"),e.remove()}else e.is("li")||(e=a("<li />").append(e)),o.push(e)};if(u(),0!==e.trimStart().indexOf("<")?n(a("<li />").append(e)):e.includes("<li")?a(e).find("li").each((function(){n(a(this))})):n(a(e)),o.length){t=!1;const e=a('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout"/>').append(a('<ul class="woocommerce-error" role="alert" />').append(o));s.prepend(e),e.get(0).scrollIntoView({behavior:"smooth"})}t?.length&&(window.scroll({top:t.offset().top-100,left:0,behavior:"smooth"}),t.find("input.input-text, select, input:checkbox").trigger("focus")),E(s),a(document.body).trigger("update_checkout"),a(document.body).trigger("checkout_error",[e])}function C(e){e.preventDefault(),e.stopImmediatePropagation(),M(),i("continue")}function x(e){const t=window.newspack_grecaptcha||{};if(u(),a("#checkout_details").remove(),e)s.attr("data-skip-recaptcha","1"),s.append('<input name="is_validation_only" type="hidden" value="1" />'),"v3"===t?.version&&t.destroy(s.get()),m.length&&m.hide(),h.length&&h.hide(),g.show(),k.hide(),g.find("input").first().focus(),n=function(e,t){const o=a._data(e,"events");return o?t?o[t]||[]:o:[]}(s[0],"submit").slice(0),n.forEach((e=>{s.off("submit",e.handler)})),s.on("submit",C);else{s.removeAttr("data-skip-recaptcha");const e=s.find('[name="is_validation_only"]');if(e.length&&e.remove(),t?.render){s.data("newspack-recaptcha","newspack_modal_checkout");const e=()=>{u(),s.get(0).scrollIntoView({behavior:"smooth"})},o=e=>v(e);t.render(s.get(),e,o),a(document).on("updated_checkout",(()=>t.render(s.get(),e,o))),a(document.body).on("checkout_error",(()=>t.render(s.get(),e,o)))}m.length&&m.show(),h.length&&h.show(),g.hide(),k.show(),function(){a("#checkout_details").remove();const e={};s.serializeArray().forEach((t=>{e[t.name]=t.value}));const t=`${newspackBlocksModalCheckout.newspack_class_prefix}__font--xs`,o=[];o.push('<div class="billing-details">'),o.push("<h3>"+newspackBlocksModalCheckout.labels.billing_details+"</h3>"),(e.billing_first_name||e.billing_last_name)&&o.push(`<p class="${t}">`+e.billing_first_name+" "+e.billing_last_name+"</p>"),e.billing_company&&o.push(`<p class="${t}">`+e.billing_company+"</p>");let n="";if((e.billing_address_1||e.billing_address_2)&&(n=`<p class="${t}">`,e.billing_address_1&&(n+=e.billing_address_1),e.billing_address_2&&(n+=" "+e.billing_address_2),n+="<br>",e.billing_city&&(n+=e.billing_city),e.billing_state&&(n+=", "+e.billing_state),e.billing_postcode&&(n+=" "+e.billing_postcode),n+="<br>",e.billing_country&&(n+=e.billing_country)),o.push(n),e.billing_email&&o.push(`<p class="${t}">`+e.billing_email+"</p>"),o.push("</div>"),e.hasOwnProperty("shipping_address_1")){o.push('<div class="shipping-details">'),o.push("<h3>"+newspackBlocksModalCheckout.labels.shipping_details+"</h3>");let c="";e.ship_to_different_address?(c=`<p class="${t}">`,e.shipping_address_1&&(c+=e.shipping_address_1),e.shipping_address_2&&(c+=" "+e.shipping_address_2),c+="<br>",e.shipping_city&&(c+=e.shipping_city),e.shipping_state&&(c+=", "+e.shipping_state),e.shipping_postcode&&(c+=" "+e.shipping_postcode),c+="<br>",e.shipping_country&&(c+=e.shipping_country)):c=n,o.push(c),o.push("</div>")}e.hasOwnProperty("newspack_wcsg_is_gift")&&e.hasOwnProperty("wcsg_gift_recipients_email")&&e.newspack_wcsg_is_gift&&e.wcsg_gift_recipients_email&&(o.push('<div class="gift-details">'),o.push("<h3>"+newspackBlocksModalCheckout.labels.gift_recipient+"</h3>"),o.push(`<p class="${t}">`+e.wcsg_gift_recipients_email+"</p>")),a(".order-details-summary").after('<div id="checkout_details">'+o.join("")+"</div>")}(),s.off("submit",C),n.forEach((e=>{s.on("submit",e.handler)})),_()}s.triggerHandler("editing_details",[e]),window.scroll({top:0,left:0,behavior:"smooth"})}function M(e=!1,t=(()=>{})){if(!$(s))return console.warn("Unable to block the form"),t(),!1;u();const o=s.find(".woocommerce-NoticeGroup.woocommerce-NoticeGroup-checkout");o.length&&o.remove();const n=["save_user_in_woopay"],c=s.serializeArray().filter((e=>!n.includes(e.name)));c.push({name:"woocommerce_checkout_update_totals",value:"1"}),a.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:c,dataType:"html",success:o=>{let n;try{n=JSON.parse(o)}catch(e){n={messages:'<div class="woocommerce-error">'+wc_checkout_params.i18n_checkout_error+"</div>"}}e||!0!==n.reload?(E(s),n.messages?e||(n.messages?v(n.messages):v(`<div class="${r}__inline-error">`+wc_checkout_params.i18n_checkout_error+"</div>")):(x(!1),a._data(s[0],"events")?.click?.some((e=>"#checkout_edit_billing"===e.selector))||s.on("click","#checkout_edit_billing",(function(e){e.preventDefault(),x(!0),i("back")}))),t(n)):window.location.reload()},error:(o,n,c)=>{let i="";e||(i='<div class="woocommerce-error">'+(c||wc_checkout_params.i18n_checkout_error)+"</div>",v(i)),t({messages:i})}})}function $(e){return!e.is(".modal-processing")&&(e.find("button[type=submit]").each(((e,t)=>{a(t).attr("disabled",!0)})),e.addClass("modal-processing"),!0)}function E(e){return!!e.is(".modal-processing")&&(e.find("button[type=submit]").each(((e,t)=>{a(t).attr("disabled",!1)})),e.removeClass("modal-processing"),!0)}f.length?(x(!0),w.length?p():M(!0,p)):p(),m.length&&(m.on("submit",(function(e){if(e.preventDefault(),!$(m))return!1;const t={security:wc_checkout_params.apply_coupon_nonce,coupon_code:m.find('input[name="coupon_code"]').val()};a.ajax({type:"POST",url:wc_checkout_params.wc_ajax_url.toString().replace("%%endpoint%%","apply_coupon"),data:t,dataType:"html",success:e=>{if(u(),m.find(".result").remove(),e){const o=e.includes("error");m.append(`<p class="result ${r}__helper-text ${o?r+"__inline-error":""}">`+a(e).text()+"</p>"),o?(m.find('input[name="coupon_code"]').focus(),m.find('h3, input[name="coupon_code"]').addClass("newspack-ui__field-error")):(m.find('input[name="coupon_code"]').focus(),m.find('h3, input[name="coupon_code"]').removeClass("newspack-ui__field-error")),a(document.body).trigger("applied_coupon_in_checkout",[t.coupon_code]),a(document.body).trigger("update_checkout",{update_shipping_method:!1})}},complete:()=>{E(m)}})})),a(document.body).on("removed_coupon_in_checkout",(()=>{u(),m.find(".result").remove(),m.find('input[name="coupon_code"]').val("").focus()}))),h.length&&h.on("submit",(function(e){if(e.preventDefault(),!$(h))return!1;const t=h.find('input[name="price"]');t.attr("disabled",!0);const o={_ajax_nonce:newspackBlocksModalCheckout.nyp_nonce,action:"process_name_your_price_request",price:h.find('input[name="price"]').val(),product_id:h.find('input[name="product_id"]').val(),newspack_checkout_name_your_price:h.find('input[name="newspack_checkout_name_your_price"]').val()};a.ajax({type:"POST",url:newspackBlocksModalCheckout.ajax_url,data:o,success:({success:e,data:t})=>{u(),h.find(".result").remove(),h.append(`<p class="result ${r}__helper-text ${e?"":r+"__inline-error"}">`+t.message+"</p>"),e?h.find('h3, input[name="price"]').removeClass("newspack-ui__field-error"):(h.find('input[name="price"]').focus(),h.find('h3, input[name="price"]').addClass("newspack-ui__field-error")),a(document.body).trigger("update_checkout",{update_shipping_method:!1})},complete:()=>{E(h),t.attr("disabled",!1),t.focus()}})})),s.on("click","#place_order",(function(){(()=>{if("function"!=typeof window.gtag)return;const t=c("modal-checkout-product-details"),n=e("form_submission",t);o(n)})()}))}m()}function _(){const e=a("#newspack_subscription_terms_confirmation, #newspack_subscription_confirmation");if(e.length){const t=a("form.checkout"),o=t.find("button#place_order, button#place_order_clone");function n(){const t=e.is(":checked");o.each(((e,o)=>{a(o).attr("disabled",!t)}))}n(),e.on("change",n),t.on("submit",(function(t){if(!e.is(":checked"))return t.preventDefault(),t.stopPropagation(),!1}))}}a(document.body).on("updated_checkout payment_method_selected checkout_error",_),a(document).ready(_),a(document.body).on("checkout_error",(function(){const e=a(".woocommerce-NoticeGroup-checkout, .woocommerce-notices-wrapper");e.length&&e.each(((e,t)=>a(t).addClass(`${r}__notice ${r}__notice--error`)));const t=a("#checkout_error_back");t.length&&t.on("click",(e=>{e.preventDefault(),parent.newspackCloseModalCheckout()})),p(!1)})),document.addEventListener("keydown",(function(e){"Escape"===e.key&&parent.newspackCloseModalCheckout()})),newspackBlocksModalCheckout.is_error&&a(document.body).trigger("checkout_error")}))})();
|
|
1
|
+
(()=>{"use strict";const e=(e,t={})=>({...t,action:e}),t=["action","action_type","amount","currency","product_id","product_type","variation_id","variation_ids","is_variable","is_grouped","child_ids","price_summary","newspack_popup_id","gate_post_id","recurrence","referrer"],o=(e,o="np_modal_checkout_interaction")=>{if("function"==typeof window.gtag&&e){const n={};for(const o of t)e[o]&&("boolean"==typeof e[o]?e[o]=e[o]?"yes":"no":"true"===e[o]?e[o]="yes":"false"===e[o]&&(e[o]="no"),n[o]=e[o].toString());window.gtag("event",o,n)}};function n(e){"undefined"!=typeof document&&"function"==typeof e&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}function c(e){const t="string"==typeof e?document.getElementById(e):e;if(!t)return console.warn("No container found for checkout data"),{};let o={};if("FORM"===t.tagName){const e=new FormData(t);o=Object.fromEntries(e)}const n=t.dataset.checkout;if(!n)return console.warn("No checkout data found"),o;try{o={...o,...JSON.parse(n)}}catch(e){console.warn("Error parsing checkout data")}const c=new URL(t.ownerDocument.defaultView.location.href);return c.searchParams.get("action_type")&&(o.action_type=c.searchParams.get("action_type")),o}const i=(t="continue")=>{if("function"!=typeof window.gtag)return;const{action_type:n,amount:i,currency:a,product_id:r,product_type:s,recurrence:d,referrer:u,variation_id:l="",gate_post_id:p="",newspack_popup_id:_=""}=c("modal-checkout-product-details"),h={action_type:n,amount:i,currency:a,product_id:r,product_type:s,recurrence:d,referrer:u};l&&(h.variation_id=l),p&&(h.gate_post_id=p),_&&(h.newspack_popup_id=_);const m=e(t,h);o(m)};var a;a=jQuery,n((()=>{if(!a)return void console.warn("jQuery is not available.");const t=document.querySelector("#newspack_modal_checkout_container"),r=newspackBlocksModalCheckout.newspack_class_prefix,s=new CustomEvent("checkout-ready"),d=new CustomEvent("checkout-complete"),u=new CustomEvent("checkout-cancel");function l(){a(`.woocommerce-NoticeGroup-checkout, .${r}__inline-error, .woocommerce-error, .woocommerce-message, .wc-block-components-notice-banner, .woocommerce-notices-wrapper`).remove()}function p(i=!0){t.checkoutReady=!0,t.dispatchEvent(s),i&&n((function(){if("function"!=typeof window.gtag)return;const t=c("modal-checkout-product-details"),n=e("loaded",t);o(n)}))}if(newspackBlocksModalCheckout.is_checkout_complete)(()=>{if("function"!=typeof window.gtag)return;const t=c("modal-checkout-product-details"),n=e("form_submission_success",t);o(n)})(),t&&(t.checkoutComplete=!0,t.dispatchEvent(d));else{function h(){a("#wcpay-express-checkout-button-separator, #wc-stripe-payment-request-button-separator, #wc-stripe-express-checkout-button-separator").after('<div class="newspack-ui__word-divider">'+newspackBlocksModalCheckout.divider_text+"</div>");let n=[];const s=a("form.checkout"),d=a("#checkout_cancel");if(d.length&&d.on("click",(function(){t.dispatchEvent(u)})),!s.length)return console.warn("Checkout form is not available"),void p();const h=a("form.modal_checkout_coupon"),m=a("form.modal_checkout_nyp"),f=a("#checkout_continue"),g=a("#customer_details"),k=a("#after_customer_details"),w=a(".newspack-wcsg--wrapper");function y(){const e=a('input[name="payment_method"]:checked').val();a(".wc_payment_method").removeClass("selected"),a(".wc_payment_method.payment_method_"+e).addClass("selected")}function v(){let e;if(a.ajax({url:newspackBlocksModalCheckout.ajax_url,method:"POST",async:!1,data:{action:"get_cart_total"},success:t=>{e=t}}),e)return e}if(a('input[name="payment_method"]').change(y),a(document).on("payment_method_selected",y),a(document).on("updated_checkout",y),y(),a(document).on("updated_checkout",(function(){a("#payment .wc_payment_methods").length?a("#after_customer_details > h3").show():a("#after_customer_details > h3").hide()})),a(document).on("updated_checkout",(function(){const e=a(".order-review-wrapper");if(!e.length)return;const t=e.find("table");t.is(".empty")?e.addClass("hidden"):(t.unblock(),e.removeClass("hidden"));const o=a("#after_customer_details").hasClass("transaction-details-expanded"),n=a(".payment_methods");if(n.length){const t=e.clone();o&&a('[id="order_review_heading"]',t).attr("aria-expanded","true"),a(".order-review-wrapper").remove(),n.after(t)}else o||e.find("#order_review_heading").trigger("click")})),a(document).on("click","#order_review_heading",(function(){a(this).attr("aria-expanded",(function(e,t){return"false"===t?"true":"false"})),a("#after_customer_details").toggleClass("transaction-details-expanded")})),a(document).on("updated_checkout",(function(){let e=newspackBlocksModalCheckout.labels.complete_button;if(e){if(a("#place_order").has(a("span.cart-price"))){const t=a("<div>"+e+"</div>");t.find(".cart-price").html(v,(function(){return this.childNodes})),e=t.html()}a("#place_order").html(e),a("#place_order_clone").html(e)}})),w.length){const e=w.find(".newspack-wcsg--gift-toggle input"),t=w.find(".newspack-wcsg--gift-email");e.on("change",(function(){e.is(":checked")?t.addClass("visible"):t.removeClass("visible")}))}function b(e){s.find(".input-text, select, input:checkbox").trigger("validate").trigger("blur");let t=!1;const o=[],n=e=>{const n=a("#"+e.data("id")+"_field");if(n?.length){t||(t=n);const o=n.find(".woocommerce-error");o.length&&o.remove(),n.addClass("woocommerce-invalid").removeClass("woocommerce-valid"),n.append(`<span class="${r}__inline-error">`+e.text()+"</span>"),e.remove()}else e.is("li")||(e=a("<li />").append(e)),o.push(e)};if(l(),0!==e.trimStart().indexOf("<")?n(a("<li />").append(e)):e.includes("<li")?a(e).find("li").each((function(){n(a(this))})):n(a(e)),o.length){t=!1;const e=a('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout"/>').append(a('<ul class="woocommerce-error" role="alert" />').append(o));s.prepend(e),e.get(0).scrollIntoView({behavior:"smooth"})}t?.length&&(window.scroll({top:t.offset().top-100,left:0,behavior:"smooth"}),t.find("input.input-text, select, input:checkbox").trigger("focus")),E(s),a(document.body).trigger("update_checkout"),a(document.body).trigger("checkout_error",[e])}function C(e){e.preventDefault(),e.stopImmediatePropagation(),M(),i("continue")}function x(e){const t=window.newspack_grecaptcha||{};if(l(),a("#checkout_details").remove(),e)s.attr("data-skip-recaptcha","1"),s.append('<input name="is_validation_only" type="hidden" value="1" />'),"v3"===t?.version&&t.destroy(s.get()),h.length&&h.hide(),m.length&&m.hide(),g.show(),k.hide(),g.find("input").first().focus(),n=function(e,t){const o=a._data(e,"events");return o?t?o[t]||[]:o:[]}(s[0],"submit").slice(0),n.forEach((e=>{s.off("submit",e.handler)})),s.on("submit",C);else{s.removeAttr("data-skip-recaptcha");const e=s.find('[name="is_validation_only"]');if(e.length&&e.remove(),t?.render){s.data("newspack-recaptcha","newspack_modal_checkout");const e=()=>{l(),s.get(0).scrollIntoView({behavior:"smooth"})},o=e=>b(e);t.render(s.get(),e,o),a(document).on("updated_checkout",(()=>t.render(s.get(),e,o))),a(document.body).on("checkout_error",(()=>t.render(s.get(),e,o)))}h.length&&h.show(),m.length&&m.show(),g.hide(),k.show(),function(){a("#checkout_details").remove();const e={};s.serializeArray().forEach((t=>{e[t.name]=t.value}));const t=`${newspackBlocksModalCheckout.newspack_class_prefix}__font--xs`,o=[];o.push('<div class="billing-details">'),o.push("<h3>"+newspackBlocksModalCheckout.labels.billing_details+"</h3>"),(e.billing_first_name||e.billing_last_name)&&o.push(`<p class="${t}">`+e.billing_first_name+" "+e.billing_last_name+"</p>"),e.billing_company&&o.push(`<p class="${t}">`+e.billing_company+"</p>");let n="";if((e.billing_address_1||e.billing_address_2)&&(n=`<p class="${t}">`,e.billing_address_1&&(n+=e.billing_address_1),e.billing_address_2&&(n+=" "+e.billing_address_2),n+="<br>",e.billing_city&&(n+=e.billing_city),e.billing_state&&(n+=", "+e.billing_state),e.billing_postcode&&(n+=" "+e.billing_postcode),n+="<br>",e.billing_country&&(n+=e.billing_country)),o.push(n),e.billing_email&&o.push(`<p class="${t}">`+e.billing_email+"</p>"),o.push("</div>"),e.hasOwnProperty("shipping_address_1")){o.push('<div class="shipping-details">'),o.push("<h3>"+newspackBlocksModalCheckout.labels.shipping_details+"</h3>");let c="";e.ship_to_different_address?(c=`<p class="${t}">`,e.shipping_address_1&&(c+=e.shipping_address_1),e.shipping_address_2&&(c+=" "+e.shipping_address_2),c+="<br>",e.shipping_city&&(c+=e.shipping_city),e.shipping_state&&(c+=", "+e.shipping_state),e.shipping_postcode&&(c+=" "+e.shipping_postcode),c+="<br>",e.shipping_country&&(c+=e.shipping_country)):c=n,o.push(c),o.push("</div>")}e.hasOwnProperty("newspack_wcsg_is_gift")&&e.hasOwnProperty("wcsg_gift_recipients_email")&&e.newspack_wcsg_is_gift&&e.wcsg_gift_recipients_email&&(o.push('<div class="gift-details">'),o.push("<h3>"+newspackBlocksModalCheckout.labels.gift_recipient+"</h3>"),o.push(`<p class="${t}">`+e.wcsg_gift_recipients_email+"</p>")),a(".order-details-summary").after('<div id="checkout_details">'+o.join("")+"</div>")}(),s.off("submit",C),n.forEach((e=>{s.on("submit",e.handler)})),_()}s.triggerHandler("editing_details",[e]),window.scroll({top:0,left:0,behavior:"smooth"})}function M(e=!1,t=(()=>{})){if(!$(s))return console.warn("Unable to block the form"),t(),!1;l();const o=s.find(".woocommerce-NoticeGroup.woocommerce-NoticeGroup-checkout");o.length&&o.remove();const n=["save_user_in_woopay"],c=s.serializeArray().filter((e=>!n.includes(e.name)));c.push({name:"woocommerce_checkout_update_totals",value:"1"}),a.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:c,dataType:"html",success:o=>{let n;try{n=JSON.parse(o)}catch(e){n={messages:'<div class="woocommerce-error">'+wc_checkout_params.i18n_checkout_error+"</div>"}}e||!0!==n.reload?(E(s),n.messages?e||(n.messages?b(n.messages):b(`<div class="${r}__inline-error">`+wc_checkout_params.i18n_checkout_error+"</div>")):(x(!1),a._data(s[0],"events")?.click?.some((e=>"#checkout_edit_billing"===e.selector))||s.on("click","#checkout_edit_billing",(function(e){e.preventDefault(),x(!0),i("back")}))),t(n)):window.location.reload()},error:(o,n,c)=>{let i="";e||(i='<div class="woocommerce-error">'+(c||wc_checkout_params.i18n_checkout_error)+"</div>",b(i)),t({messages:i})}})}function $(e){return!e.is(".modal-processing")&&(e.find("button[type=submit]").each(((e,t)=>{a(t).attr("disabled",!0)})),e.addClass("modal-processing"),!0)}function E(e){return!!e.is(".modal-processing")&&(e.find("button[type=submit]").each(((e,t)=>{a(t).attr("disabled",!1)})),e.removeClass("modal-processing"),!0)}f.length?(x(!0),w.length?p():M(!0,p)):p(),h.length&&(h.on("submit",(function(e){if(e.preventDefault(),!$(h))return!1;const t={security:wc_checkout_params.apply_coupon_nonce,coupon_code:h.find('input[name="coupon_code"]').val()};a.ajax({type:"POST",url:wc_checkout_params.wc_ajax_url.toString().replace("%%endpoint%%","apply_coupon"),data:t,dataType:"html",success:e=>{if(l(),h.find(".result").remove(),e){const o=e.includes("error");h.append(`<p class="result ${r}__helper-text ${o?r+"__inline-error":""}">`+a(e).text()+"</p>"),o?(h.find('input[name="coupon_code"]').focus(),h.find('h3, input[name="coupon_code"]').addClass("newspack-ui__field-error")):(h.find('input[name="coupon_code"]').focus(),h.find('h3, input[name="coupon_code"]').removeClass("newspack-ui__field-error")),a(document.body).trigger("applied_coupon_in_checkout",[t.coupon_code]),a(document.body).trigger("update_checkout",{update_shipping_method:!1})}},complete:()=>{E(h)}})})),a(document.body).on("removed_coupon_in_checkout",(()=>{l(),h.find(".result").remove(),h.find('input[name="coupon_code"]').val("").focus()}))),m.length&&m.on("submit",(function(e){if(e.preventDefault(),!$(m))return!1;const t=m.find('input[name="price"]');t.attr("disabled",!0);const o={_ajax_nonce:newspackBlocksModalCheckout.nyp_nonce,action:"process_name_your_price_request",price:m.find('input[name="price"]').val(),product_id:m.find('input[name="product_id"]').val(),newspack_checkout_name_your_price:m.find('input[name="newspack_checkout_name_your_price"]').val()};a.ajax({type:"POST",url:newspackBlocksModalCheckout.ajax_url,data:o,success:({success:e,data:t})=>{l(),m.find(".result").remove(),m.append(`<p class="result ${r}__helper-text ${e?"":r+"__inline-error"}">`+t.message+"</p>"),e?m.find('h3, input[name="price"]').removeClass("newspack-ui__field-error"):(m.find('input[name="price"]').focus(),m.find('h3, input[name="price"]').addClass("newspack-ui__field-error")),a(document.body).trigger("update_checkout",{update_shipping_method:!1})},complete:()=>{E(m),t.attr("disabled",!1),t.focus()}})})),s.on("click","#place_order",(function(){(()=>{if("function"!=typeof window.gtag)return;const t=c("modal-checkout-product-details"),n=e("form_submission",t);o(n)})()}))}h()}function _(){const e=a("#newspack_subscription_terms_confirmation, #newspack_subscription_confirmation");if(e.length){const t=a("form.checkout"),o=t.find("button#place_order, button#place_order_clone");function n(){const t=e.is(":checked");o.each(((e,o)=>{a(o).attr("disabled",!t)}))}n(),e.on("change",n),t.on("submit",(function(t){if(!e.is(":checked"))return t.preventDefault(),t.stopPropagation(),!1}))}}a(document.body).on("updated_checkout payment_method_selected checkout_error",_),a(document).ready(_),a(document.body).on("checkout_error",(function(){const e=a(".woocommerce-NoticeGroup-checkout, .woocommerce-notices-wrapper");e.length&&e.each(((e,t)=>a(t).addClass(`${r}__notice ${r}__notice--error`)));const t=a("#checkout_error_back");t.length&&t.on("click",(e=>{e.preventDefault(),parent.newspackCloseModalCheckout()})),p(!1)})),document.addEventListener("keydown",(function(e){"Escape"===e.key&&parent.newspackCloseModalCheckout()})),newspackBlocksModalCheckout.is_error&&a(document.body).trigger("checkout_error")}))})();
|
|
@@ -1488,7 +1488,16 @@ final class Modal_Checkout {
|
|
|
1488
1488
|
*/
|
|
1489
1489
|
public static function pass_url_param_on_redirect( $location ) {
|
|
1490
1490
|
if ( self::is_modal_checkout() ) {
|
|
1491
|
-
$
|
|
1491
|
+
$params = [ 'modal_checkout' => 1 ];
|
|
1492
|
+
$newspack_popup_id = filter_input( INPUT_GET, 'newspack_popup_id', FILTER_SANITIZE_NUMBER_INT );
|
|
1493
|
+
$gate_post_id = filter_input( INPUT_GET, 'gate_post_id', FILTER_SANITIZE_NUMBER_INT );
|
|
1494
|
+
if ( $newspack_popup_id ) {
|
|
1495
|
+
$params['newspack_popup_id'] = $newspack_popup_id;
|
|
1496
|
+
}
|
|
1497
|
+
if ( $gate_post_id ) {
|
|
1498
|
+
$params['gate_post_id'] = $gate_post_id;
|
|
1499
|
+
}
|
|
1500
|
+
$location = \add_query_arg( $params, $location );
|
|
1492
1501
|
}
|
|
1493
1502
|
return $location;
|
|
1494
1503
|
}
|
|
@@ -363,13 +363,13 @@ final class Checkout_Data {
|
|
|
363
363
|
$gate_post_id = null;
|
|
364
364
|
$newspack_popup_id = null;
|
|
365
365
|
if ( $order ) {
|
|
366
|
-
$gate_post_id = $order->get_meta( '
|
|
366
|
+
$gate_post_id = $order->get_meta( '_gate_post_id' );
|
|
367
367
|
$newspack_popup_id = $order->get_meta( '_newspack_popup_id' );
|
|
368
368
|
} elseif ( $cart_item ) {
|
|
369
|
-
$gate_post_id = $cart_item['
|
|
369
|
+
$gate_post_id = $cart_item['gate_post_id'] ?? null;
|
|
370
370
|
$newspack_popup_id = $cart_item['newspack_popup_id'] ?? null;
|
|
371
371
|
} else {
|
|
372
|
-
$gate_post_id = filter_input( INPUT_GET, '
|
|
372
|
+
$gate_post_id = filter_input( INPUT_GET, 'gate_post_id', FILTER_SANITIZE_NUMBER_INT );
|
|
373
373
|
$newspack_popup_id = filter_input( INPUT_GET, 'newspack_popup_id', FILTER_SANITIZE_NUMBER_INT );
|
|
374
374
|
}
|
|
375
375
|
if ( $gate_post_id ) {
|
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.17.
|
|
10
|
+
* Version: 4.17.4
|
|
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.17.
|
|
18
|
+
define( 'NEWSPACK_BLOCKS__VERSION', '4.17.4' );
|
|
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
|
@@ -301,15 +301,17 @@ domReady( () => {
|
|
|
301
301
|
variationModal
|
|
302
302
|
.querySelectorAll( `form[target="${ IFRAME_NAME }"]` )
|
|
303
303
|
.forEach( singleVariationForm => {
|
|
304
|
-
// Fill in the
|
|
304
|
+
// Fill in the hidden params in the variation modal.
|
|
305
305
|
[
|
|
306
306
|
'after_success_behavior',
|
|
307
307
|
'after_success_url',
|
|
308
308
|
'after_success_button_label',
|
|
309
|
-
|
|
310
|
-
|
|
309
|
+
'gate_post_id',
|
|
310
|
+
'newspack_popup_id',
|
|
311
|
+
].forEach( hiddenParams => {
|
|
312
|
+
const existingInputs = singleVariationForm.querySelectorAll( 'input[name="' + hiddenParams + '"]' );
|
|
311
313
|
if ( 0 === existingInputs.length ) {
|
|
312
|
-
singleVariationForm.prepend( createHiddenInput(
|
|
314
|
+
singleVariationForm.prepend( createHiddenInput( hiddenParams, checkoutData[ hiddenParams ] ) );
|
|
313
315
|
}
|
|
314
316
|
} );
|
|
315
317
|
|
|
@@ -219,12 +219,6 @@ export function getCheckoutData( element ) {
|
|
|
219
219
|
data.action_type = url.searchParams.get( 'action_type' );
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
// Replace 'memberships_content_gate' with 'gate_post_id'.
|
|
223
|
-
if ( data.memberships_content_gate ) {
|
|
224
|
-
data.gate_post_id = data.memberships_content_gate;
|
|
225
|
-
delete data.memberships_content_gate;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
222
|
return data;
|
|
229
223
|
}
|
|
230
224
|
|
|
@@ -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' => 'fe6cc18898349d978af8f0dd9d62b65ed92df652',
|
|
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' => 'fe6cc18898349d978af8f0dd9d62b65ed92df652',
|
|
17
17
|
'type' => 'wordpress-plugin',
|
|
18
18
|
'install_path' => __DIR__ . '/../../',
|
|
19
19
|
'aliases' => array(),
|