@automattic/newspack-blocks 1.0.0-hotfix-cap-count-user-posts-dedup.1
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/.eslintrc.js +3 -0
- package/.hooks/pre-push +8 -0
- package/.nvmrc +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc.js +5 -0
- package/.stylelintrc.js +3 -0
- package/AGENTS.md +275 -0
- package/CHANGELOG.md +3971 -0
- package/CLAUDE.md +1 -0
- package/README.md +43 -0
- package/babel.config.js +6 -0
- package/bin/install-wp-tests.sh +155 -0
- package/bin/update-translations.sh +13 -0
- package/block-list.json +12 -0
- package/composer.json +46 -0
- package/composer.lock +3632 -0
- package/dist/author-list/view-rtl.css +1 -0
- package/dist/author-list/view.asset.php +1 -0
- package/dist/author-list/view.css +1 -0
- package/dist/author-list/view.js +0 -0
- package/dist/author-profile/view-rtl.css +1 -0
- package/dist/author-profile/view.asset.php +1 -0
- package/dist/author-profile/view.css +1 -0
- package/dist/author-profile/view.js +0 -0
- package/dist/block_styles-rtl.css +2 -0
- package/dist/block_styles.asset.php +1 -0
- package/dist/block_styles.css +2 -0
- package/dist/block_styles.js +0 -0
- package/dist/blocks/author-list/block.json +89 -0
- package/dist/blocks/author-profile/block.json +80 -0
- package/dist/blocks/carousel/block.json +125 -0
- package/dist/blocks/checkout-button/block.json +117 -0
- package/dist/blocks/donate/block.json +103 -0
- package/dist/blocks/homepage-articles/block.json +260 -0
- package/dist/blocks/iframe/block.json +36 -0
- package/dist/carousel/view-rtl.css +2 -0
- package/dist/carousel/view.asset.php +1 -0
- package/dist/carousel/view.css +2 -0
- package/dist/carousel/view.js +3 -0
- package/dist/checkout-button/view-rtl.css +1 -0
- package/dist/checkout-button/view.asset.php +1 -0
- package/dist/checkout-button/view.css +1 -0
- package/dist/checkout-button/view.js +0 -0
- package/dist/donate/view-rtl.css +1 -0
- package/dist/donate/view.asset.php +1 -0
- package/dist/donate/view.css +1 -0
- package/dist/donate/view.js +1 -0
- package/dist/editor-rtl.css +66 -0
- package/dist/editor.asset.php +1 -0
- package/dist/editor.css +66 -0
- package/dist/editor.js +57 -0
- package/dist/frequencyBased-rtl.css +1 -0
- package/dist/frequencyBased.asset.php +1 -0
- package/dist/frequencyBased.css +1 -0
- package/dist/frequencyBased.js +1 -0
- package/dist/homepage-articles/view-rtl.css +1 -0
- package/dist/homepage-articles/view.asset.php +1 -0
- package/dist/homepage-articles/view.css +1 -0
- package/dist/homepage-articles/view.js +1 -0
- package/dist/iframe/view-rtl.css +1 -0
- package/dist/iframe/view.asset.php +1 -0
- package/dist/iframe/view.css +1 -0
- package/dist/iframe/view.js +1 -0
- package/dist/modal-rtl.css +1 -0
- package/dist/modal.asset.php +1 -0
- package/dist/modal.css +1 -0
- package/dist/modal.js +1 -0
- package/dist/modalCheckout-rtl.css +1 -0
- package/dist/modalCheckout.asset.php +1 -0
- package/dist/modalCheckout.css +1 -0
- package/dist/modalCheckout.js +1 -0
- package/dist/placeholder_blocks.asset.php +1 -0
- package/dist/placeholder_blocks.js +4 -0
- package/dist/tiersBased-rtl.css +1 -0
- package/dist/tiersBased.asset.php +1 -0
- package/dist/tiersBased.css +1 -0
- package/dist/tiersBased.js +1 -0
- package/includes/class-modal-checkout.php +2324 -0
- package/includes/class-newspack-blocks-api.php +347 -0
- package/includes/class-newspack-blocks-caching.php +291 -0
- package/includes/class-newspack-blocks-patterns.php +167 -0
- package/includes/class-newspack-blocks.php +1581 -0
- package/includes/modal-checkout/class-change-payment-gateway.php +86 -0
- package/includes/modal-checkout/class-checkout-data.php +406 -0
- package/includes/plugins/class-the-events-calendar.php +84 -0
- package/includes/tracking/class-data-events.php +83 -0
- package/languages/newspack-blocks-de_DE-01a5b44b8bc8d20f62541de420aa61ab.json +1 -0
- package/languages/newspack-blocks-de_DE-0662222bf15e7a1a7b74db2dabb48d6c.json +1 -0
- package/languages/newspack-blocks-de_DE-0c8dad524e2a57cee4f8efb6e35387c1.json +1 -0
- package/languages/newspack-blocks-de_DE-10754bc02d28d4301c103f26dbf519ce.json +1 -0
- package/languages/newspack-blocks-de_DE-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -0
- package/languages/newspack-blocks-de_DE-34e5c64f90b1444f3fc735376442eada.json +1 -0
- package/languages/newspack-blocks-de_DE-351fd022e077061b5796bf7042446bfc.json +1 -0
- package/languages/newspack-blocks-de_DE-37552bb09e2a9fceec1970e3c6d46557.json +1 -0
- package/languages/newspack-blocks-de_DE-4b2ccb4e4dc8b3491228b2feb54872f2.json +1 -0
- package/languages/newspack-blocks-de_DE-4cecf783e091d36284a3e0cdafcd0fd5.json +1 -0
- package/languages/newspack-blocks-de_DE-4f16e21047908d19937bc10ced63acd1.json +1 -0
- package/languages/newspack-blocks-de_DE-4fdea541976076f02d56139fb35e5b42.json +1 -0
- package/languages/newspack-blocks-de_DE-501b38ac90d35730a620fb0d483702fa.json +1 -0
- package/languages/newspack-blocks-de_DE-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -0
- package/languages/newspack-blocks-de_DE-5d4055f484eeb00e3ea0f9d8aace0897.json +1 -0
- package/languages/newspack-blocks-de_DE-5f70538e0223bc8a05b922cba67da6fb.json +1 -0
- package/languages/newspack-blocks-de_DE-6c2e53bab28419c30e1eaee70ba599cf.json +1 -0
- package/languages/newspack-blocks-de_DE-6ed95fb4873e6e2b81351177a44995f6.json +1 -0
- package/languages/newspack-blocks-de_DE-727631509ad8eec8e2cbe740c6dad199.json +1 -0
- package/languages/newspack-blocks-de_DE-73c6d3bde805172d1993f75397e9832d.json +1 -0
- package/languages/newspack-blocks-de_DE-78456b164809d080adecb4d2b3895802.json +1 -0
- package/languages/newspack-blocks-de_DE-7b1aa64ce2d962decc04666ab86c53de.json +1 -0
- package/languages/newspack-blocks-de_DE-7c29764d5ef91723f5ce454f66431b9e.json +1 -0
- package/languages/newspack-blocks-de_DE-912a2876091ef0dca9b26f3cfc01fc9c.json +1 -0
- package/languages/newspack-blocks-de_DE-91a7ac8017d6e2159be1c5a3c1e372e4.json +1 -0
- package/languages/newspack-blocks-de_DE-969286d51bb0afe10983b9aec317b5ee.json +1 -0
- package/languages/newspack-blocks-de_DE-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -0
- package/languages/newspack-blocks-de_DE-a822c3d210c89af3cb7da28eaaef929c.json +1 -0
- package/languages/newspack-blocks-de_DE-aa9f9057c77a46b31d7e325a4322f2da.json +1 -0
- package/languages/newspack-blocks-de_DE-b6d3cfc30bb16d88d7bc5384bc775543.json +1 -0
- package/languages/newspack-blocks-de_DE-b712270cd4eb3cae7899b50b57bdd576.json +1 -0
- package/languages/newspack-blocks-de_DE-babcc0ca24e7f0145b1c8f647049f085.json +1 -0
- package/languages/newspack-blocks-de_DE-bb66d96d450663284550bed5a3e9113e.json +1 -0
- package/languages/newspack-blocks-de_DE-c810378e74f20906b8193ea76adb6bc0.json +1 -0
- package/languages/newspack-blocks-de_DE-d3a1c55a07efd1a65e227bf120840752.json +1 -0
- package/languages/newspack-blocks-de_DE-d5f23a52ecbfd492ebf819c14206a9e2.json +1 -0
- package/languages/newspack-blocks-de_DE-d684e5c5ac51934ba20811c2f588e1d5.json +1 -0
- package/languages/newspack-blocks-de_DE-dd56360b115d1b39c48033c1e0749a11.json +1 -0
- package/languages/newspack-blocks-de_DE-e0e4434aee4db01e71268ce3edf1dd97.json +1 -0
- package/languages/newspack-blocks-de_DE-e58126c278611ed6c17684ba8e7459b4.json +1 -0
- package/languages/newspack-blocks-de_DE-ea3e2a660753c7bfa13b5bbd8a46bdd0.json +1 -0
- package/languages/newspack-blocks-de_DE-eccbc51a43c04f59165364eda71e0be7.json +1 -0
- package/languages/newspack-blocks-de_DE-eeb28f99adedd5fad3081d2756d6f4a4.json +1 -0
- package/languages/newspack-blocks-de_DE-f03802d9ac1ae8f3b85caee4347b93a7.json +1 -0
- package/languages/newspack-blocks-de_DE-f32a4d8bd8f1f1e03b6523dfaa4c9f73.json +1 -0
- package/languages/newspack-blocks-de_DE-f5f8db76788e4079ddfa743333708b88.json +1 -0
- package/languages/newspack-blocks-de_DE-f8b1589c450689398f90b179f47e74ee.json +1 -0
- package/languages/newspack-blocks-de_DE-f9d0b05d4d6ddd3273f1f3fb2eb2ca50.json +1 -0
- package/languages/newspack-blocks-de_DE-fbe7f8c598cf05d4603ba49fec909ded.json +1 -0
- package/languages/newspack-blocks-de_DE-fcc93143c1f2b74671f595454b971f44.json +1 -0
- package/languages/newspack-blocks-de_DE.mo +0 -0
- package/languages/newspack-blocks-de_DE.po +2088 -0
- package/languages/newspack-blocks-es_ES-01a5b44b8bc8d20f62541de420aa61ab.json +1 -0
- package/languages/newspack-blocks-es_ES-0662222bf15e7a1a7b74db2dabb48d6c.json +1 -0
- package/languages/newspack-blocks-es_ES-0c8dad524e2a57cee4f8efb6e35387c1.json +1 -0
- package/languages/newspack-blocks-es_ES-10754bc02d28d4301c103f26dbf519ce.json +1 -0
- package/languages/newspack-blocks-es_ES-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -0
- package/languages/newspack-blocks-es_ES-34e5c64f90b1444f3fc735376442eada.json +1 -0
- package/languages/newspack-blocks-es_ES-351fd022e077061b5796bf7042446bfc.json +1 -0
- package/languages/newspack-blocks-es_ES-37552bb09e2a9fceec1970e3c6d46557.json +1 -0
- package/languages/newspack-blocks-es_ES-4b2ccb4e4dc8b3491228b2feb54872f2.json +1 -0
- package/languages/newspack-blocks-es_ES-4cecf783e091d36284a3e0cdafcd0fd5.json +1 -0
- package/languages/newspack-blocks-es_ES-4f16e21047908d19937bc10ced63acd1.json +1 -0
- package/languages/newspack-blocks-es_ES-4fdea541976076f02d56139fb35e5b42.json +1 -0
- package/languages/newspack-blocks-es_ES-501b38ac90d35730a620fb0d483702fa.json +1 -0
- package/languages/newspack-blocks-es_ES-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -0
- package/languages/newspack-blocks-es_ES-5d4055f484eeb00e3ea0f9d8aace0897.json +1 -0
- package/languages/newspack-blocks-es_ES-5f70538e0223bc8a05b922cba67da6fb.json +1 -0
- package/languages/newspack-blocks-es_ES-6c2e53bab28419c30e1eaee70ba599cf.json +1 -0
- package/languages/newspack-blocks-es_ES-6ed95fb4873e6e2b81351177a44995f6.json +1 -0
- package/languages/newspack-blocks-es_ES-727631509ad8eec8e2cbe740c6dad199.json +1 -0
- package/languages/newspack-blocks-es_ES-73c6d3bde805172d1993f75397e9832d.json +1 -0
- package/languages/newspack-blocks-es_ES-78456b164809d080adecb4d2b3895802.json +1 -0
- package/languages/newspack-blocks-es_ES-7b1aa64ce2d962decc04666ab86c53de.json +1 -0
- package/languages/newspack-blocks-es_ES-7c29764d5ef91723f5ce454f66431b9e.json +1 -0
- package/languages/newspack-blocks-es_ES-912a2876091ef0dca9b26f3cfc01fc9c.json +1 -0
- package/languages/newspack-blocks-es_ES-91a7ac8017d6e2159be1c5a3c1e372e4.json +1 -0
- package/languages/newspack-blocks-es_ES-969286d51bb0afe10983b9aec317b5ee.json +1 -0
- package/languages/newspack-blocks-es_ES-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -0
- package/languages/newspack-blocks-es_ES-a822c3d210c89af3cb7da28eaaef929c.json +1 -0
- package/languages/newspack-blocks-es_ES-aa9f9057c77a46b31d7e325a4322f2da.json +1 -0
- package/languages/newspack-blocks-es_ES-b6d3cfc30bb16d88d7bc5384bc775543.json +1 -0
- package/languages/newspack-blocks-es_ES-b712270cd4eb3cae7899b50b57bdd576.json +1 -0
- package/languages/newspack-blocks-es_ES-babcc0ca24e7f0145b1c8f647049f085.json +1 -0
- package/languages/newspack-blocks-es_ES-bb66d96d450663284550bed5a3e9113e.json +1 -0
- package/languages/newspack-blocks-es_ES-c810378e74f20906b8193ea76adb6bc0.json +1 -0
- package/languages/newspack-blocks-es_ES-d3a1c55a07efd1a65e227bf120840752.json +1 -0
- package/languages/newspack-blocks-es_ES-d5f23a52ecbfd492ebf819c14206a9e2.json +1 -0
- package/languages/newspack-blocks-es_ES-d684e5c5ac51934ba20811c2f588e1d5.json +1 -0
- package/languages/newspack-blocks-es_ES-dd56360b115d1b39c48033c1e0749a11.json +1 -0
- package/languages/newspack-blocks-es_ES-e0e4434aee4db01e71268ce3edf1dd97.json +1 -0
- package/languages/newspack-blocks-es_ES-e58126c278611ed6c17684ba8e7459b4.json +1 -0
- package/languages/newspack-blocks-es_ES-ea3e2a660753c7bfa13b5bbd8a46bdd0.json +1 -0
- package/languages/newspack-blocks-es_ES-eccbc51a43c04f59165364eda71e0be7.json +1 -0
- package/languages/newspack-blocks-es_ES-eeb28f99adedd5fad3081d2756d6f4a4.json +1 -0
- package/languages/newspack-blocks-es_ES-f03802d9ac1ae8f3b85caee4347b93a7.json +1 -0
- package/languages/newspack-blocks-es_ES-f32a4d8bd8f1f1e03b6523dfaa4c9f73.json +1 -0
- package/languages/newspack-blocks-es_ES-f5f8db76788e4079ddfa743333708b88.json +1 -0
- package/languages/newspack-blocks-es_ES-f8b1589c450689398f90b179f47e74ee.json +1 -0
- package/languages/newspack-blocks-es_ES-f9d0b05d4d6ddd3273f1f3fb2eb2ca50.json +1 -0
- package/languages/newspack-blocks-es_ES-fbe7f8c598cf05d4603ba49fec909ded.json +1 -0
- package/languages/newspack-blocks-es_ES-fcc93143c1f2b74671f595454b971f44.json +1 -0
- package/languages/newspack-blocks-es_ES.mo +0 -0
- package/languages/newspack-blocks-es_ES.po +2080 -0
- package/languages/newspack-blocks-fr_BE-01a5b44b8bc8d20f62541de420aa61ab.json +1 -0
- package/languages/newspack-blocks-fr_BE-0662222bf15e7a1a7b74db2dabb48d6c.json +1 -0
- package/languages/newspack-blocks-fr_BE-0c8dad524e2a57cee4f8efb6e35387c1.json +1 -0
- package/languages/newspack-blocks-fr_BE-10754bc02d28d4301c103f26dbf519ce.json +1 -0
- package/languages/newspack-blocks-fr_BE-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -0
- package/languages/newspack-blocks-fr_BE-34e5c64f90b1444f3fc735376442eada.json +1 -0
- package/languages/newspack-blocks-fr_BE-351fd022e077061b5796bf7042446bfc.json +1 -0
- package/languages/newspack-blocks-fr_BE-37552bb09e2a9fceec1970e3c6d46557.json +1 -0
- package/languages/newspack-blocks-fr_BE-4b2ccb4e4dc8b3491228b2feb54872f2.json +1 -0
- package/languages/newspack-blocks-fr_BE-4cecf783e091d36284a3e0cdafcd0fd5.json +1 -0
- package/languages/newspack-blocks-fr_BE-4f16e21047908d19937bc10ced63acd1.json +1 -0
- package/languages/newspack-blocks-fr_BE-4fdea541976076f02d56139fb35e5b42.json +1 -0
- package/languages/newspack-blocks-fr_BE-501b38ac90d35730a620fb0d483702fa.json +1 -0
- package/languages/newspack-blocks-fr_BE-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -0
- package/languages/newspack-blocks-fr_BE-5d4055f484eeb00e3ea0f9d8aace0897.json +1 -0
- package/languages/newspack-blocks-fr_BE-5f70538e0223bc8a05b922cba67da6fb.json +1 -0
- package/languages/newspack-blocks-fr_BE-6c2e53bab28419c30e1eaee70ba599cf.json +1 -0
- package/languages/newspack-blocks-fr_BE-6ed95fb4873e6e2b81351177a44995f6.json +1 -0
- package/languages/newspack-blocks-fr_BE-727631509ad8eec8e2cbe740c6dad199.json +1 -0
- package/languages/newspack-blocks-fr_BE-73c6d3bde805172d1993f75397e9832d.json +1 -0
- package/languages/newspack-blocks-fr_BE-78456b164809d080adecb4d2b3895802.json +1 -0
- package/languages/newspack-blocks-fr_BE-7b1aa64ce2d962decc04666ab86c53de.json +1 -0
- package/languages/newspack-blocks-fr_BE-7c29764d5ef91723f5ce454f66431b9e.json +1 -0
- package/languages/newspack-blocks-fr_BE-912a2876091ef0dca9b26f3cfc01fc9c.json +1 -0
- package/languages/newspack-blocks-fr_BE-91a7ac8017d6e2159be1c5a3c1e372e4.json +1 -0
- package/languages/newspack-blocks-fr_BE-969286d51bb0afe10983b9aec317b5ee.json +1 -0
- package/languages/newspack-blocks-fr_BE-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -0
- package/languages/newspack-blocks-fr_BE-a822c3d210c89af3cb7da28eaaef929c.json +1 -0
- package/languages/newspack-blocks-fr_BE-aa9f9057c77a46b31d7e325a4322f2da.json +1 -0
- package/languages/newspack-blocks-fr_BE-b6d3cfc30bb16d88d7bc5384bc775543.json +1 -0
- package/languages/newspack-blocks-fr_BE-b712270cd4eb3cae7899b50b57bdd576.json +1 -0
- package/languages/newspack-blocks-fr_BE-babcc0ca24e7f0145b1c8f647049f085.json +1 -0
- package/languages/newspack-blocks-fr_BE-bb66d96d450663284550bed5a3e9113e.json +1 -0
- package/languages/newspack-blocks-fr_BE-c810378e74f20906b8193ea76adb6bc0.json +1 -0
- package/languages/newspack-blocks-fr_BE-d3a1c55a07efd1a65e227bf120840752.json +1 -0
- package/languages/newspack-blocks-fr_BE-d5f23a52ecbfd492ebf819c14206a9e2.json +1 -0
- package/languages/newspack-blocks-fr_BE-d684e5c5ac51934ba20811c2f588e1d5.json +1 -0
- package/languages/newspack-blocks-fr_BE-dd56360b115d1b39c48033c1e0749a11.json +1 -0
- package/languages/newspack-blocks-fr_BE-e0e4434aee4db01e71268ce3edf1dd97.json +1 -0
- package/languages/newspack-blocks-fr_BE-e58126c278611ed6c17684ba8e7459b4.json +1 -0
- package/languages/newspack-blocks-fr_BE-ea3e2a660753c7bfa13b5bbd8a46bdd0.json +1 -0
- package/languages/newspack-blocks-fr_BE-eccbc51a43c04f59165364eda71e0be7.json +1 -0
- package/languages/newspack-blocks-fr_BE-eeb28f99adedd5fad3081d2756d6f4a4.json +1 -0
- package/languages/newspack-blocks-fr_BE-f03802d9ac1ae8f3b85caee4347b93a7.json +1 -0
- package/languages/newspack-blocks-fr_BE-f32a4d8bd8f1f1e03b6523dfaa4c9f73.json +1 -0
- package/languages/newspack-blocks-fr_BE-f5f8db76788e4079ddfa743333708b88.json +1 -0
- package/languages/newspack-blocks-fr_BE-f8b1589c450689398f90b179f47e74ee.json +1 -0
- package/languages/newspack-blocks-fr_BE-f9d0b05d4d6ddd3273f1f3fb2eb2ca50.json +1 -0
- package/languages/newspack-blocks-fr_BE-fbe7f8c598cf05d4603ba49fec909ded.json +1 -0
- package/languages/newspack-blocks-fr_BE-fcc93143c1f2b74671f595454b971f44.json +1 -0
- package/languages/newspack-blocks-fr_BE.mo +0 -0
- package/languages/newspack-blocks-fr_BE.po +2079 -0
- package/languages/newspack-blocks-nb_NO-01a5b44b8bc8d20f62541de420aa61ab.json +1 -0
- package/languages/newspack-blocks-nb_NO-0662222bf15e7a1a7b74db2dabb48d6c.json +1 -0
- package/languages/newspack-blocks-nb_NO-0c8dad524e2a57cee4f8efb6e35387c1.json +1 -0
- package/languages/newspack-blocks-nb_NO-10754bc02d28d4301c103f26dbf519ce.json +1 -0
- package/languages/newspack-blocks-nb_NO-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -0
- package/languages/newspack-blocks-nb_NO-34e5c64f90b1444f3fc735376442eada.json +1 -0
- package/languages/newspack-blocks-nb_NO-351fd022e077061b5796bf7042446bfc.json +1 -0
- package/languages/newspack-blocks-nb_NO-37552bb09e2a9fceec1970e3c6d46557.json +1 -0
- package/languages/newspack-blocks-nb_NO-4b2ccb4e4dc8b3491228b2feb54872f2.json +1 -0
- package/languages/newspack-blocks-nb_NO-4cecf783e091d36284a3e0cdafcd0fd5.json +1 -0
- package/languages/newspack-blocks-nb_NO-4f16e21047908d19937bc10ced63acd1.json +1 -0
- package/languages/newspack-blocks-nb_NO-4fdea541976076f02d56139fb35e5b42.json +1 -0
- package/languages/newspack-blocks-nb_NO-501b38ac90d35730a620fb0d483702fa.json +1 -0
- package/languages/newspack-blocks-nb_NO-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -0
- package/languages/newspack-blocks-nb_NO-5d4055f484eeb00e3ea0f9d8aace0897.json +1 -0
- package/languages/newspack-blocks-nb_NO-5f70538e0223bc8a05b922cba67da6fb.json +1 -0
- package/languages/newspack-blocks-nb_NO-6c2e53bab28419c30e1eaee70ba599cf.json +1 -0
- package/languages/newspack-blocks-nb_NO-6ed95fb4873e6e2b81351177a44995f6.json +1 -0
- package/languages/newspack-blocks-nb_NO-73c6d3bde805172d1993f75397e9832d.json +1 -0
- package/languages/newspack-blocks-nb_NO-78456b164809d080adecb4d2b3895802.json +1 -0
- package/languages/newspack-blocks-nb_NO-7b1aa64ce2d962decc04666ab86c53de.json +1 -0
- package/languages/newspack-blocks-nb_NO-7c29764d5ef91723f5ce454f66431b9e.json +1 -0
- package/languages/newspack-blocks-nb_NO-912a2876091ef0dca9b26f3cfc01fc9c.json +1 -0
- package/languages/newspack-blocks-nb_NO-91a7ac8017d6e2159be1c5a3c1e372e4.json +1 -0
- package/languages/newspack-blocks-nb_NO-969286d51bb0afe10983b9aec317b5ee.json +1 -0
- package/languages/newspack-blocks-nb_NO-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -0
- package/languages/newspack-blocks-nb_NO-a822c3d210c89af3cb7da28eaaef929c.json +1 -0
- package/languages/newspack-blocks-nb_NO-aa9f9057c77a46b31d7e325a4322f2da.json +1 -0
- package/languages/newspack-blocks-nb_NO-b6d3cfc30bb16d88d7bc5384bc775543.json +1 -0
- package/languages/newspack-blocks-nb_NO-b712270cd4eb3cae7899b50b57bdd576.json +1 -0
- package/languages/newspack-blocks-nb_NO-babcc0ca24e7f0145b1c8f647049f085.json +1 -0
- package/languages/newspack-blocks-nb_NO-bb66d96d450663284550bed5a3e9113e.json +1 -0
- package/languages/newspack-blocks-nb_NO-c810378e74f20906b8193ea76adb6bc0.json +1 -0
- package/languages/newspack-blocks-nb_NO-d3a1c55a07efd1a65e227bf120840752.json +1 -0
- package/languages/newspack-blocks-nb_NO-d5f23a52ecbfd492ebf819c14206a9e2.json +1 -0
- package/languages/newspack-blocks-nb_NO-d684e5c5ac51934ba20811c2f588e1d5.json +1 -0
- package/languages/newspack-blocks-nb_NO-dd56360b115d1b39c48033c1e0749a11.json +1 -0
- package/languages/newspack-blocks-nb_NO-e0e4434aee4db01e71268ce3edf1dd97.json +1 -0
- package/languages/newspack-blocks-nb_NO-e58126c278611ed6c17684ba8e7459b4.json +1 -0
- package/languages/newspack-blocks-nb_NO-ea3e2a660753c7bfa13b5bbd8a46bdd0.json +1 -0
- package/languages/newspack-blocks-nb_NO-eccbc51a43c04f59165364eda71e0be7.json +1 -0
- package/languages/newspack-blocks-nb_NO-eeb28f99adedd5fad3081d2756d6f4a4.json +1 -0
- package/languages/newspack-blocks-nb_NO-f03802d9ac1ae8f3b85caee4347b93a7.json +1 -0
- package/languages/newspack-blocks-nb_NO-f32a4d8bd8f1f1e03b6523dfaa4c9f73.json +1 -0
- package/languages/newspack-blocks-nb_NO-f5f8db76788e4079ddfa743333708b88.json +1 -0
- package/languages/newspack-blocks-nb_NO-f8b1589c450689398f90b179f47e74ee.json +1 -0
- package/languages/newspack-blocks-nb_NO-f9d0b05d4d6ddd3273f1f3fb2eb2ca50.json +1 -0
- package/languages/newspack-blocks-nb_NO-fbe7f8c598cf05d4603ba49fec909ded.json +1 -0
- package/languages/newspack-blocks-nb_NO-fcc93143c1f2b74671f595454b971f44.json +1 -0
- package/languages/newspack-blocks-nb_NO.mo +0 -0
- package/languages/newspack-blocks-nb_NO.po +2078 -0
- package/languages/newspack-blocks-pt_PT-01a5b44b8bc8d20f62541de420aa61ab.json +1 -0
- package/languages/newspack-blocks-pt_PT-0662222bf15e7a1a7b74db2dabb48d6c.json +1 -0
- package/languages/newspack-blocks-pt_PT-0c8dad524e2a57cee4f8efb6e35387c1.json +1 -0
- package/languages/newspack-blocks-pt_PT-10754bc02d28d4301c103f26dbf519ce.json +1 -0
- package/languages/newspack-blocks-pt_PT-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -0
- package/languages/newspack-blocks-pt_PT-34e5c64f90b1444f3fc735376442eada.json +1 -0
- package/languages/newspack-blocks-pt_PT-351fd022e077061b5796bf7042446bfc.json +1 -0
- package/languages/newspack-blocks-pt_PT-37552bb09e2a9fceec1970e3c6d46557.json +1 -0
- package/languages/newspack-blocks-pt_PT-4b2ccb4e4dc8b3491228b2feb54872f2.json +1 -0
- package/languages/newspack-blocks-pt_PT-4cecf783e091d36284a3e0cdafcd0fd5.json +1 -0
- package/languages/newspack-blocks-pt_PT-4f16e21047908d19937bc10ced63acd1.json +1 -0
- package/languages/newspack-blocks-pt_PT-4fdea541976076f02d56139fb35e5b42.json +1 -0
- package/languages/newspack-blocks-pt_PT-501b38ac90d35730a620fb0d483702fa.json +1 -0
- package/languages/newspack-blocks-pt_PT-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -0
- package/languages/newspack-blocks-pt_PT-5d4055f484eeb00e3ea0f9d8aace0897.json +1 -0
- package/languages/newspack-blocks-pt_PT-5f70538e0223bc8a05b922cba67da6fb.json +1 -0
- package/languages/newspack-blocks-pt_PT-6c2e53bab28419c30e1eaee70ba599cf.json +1 -0
- package/languages/newspack-blocks-pt_PT-6ed95fb4873e6e2b81351177a44995f6.json +1 -0
- package/languages/newspack-blocks-pt_PT-727631509ad8eec8e2cbe740c6dad199.json +1 -0
- package/languages/newspack-blocks-pt_PT-73c6d3bde805172d1993f75397e9832d.json +1 -0
- package/languages/newspack-blocks-pt_PT-78456b164809d080adecb4d2b3895802.json +1 -0
- package/languages/newspack-blocks-pt_PT-7b1aa64ce2d962decc04666ab86c53de.json +1 -0
- package/languages/newspack-blocks-pt_PT-7c29764d5ef91723f5ce454f66431b9e.json +1 -0
- package/languages/newspack-blocks-pt_PT-912a2876091ef0dca9b26f3cfc01fc9c.json +1 -0
- package/languages/newspack-blocks-pt_PT-91a7ac8017d6e2159be1c5a3c1e372e4.json +1 -0
- package/languages/newspack-blocks-pt_PT-969286d51bb0afe10983b9aec317b5ee.json +1 -0
- package/languages/newspack-blocks-pt_PT-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -0
- package/languages/newspack-blocks-pt_PT-a822c3d210c89af3cb7da28eaaef929c.json +1 -0
- package/languages/newspack-blocks-pt_PT-aa9f9057c77a46b31d7e325a4322f2da.json +1 -0
- package/languages/newspack-blocks-pt_PT-b6d3cfc30bb16d88d7bc5384bc775543.json +1 -0
- package/languages/newspack-blocks-pt_PT-b712270cd4eb3cae7899b50b57bdd576.json +1 -0
- package/languages/newspack-blocks-pt_PT-babcc0ca24e7f0145b1c8f647049f085.json +1 -0
- package/languages/newspack-blocks-pt_PT-bb66d96d450663284550bed5a3e9113e.json +1 -0
- package/languages/newspack-blocks-pt_PT-c810378e74f20906b8193ea76adb6bc0.json +1 -0
- package/languages/newspack-blocks-pt_PT-d3a1c55a07efd1a65e227bf120840752.json +1 -0
- package/languages/newspack-blocks-pt_PT-d5f23a52ecbfd492ebf819c14206a9e2.json +1 -0
- package/languages/newspack-blocks-pt_PT-d684e5c5ac51934ba20811c2f588e1d5.json +1 -0
- package/languages/newspack-blocks-pt_PT-dd56360b115d1b39c48033c1e0749a11.json +1 -0
- package/languages/newspack-blocks-pt_PT-e0e4434aee4db01e71268ce3edf1dd97.json +1 -0
- package/languages/newspack-blocks-pt_PT-e58126c278611ed6c17684ba8e7459b4.json +1 -0
- package/languages/newspack-blocks-pt_PT-ea3e2a660753c7bfa13b5bbd8a46bdd0.json +1 -0
- package/languages/newspack-blocks-pt_PT-eccbc51a43c04f59165364eda71e0be7.json +1 -0
- package/languages/newspack-blocks-pt_PT-eeb28f99adedd5fad3081d2756d6f4a4.json +1 -0
- package/languages/newspack-blocks-pt_PT-f03802d9ac1ae8f3b85caee4347b93a7.json +1 -0
- package/languages/newspack-blocks-pt_PT-f32a4d8bd8f1f1e03b6523dfaa4c9f73.json +1 -0
- package/languages/newspack-blocks-pt_PT-f5f8db76788e4079ddfa743333708b88.json +1 -0
- package/languages/newspack-blocks-pt_PT-f8b1589c450689398f90b179f47e74ee.json +1 -0
- package/languages/newspack-blocks-pt_PT-f9d0b05d4d6ddd3273f1f3fb2eb2ca50.json +1 -0
- package/languages/newspack-blocks-pt_PT-fbe7f8c598cf05d4603ba49fec909ded.json +1 -0
- package/languages/newspack-blocks-pt_PT-fcc93143c1f2b74671f595454b971f44.json +1 -0
- package/languages/newspack-blocks-pt_PT.mo +0 -0
- package/languages/newspack-blocks-pt_PT.po +2078 -0
- package/languages/newspack-blocks.pot +2370 -0
- package/newspack-blocks.php +96 -0
- package/package.json +64 -0
- package/phpcs.xml +38 -0
- package/release.config.js +1 -0
- package/src/assets/placeholder-1024x536.jpg +0 -0
- package/src/assets/placeholder-600x800.jpg +0 -0
- package/src/assets/placeholder-800x600.jpg +0 -0
- package/src/assets/placeholder-800x800.jpg +0 -0
- package/src/assets/placeholder-donations-cover.jpg +0 -0
- package/src/assets/placeholder-donations-image.jpg +0 -0
- package/src/assets/placeholder-subscribe-cover.jpg +0 -0
- package/src/assets/placeholder-subscribe-image.jpg +0 -0
- package/src/block-patterns/donations-1.php +13 -0
- package/src/block-patterns/donations-2.php +13 -0
- package/src/block-patterns/donations-3.php +13 -0
- package/src/block-patterns/donations-4.php +13 -0
- package/src/block-patterns/donations-5.php +13 -0
- package/src/block-patterns/homepage-posts-1.php +13 -0
- package/src/block-patterns/homepage-posts-10.php +13 -0
- package/src/block-patterns/homepage-posts-11.php +13 -0
- package/src/block-patterns/homepage-posts-12.php +13 -0
- package/src/block-patterns/homepage-posts-13.php +13 -0
- package/src/block-patterns/homepage-posts-14.php +13 -0
- package/src/block-patterns/homepage-posts-15.php +13 -0
- package/src/block-patterns/homepage-posts-16.php +13 -0
- package/src/block-patterns/homepage-posts-17.php +13 -0
- package/src/block-patterns/homepage-posts-18.php +13 -0
- package/src/block-patterns/homepage-posts-19.php +13 -0
- package/src/block-patterns/homepage-posts-2.php +13 -0
- package/src/block-patterns/homepage-posts-20.php +13 -0
- package/src/block-patterns/homepage-posts-21.php +13 -0
- package/src/block-patterns/homepage-posts-22.php +13 -0
- package/src/block-patterns/homepage-posts-23.php +13 -0
- package/src/block-patterns/homepage-posts-24.php +13 -0
- package/src/block-patterns/homepage-posts-25.php +13 -0
- package/src/block-patterns/homepage-posts-26.php +13 -0
- package/src/block-patterns/homepage-posts-27.php +13 -0
- package/src/block-patterns/homepage-posts-28.php +13 -0
- package/src/block-patterns/homepage-posts-29.php +13 -0
- package/src/block-patterns/homepage-posts-3.php +13 -0
- package/src/block-patterns/homepage-posts-30.php +13 -0
- package/src/block-patterns/homepage-posts-31.php +13 -0
- package/src/block-patterns/homepage-posts-4.php +13 -0
- package/src/block-patterns/homepage-posts-5.php +13 -0
- package/src/block-patterns/homepage-posts-6.php +13 -0
- package/src/block-patterns/homepage-posts-7.php +13 -0
- package/src/block-patterns/homepage-posts-8.php +13 -0
- package/src/block-patterns/homepage-posts-9.php +13 -0
- package/src/block-patterns/subscribe-1.php +13 -0
- package/src/block-patterns/subscribe-2.php +13 -0
- package/src/block-patterns/subscribe-3.php +13 -0
- package/src/block-patterns/subscribe-4.php +13 -0
- package/src/block-patterns/subscribe-5.php +13 -0
- package/src/block-patterns/subscribe-6.php +13 -0
- package/src/block-patterns/subscribe-7.php +13 -0
- package/src/block-styles/core/columns/editor.scss +90 -0
- package/src/block-styles/core/columns/index.js +20 -0
- package/src/block-styles/core/columns/view.scss +131 -0
- package/src/block-styles/core/group/editor.scss +24 -0
- package/src/block-styles/core/group/index.js +25 -0
- package/src/block-styles/core/group/view.scss +13 -0
- package/src/block-styles/view.js +5 -0
- package/src/blocks/author-list/block.json +84 -0
- package/src/blocks/author-list/class-wp-rest-newspack-author-list-controller.php +381 -0
- package/src/blocks/author-list/edit.js +456 -0
- package/src/blocks/author-list/editor.js +7 -0
- package/src/blocks/author-list/editor.scss +1 -0
- package/src/blocks/author-list/index.js +60 -0
- package/src/blocks/author-list/view.js +5 -0
- package/src/blocks/author-list/view.php +180 -0
- package/src/blocks/author-list/view.scss +46 -0
- package/src/blocks/author-profile/README.md +105 -0
- package/src/blocks/author-profile/block.json +77 -0
- package/src/blocks/author-profile/class-wp-rest-newspack-authors-controller.php +618 -0
- package/src/blocks/author-profile/context.js +26 -0
- package/src/blocks/author-profile/edit.js +1031 -0
- package/src/blocks/author-profile/editor.js +7 -0
- package/src/blocks/author-profile/editor.scss +61 -0
- package/src/blocks/author-profile/index.js +66 -0
- package/src/blocks/author-profile/single-author.js +106 -0
- package/src/blocks/author-profile/templates.js +263 -0
- package/src/blocks/author-profile/variations.js +86 -0
- package/src/blocks/author-profile/view.js +5 -0
- package/src/blocks/author-profile/view.php +501 -0
- package/src/blocks/author-profile/view.scss +159 -0
- package/src/blocks/carousel/block.json +121 -0
- package/src/blocks/carousel/create-swiper.js +230 -0
- package/src/blocks/carousel/edit.js +469 -0
- package/src/blocks/carousel/editor.js +7 -0
- package/src/blocks/carousel/editor.scss +54 -0
- package/src/blocks/carousel/index.js +55 -0
- package/src/blocks/carousel/view.js +49 -0
- package/src/blocks/carousel/view.php +417 -0
- package/src/blocks/carousel/view.scss +397 -0
- package/src/blocks/checkout-button/block.json +117 -0
- package/src/blocks/checkout-button/deprecated.js +81 -0
- package/src/blocks/checkout-button/edit.js +385 -0
- package/src/blocks/checkout-button/edit.scss +67 -0
- package/src/blocks/checkout-button/editor.js +19 -0
- package/src/blocks/checkout-button/index.js +32 -0
- package/src/blocks/checkout-button/view.js +4 -0
- package/src/blocks/checkout-button/view.php +178 -0
- package/src/blocks/checkout-button/view.scss +39 -0
- package/src/blocks/donate/block.json +103 -0
- package/src/blocks/donate/consts.ts +25 -0
- package/src/blocks/donate/edit/FrequencyBasedLayout.tsx +255 -0
- package/src/blocks/donate/edit/TierBasedLayout.tsx +133 -0
- package/src/blocks/donate/edit/components/AmountValueInput.tsx +62 -0
- package/src/blocks/donate/edit/components/index.tsx +1 -0
- package/src/blocks/donate/edit/index.tsx +445 -0
- package/src/blocks/donate/editor.js +7 -0
- package/src/blocks/donate/frequency-based/index.ts +135 -0
- package/src/blocks/donate/frequency-based/style.scss +245 -0
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php +225 -0
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php +341 -0
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php +184 -0
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php +117 -0
- package/src/blocks/donate/index.js +72 -0
- package/src/blocks/donate/styles/editor.scss +230 -0
- package/src/blocks/donate/styles/style-variations.scss +792 -0
- package/src/blocks/donate/styles/view.scss +45 -0
- package/src/blocks/donate/tiers-based/index.ts +36 -0
- package/src/blocks/donate/tiers-based/slider.ts +64 -0
- package/src/blocks/donate/tiers-based/style.scss +185 -0
- package/src/blocks/donate/tiers-based/types.ts +3 -0
- package/src/blocks/donate/tiers-based/utils.test.js +38 -0
- package/src/blocks/donate/tiers-based/utils.ts +21 -0
- package/src/blocks/donate/tiers-based/view.ts +132 -0
- package/src/blocks/donate/types.ts +96 -0
- package/src/blocks/donate/utils.ts +108 -0
- package/src/blocks/donate/view.php +29 -0
- package/src/blocks/donate/view.ts +44 -0
- package/src/blocks/homepage-articles/block.json +260 -0
- package/src/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php +231 -0
- package/src/blocks/homepage-articles/edit.tsx +730 -0
- package/src/blocks/homepage-articles/editor.js +16 -0
- package/src/blocks/homepage-articles/editor.scss +226 -0
- package/src/blocks/homepage-articles/index.js +102 -0
- package/src/blocks/homepage-articles/store.js +193 -0
- package/src/blocks/homepage-articles/templates/article.php +290 -0
- package/src/blocks/homepage-articles/templates/articles-list.php +21 -0
- package/src/blocks/homepage-articles/templates/articles-loop.php +35 -0
- package/src/blocks/homepage-articles/utils.ts +270 -0
- package/src/blocks/homepage-articles/view.js +242 -0
- package/src/blocks/homepage-articles/view.php +561 -0
- package/src/blocks/homepage-articles/view.scss +784 -0
- package/src/blocks/iframe/block.json +36 -0
- package/src/blocks/iframe/class-wp-rest-newspack-iframe-controller.php +586 -0
- package/src/blocks/iframe/edit.js +232 -0
- package/src/blocks/iframe/editor.js +7 -0
- package/src/blocks/iframe/editor.scss +84 -0
- package/src/blocks/iframe/iframe-placeholder.js +166 -0
- package/src/blocks/iframe/index.js +54 -0
- package/src/blocks/iframe/view.js +49 -0
- package/src/blocks/iframe/view.php +116 -0
- package/src/blocks/iframe/view.scss +9 -0
- package/src/blocks/shared/author.js +47 -0
- package/src/blocks/video-playlist/edit.js +222 -0
- package/src/blocks/video-playlist/editor.js +7 -0
- package/src/blocks/video-playlist/editor.scss +23 -0
- package/src/blocks/video-playlist/index.js +54 -0
- package/src/blocks/video-playlist/view.php +188 -0
- package/src/components/autocomplete-tokenfield.js +189 -0
- package/src/components/autocomplete-tokenfield.scss +27 -0
- package/src/components/editor-panels.js +90 -0
- package/src/components/query-controls.js +450 -0
- package/src/components/redirect-after-success.tsx +50 -0
- package/src/modal-checkout/accessibility.js +73 -0
- package/src/modal-checkout/analytics/ga4/README.md +45 -0
- package/src/modal-checkout/analytics/ga4/checkout-attempt.js +18 -0
- package/src/modal-checkout/analytics/ga4/checkout-success.js +17 -0
- package/src/modal-checkout/analytics/ga4/dismissed.js +17 -0
- package/src/modal-checkout/analytics/ga4/loaded.js +17 -0
- package/src/modal-checkout/analytics/ga4/opened.js +37 -0
- package/src/modal-checkout/analytics/ga4/pagination.js +59 -0
- package/src/modal-checkout/analytics/ga4/utils/index.js +64 -0
- package/src/modal-checkout/analytics/index.js +6 -0
- package/src/modal-checkout/checkout.scss +1064 -0
- package/src/modal-checkout/index.js +929 -0
- package/src/modal-checkout/modal.js +983 -0
- package/src/modal-checkout/modal.scss +265 -0
- package/src/modal-checkout/templates/empty-html-add-recipient.php +15 -0
- package/src/modal-checkout/templates/empty-order-details.php +16 -0
- package/src/modal-checkout/templates/form-change-payment-method.php +99 -0
- package/src/modal-checkout/templates/form-checkout.php +74 -0
- package/src/modal-checkout/templates/form-coupon.php +22 -0
- package/src/modal-checkout/templates/form-gift-subscription.php +34 -0
- package/src/modal-checkout/templates/payment-method.php +29 -0
- package/src/modal-checkout/templates/thankyou.php +94 -0
- package/src/modal-checkout/utils.js +309 -0
- package/src/setup/block-styles.js +2 -0
- package/src/setup/category.js +18 -0
- package/src/setup/editor.js +7 -0
- package/src/setup/editor.scss +56 -0
- package/src/setup/newspack-logo.js +26 -0
- package/src/setup/placeholder-blocks.js +84 -0
- package/src/setup/unregister-blocks.js +14 -0
- package/src/shared/authors.php +63 -0
- package/src/shared/js/newspack-icon.js +31 -0
- package/src/shared/js/utils.js +50 -0
- package/src/shared/sass/_mixins.scss +42 -0
- package/src/shared/sass/_placeholder.scss +5 -0
- package/src/shared/sass/_preview.scss +12 -0
- package/src/shared/sass/_variables.scss +24 -0
- package/src/templates/author-profile-card.php +145 -0
- package/src/types/@wordpress/block-editor.d.ts +1 -0
- package/src/types/@wordpress/components.d.ts +1 -0
- package/src/types/index.d.ts +170 -0
- package/src/types/newspack-components.d.ts +7 -0
- package/tsconfig.json +7 -0
- package/vendor/autoload.php +22 -0
- package/vendor/composer/ClassLoader.php +579 -0
- package/vendor/composer/InstalledVersions.php +396 -0
- package/vendor/composer/LICENSE +21 -0
- package/vendor/composer/autoload_classmap.php +10 -0
- package/vendor/composer/autoload_namespaces.php +9 -0
- package/vendor/composer/autoload_psr4.php +9 -0
- package/vendor/composer/autoload_real.php +36 -0
- package/vendor/composer/autoload_static.php +20 -0
- package/vendor/composer/installed.json +5 -0
- package/vendor/composer/installed.php +23 -0
- package/webpack.config.js +82 -0
|
@@ -0,0 +1,983 @@
|
|
|
1
|
+
/* globals newspackBlocksModal, newspack_ras_config */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Style dependencies
|
|
5
|
+
*/
|
|
6
|
+
import './modal.scss';
|
|
7
|
+
import * as a11y from './accessibility.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { manageDismissed, manageOpened } from './analytics';
|
|
13
|
+
import {
|
|
14
|
+
domReady,
|
|
15
|
+
iframeReady,
|
|
16
|
+
onCheckoutReady,
|
|
17
|
+
onCheckoutComplete,
|
|
18
|
+
onCheckoutCancel,
|
|
19
|
+
onCheckoutPlaceOrderStart,
|
|
20
|
+
onCheckoutPlaceOrderError,
|
|
21
|
+
onCheckoutPlaceOrderCriticalError,
|
|
22
|
+
createHiddenInput,
|
|
23
|
+
triggerFormSubmit,
|
|
24
|
+
getCheckoutData,
|
|
25
|
+
getFormattedAmount,
|
|
26
|
+
} from './utils';
|
|
27
|
+
|
|
28
|
+
const CLASS_PREFIX = newspackBlocksModal.newspack_class_prefix;
|
|
29
|
+
const IFRAME_NAME = 'newspack_modal_checkout_iframe';
|
|
30
|
+
const IFRAME_CONTAINER_ID = 'newspack_modal_checkout_container';
|
|
31
|
+
const MODAL_CHECKOUT_ID = 'newspack_modal_checkout';
|
|
32
|
+
const MODAL_CLASS_PREFIX = `${ CLASS_PREFIX }__modal`;
|
|
33
|
+
const VARIATON_MODAL_CLASS_PREFIX = 'newspack-blocks__modal-variation';
|
|
34
|
+
const PROCESSING_PAYMENT_TEXT_CLASS = `${ CLASS_PREFIX }__processing-payment-text`;
|
|
35
|
+
const PROCESSING_PAYMENT_MESSAGES = newspackBlocksModal.processing_payment_messages;
|
|
36
|
+
|
|
37
|
+
// Track the checkout intent to avoid multiple analytics events.
|
|
38
|
+
let inCheckoutIntent = false;
|
|
39
|
+
|
|
40
|
+
// Checkout title.
|
|
41
|
+
let checkoutTitle = newspackBlocksModal.labels.checkout_modal_title;
|
|
42
|
+
|
|
43
|
+
// Last-submitted checkout form.
|
|
44
|
+
let activeCheckoutForm = null;
|
|
45
|
+
|
|
46
|
+
// Close the modal.
|
|
47
|
+
const closeModal = el => {
|
|
48
|
+
if ( el.overlayId && window.newspackReaderActivation?.overlays ) {
|
|
49
|
+
window.newspackReaderActivation?.overlays.remove( el.overlayId );
|
|
50
|
+
}
|
|
51
|
+
el.setAttribute( 'data-state', 'closed' );
|
|
52
|
+
document.body.style.overflow = 'auto';
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Cleanup if page is loaded via back button.
|
|
56
|
+
window.onpageshow = event => {
|
|
57
|
+
if ( event.persisted ) {
|
|
58
|
+
// If the page is loaded from the back button, find and remove any loading-related classes and modals:
|
|
59
|
+
document.querySelectorAll( '.modal-processing' ).forEach( el => el.classList.remove( 'modal-processing' ) );
|
|
60
|
+
document.querySelectorAll( '.non-modal-checkout-loading' ).forEach( el => el.classList.remove( 'non-modal-checkout-loading' ) );
|
|
61
|
+
document.querySelectorAll( `.${ MODAL_CLASS_PREFIX }-container` ).forEach( el => closeModal( el ) );
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Register the "checkout closed" event.
|
|
66
|
+
const checkoutClosedEvent = new CustomEvent( 'checkout-closed' );
|
|
67
|
+
|
|
68
|
+
window.newspackRAS = window.newspackRAS || [];
|
|
69
|
+
|
|
70
|
+
domReady( () => {
|
|
71
|
+
const modalCheckout = document.querySelector( `#${ MODAL_CHECKOUT_ID }` );
|
|
72
|
+
if ( ! modalCheckout ) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const modalContent = modalCheckout.querySelector( `.${ MODAL_CLASS_PREFIX }__content` );
|
|
77
|
+
const modalCheckoutHiddenInput = createHiddenInput( 'modal_checkout', '1' );
|
|
78
|
+
const spinner = modalContent.querySelector( `.${ CLASS_PREFIX }__spinner` );
|
|
79
|
+
let modalTrigger = document.querySelector( '.newspack-reader__account-link' )?.[ 0 ];
|
|
80
|
+
// Initialize empty iframe.
|
|
81
|
+
const initialHeight = '600px'; // Fixed initial height to avoid too much layout shift.
|
|
82
|
+
const iframe = document.createElement( 'iframe' );
|
|
83
|
+
iframe.name = IFRAME_NAME;
|
|
84
|
+
iframe.style.height = initialHeight;
|
|
85
|
+
iframe.style.visibility = 'hidden';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Set the modal as ready.
|
|
89
|
+
*
|
|
90
|
+
* @param {Object} container The container element inside the iframe document.
|
|
91
|
+
*/
|
|
92
|
+
const setModalReady = container => {
|
|
93
|
+
iframeResizeObserver.observe( container );
|
|
94
|
+
if ( spinner.style.display !== 'none' ) {
|
|
95
|
+
spinner.style.display = 'none';
|
|
96
|
+
}
|
|
97
|
+
if ( iframe.style.visibility !== 'visible' ) {
|
|
98
|
+
iframe.style.visibility = 'visible';
|
|
99
|
+
}
|
|
100
|
+
iframe._ready = true;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Handle iframe load state.
|
|
105
|
+
*/
|
|
106
|
+
function handleIframeReady() {
|
|
107
|
+
const location = iframe.contentWindow?.location;
|
|
108
|
+
// If RAS is available, set the front-end authentication.
|
|
109
|
+
if ( window.newspackReaderActivation && location?.href?.includes( 'order-received' ) ) {
|
|
110
|
+
const ras = window.newspackReaderActivation;
|
|
111
|
+
const params = new Proxy( new URLSearchParams( location.search ), {
|
|
112
|
+
get: ( searchParams, prop ) => searchParams.get( prop ),
|
|
113
|
+
} );
|
|
114
|
+
if ( params.email ) {
|
|
115
|
+
ras.setReaderEmail( params.email );
|
|
116
|
+
ras.setAuthenticated( true );
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const container = iframe?.contentDocument?.querySelector( `#${ IFRAME_CONTAINER_ID }` );
|
|
120
|
+
if ( ! container ) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const productDetails = container.querySelector( '#modal-checkout-product-details' );
|
|
125
|
+
const checkoutData = getCheckoutData( productDetails );
|
|
126
|
+
|
|
127
|
+
const processingPaymentText = document.createElement( 'p' );
|
|
128
|
+
processingPaymentText.classList.add( PROCESSING_PAYMENT_TEXT_CLASS );
|
|
129
|
+
let processingPaymentTimeouts = [];
|
|
130
|
+
|
|
131
|
+
const clearProcessingPaymentTimeouts = () => {
|
|
132
|
+
processingPaymentTimeouts.forEach( timeoutId => clearTimeout( timeoutId ) );
|
|
133
|
+
processingPaymentTimeouts = [];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const renderProcessingPaymentScreen = event => {
|
|
137
|
+
spinner.querySelectorAll( `.${ PROCESSING_PAYMENT_TEXT_CLASS }` ).forEach( node => node.remove() );
|
|
138
|
+
spinner.style.display = 'flex';
|
|
139
|
+
clearProcessingPaymentTimeouts();
|
|
140
|
+
processingPaymentText.textContent = PROCESSING_PAYMENT_MESSAGES[ 0 ]?.text ?? '';
|
|
141
|
+
PROCESSING_PAYMENT_MESSAGES.slice( 1 ).forEach( ( { text, delay } ) => {
|
|
142
|
+
const timeoutId = setTimeout( () => {
|
|
143
|
+
event.target.dispatchEvent( new CustomEvent( 'checkout-place-order-processing' ) );
|
|
144
|
+
processingPaymentText.textContent = text;
|
|
145
|
+
}, delay );
|
|
146
|
+
processingPaymentTimeouts.push( timeoutId );
|
|
147
|
+
} );
|
|
148
|
+
spinner.appendChild( processingPaymentText );
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const hideProcessingPaymentScreen = () => {
|
|
152
|
+
spinner.style.display = 'none';
|
|
153
|
+
clearProcessingPaymentTimeouts();
|
|
154
|
+
spinner.querySelectorAll( `.${ PROCESSING_PAYMENT_TEXT_CLASS }` ).forEach( node => node.remove() );
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
onCheckoutCancel( container, () => {
|
|
158
|
+
closeCheckout();
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
onCheckoutPlaceOrderStart( container, renderProcessingPaymentScreen );
|
|
162
|
+
|
|
163
|
+
onCheckoutPlaceOrderError( container, hideProcessingPaymentScreen );
|
|
164
|
+
|
|
165
|
+
onCheckoutReady( container, () => {
|
|
166
|
+
// Make sure the order summary renders the correct text.
|
|
167
|
+
const summaryTextNode = productDetails?.querySelector( 'strong' );
|
|
168
|
+
if ( summaryTextNode ) {
|
|
169
|
+
summaryTextNode.textContent = checkoutData.price_summary;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Display initial errors if any.
|
|
173
|
+
if ( modalCheckout.initialErrors ) {
|
|
174
|
+
const errorContainer = document.createElement( 'div' );
|
|
175
|
+
errorContainer.classList.add( 'woocommerce-error' );
|
|
176
|
+
errorContainer.textContent = modalCheckout.initialErrors;
|
|
177
|
+
container.prepend( errorContainer );
|
|
178
|
+
delete modalCheckout.initialErrors;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Revert modal title and width default value.
|
|
182
|
+
setModalSize();
|
|
183
|
+
setModalTitle( checkoutTitle );
|
|
184
|
+
if ( iframe.contentWindow?.newspackBlocksModalCheckout?.checkout_nonce ) {
|
|
185
|
+
// Store the checkout nonce for later use.
|
|
186
|
+
// We store the nonce from the iframe content window to ensure the nonce was generated for a logged in session
|
|
187
|
+
modalCheckout.checkout_nonce = iframe.contentWindow.newspackBlocksModalCheckout.checkout_nonce;
|
|
188
|
+
}
|
|
189
|
+
setModalReady( container );
|
|
190
|
+
} );
|
|
191
|
+
|
|
192
|
+
onCheckoutComplete( container, () => {
|
|
193
|
+
// Dispatch a `checkout_completed` activity to RAS.
|
|
194
|
+
window.newspackRAS.push( [ 'checkout_completed', checkoutData ] );
|
|
195
|
+
|
|
196
|
+
// Update the newsletters signup modal if it exists.
|
|
197
|
+
if ( window?.newspackReaderActivation?.refreshNewslettersSignupModal && window?.newspackReaderActivation?.getReader()?.email ) {
|
|
198
|
+
window.newspackReaderActivation.refreshNewslettersSignupModal( window.newspackReaderActivation.getReader().email );
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Update the modal title and width to reflect successful transaction.
|
|
202
|
+
setModalSize( 'small' );
|
|
203
|
+
setModalTitle( newspackBlocksModal.labels.thankyou_modal_title );
|
|
204
|
+
setModalReady( container );
|
|
205
|
+
a11y.trapFocus( modalCheckout.querySelector( `.${ MODAL_CLASS_PREFIX }` ) );
|
|
206
|
+
|
|
207
|
+
hideProcessingPaymentScreen();
|
|
208
|
+
} );
|
|
209
|
+
|
|
210
|
+
// Resubmit modal checkout form if an unrecoverable error is encountered.
|
|
211
|
+
const refreshCheckout = form => {
|
|
212
|
+
if ( ! form ) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
closeCheckout();
|
|
216
|
+
spinner.style.display = 'none';
|
|
217
|
+
modalCheckout.initialErrors = newspackBlocksModal.labels.critical_error;
|
|
218
|
+
form.requestSubmit( form.querySelector( 'button[type="submit"]' ) );
|
|
219
|
+
hideProcessingPaymentScreen();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
onCheckoutPlaceOrderCriticalError( container, () => refreshCheckout( activeCheckoutForm ) );
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
iframeReady( iframe, handleIframeReady, () => {
|
|
226
|
+
spinner.style.display = 'flex';
|
|
227
|
+
} );
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Generate cart via ajax.
|
|
231
|
+
*
|
|
232
|
+
* This strategy, used for anonymous users, addresses an edge case in which
|
|
233
|
+
* the session for a newly registered reader fails to carry the cart over to
|
|
234
|
+
* the checkout.
|
|
235
|
+
*
|
|
236
|
+
* @param {Object} checkoutData The checkout data.
|
|
237
|
+
*
|
|
238
|
+
* @return {Promise} The promise that resolves with the checkout URL.
|
|
239
|
+
*/
|
|
240
|
+
const generateCart = checkoutData => {
|
|
241
|
+
return new Promise( ( resolve, reject ) => {
|
|
242
|
+
const urlParams = new URLSearchParams( checkoutData );
|
|
243
|
+
urlParams.append( 'action', 'modal_checkout_request' );
|
|
244
|
+
fetch( newspackBlocksModal.ajax_url + '?' + urlParams.toString() )
|
|
245
|
+
.then( res => {
|
|
246
|
+
if ( ! res.ok ) {
|
|
247
|
+
reject( res );
|
|
248
|
+
}
|
|
249
|
+
res.json()
|
|
250
|
+
.then( jsonData => {
|
|
251
|
+
resolve( jsonData.url );
|
|
252
|
+
} )
|
|
253
|
+
.catch( reject );
|
|
254
|
+
} )
|
|
255
|
+
.catch( reject );
|
|
256
|
+
} );
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Empty cart via ajax.
|
|
261
|
+
*/
|
|
262
|
+
const emptyCart = async () => {
|
|
263
|
+
const body = new FormData();
|
|
264
|
+
if ( ! newspackBlocksModal.has_unsupported_payment_gateway ) {
|
|
265
|
+
body.append( 'modal_checkout', '1' );
|
|
266
|
+
}
|
|
267
|
+
body.append( 'action', 'abandon_modal_checkout' );
|
|
268
|
+
body.append( '_wpnonce', modalCheckout.checkout_nonce );
|
|
269
|
+
modalCheckout.checkout_nonce = null;
|
|
270
|
+
try {
|
|
271
|
+
await fetch( newspackBlocksModal.ajax_url, {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
body,
|
|
274
|
+
} );
|
|
275
|
+
} catch ( error ) {
|
|
276
|
+
console.warn( 'Unable to empty cart:', error ); // eslint-disable-line no-console
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Whether reader should be prompted with registration.
|
|
282
|
+
*/
|
|
283
|
+
const shouldPromptRegistration = () =>
|
|
284
|
+
typeof newspack_ras_config !== 'undefined' &&
|
|
285
|
+
! newspack_ras_config?.is_logged_in &&
|
|
286
|
+
! window?.newspackReaderActivation?.getReader?.()?.authenticated &&
|
|
287
|
+
newspackBlocksModal?.is_registration_required &&
|
|
288
|
+
window?.newspackReaderActivation?.openAuthModal;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Handle checkout form submit.
|
|
292
|
+
*
|
|
293
|
+
* @param {Event} ev
|
|
294
|
+
*/
|
|
295
|
+
const handleCheckoutFormSubmit = ev => {
|
|
296
|
+
const isModalCheckout = ! newspackBlocksModal.has_unsupported_payment_gateway;
|
|
297
|
+
if ( ! isModalCheckout ) {
|
|
298
|
+
ev.preventDefault();
|
|
299
|
+
}
|
|
300
|
+
const form = ev.target;
|
|
301
|
+
form.classList.add( 'modal-processing' );
|
|
302
|
+
|
|
303
|
+
const checkoutData = getCheckoutData( form );
|
|
304
|
+
|
|
305
|
+
const isDonateBlock = checkoutData.newspack_donate;
|
|
306
|
+
if ( isDonateBlock ) {
|
|
307
|
+
const frequency = checkoutData.donation_frequency;
|
|
308
|
+
const donationTiers = [ ...form.querySelectorAll( `.donation-tier__${ frequency }, .donation-frequency__${ frequency }` ) ];
|
|
309
|
+
const donationTierIndex = checkoutData.donation_tier_index;
|
|
310
|
+
let donationContainer, customAmount;
|
|
311
|
+
if ( donationTierIndex ) {
|
|
312
|
+
donationContainer = donationTiers[ donationTierIndex ];
|
|
313
|
+
customAmount = checkoutData[ `donation_value_${ frequency }` ];
|
|
314
|
+
} else {
|
|
315
|
+
donationContainer = donationTiers[ 0 ];
|
|
316
|
+
if ( checkoutData[ `donation_value_${ frequency }_untiered` ] ) {
|
|
317
|
+
customAmount = checkoutData[ `donation_value_${ frequency }_untiered` ];
|
|
318
|
+
} else {
|
|
319
|
+
customAmount = checkoutData[ `donation_value_${ frequency }` ];
|
|
320
|
+
if ( customAmount === 'other' ) {
|
|
321
|
+
customAmount = checkoutData[ `donation_value_${ frequency }_other` ];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const donationData = getCheckoutData( donationContainer );
|
|
326
|
+
for ( const key in donationData ) {
|
|
327
|
+
checkoutData[ key ] = donationData[ key ];
|
|
328
|
+
}
|
|
329
|
+
checkoutData.amount = customAmount;
|
|
330
|
+
checkoutData.price_summary = checkoutData.summary_template.replace(
|
|
331
|
+
'{{PRICE}}',
|
|
332
|
+
getFormattedAmount( checkoutData.amount, checkoutData.currency )
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if ( checkoutData ) {
|
|
337
|
+
Object.keys( checkoutData ).forEach( key => {
|
|
338
|
+
const existingInputs = form.querySelectorAll( 'input[name="' + key + '"]' );
|
|
339
|
+
if ( 0 === existingInputs.length ) {
|
|
340
|
+
form.prepend( createHiddenInput( key, checkoutData[ key ] ) );
|
|
341
|
+
}
|
|
342
|
+
} );
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// If we're not going from variation picker to checkout, set the modal trigger:
|
|
346
|
+
if ( ! checkoutData.variation_id ) {
|
|
347
|
+
modalTrigger = ev.submitter;
|
|
348
|
+
}
|
|
349
|
+
// Clear any open variation modal.
|
|
350
|
+
const variationModals = document.querySelectorAll( `.${ VARIATON_MODAL_CLASS_PREFIX }` );
|
|
351
|
+
variationModals.forEach( variationModal => {
|
|
352
|
+
// Only close the variation picker if is the modal checkout, or if registration is required.
|
|
353
|
+
if ( shouldPromptRegistration() || isModalCheckout ) {
|
|
354
|
+
closeModal( variationModal );
|
|
355
|
+
}
|
|
356
|
+
} );
|
|
357
|
+
|
|
358
|
+
// Trigger variation modal if variation is not selected.
|
|
359
|
+
if ( checkoutData.is_grouped || ( checkoutData.is_variable && ! checkoutData.variation_id ) ) {
|
|
360
|
+
const variationModal = [ ...variationModals ].find( modal => modal.dataset.productId === checkoutData.product_id );
|
|
361
|
+
if ( variationModal ) {
|
|
362
|
+
variationModal.querySelectorAll( `form[target="${ IFRAME_NAME }"]` ).forEach( singleVariationForm => {
|
|
363
|
+
// Fill in the hidden params in the variation modal.
|
|
364
|
+
[
|
|
365
|
+
'after_success_behavior',
|
|
366
|
+
'after_success_url',
|
|
367
|
+
'after_success_button_label',
|
|
368
|
+
'gate_post_id',
|
|
369
|
+
'newspack_popup_id',
|
|
370
|
+
'prompt_title',
|
|
371
|
+
].forEach( hiddenParam => {
|
|
372
|
+
const existingInputs = singleVariationForm.querySelectorAll( 'input[name="' + hiddenParam + '"]' );
|
|
373
|
+
if ( 0 === existingInputs.length ) {
|
|
374
|
+
singleVariationForm.prepend( createHiddenInput( hiddenParam, checkoutData[ hiddenParam ] ) );
|
|
375
|
+
}
|
|
376
|
+
} );
|
|
377
|
+
|
|
378
|
+
// Append the product data hidden inputs.
|
|
379
|
+
const variationData = singleVariationForm.dataset.checkout;
|
|
380
|
+
if ( variationData ) {
|
|
381
|
+
const data = JSON.parse( variationData );
|
|
382
|
+
Object.keys( data ).forEach( key => {
|
|
383
|
+
const existingInputs = singleVariationForm.querySelectorAll( 'input[name="' + key + '"]' );
|
|
384
|
+
if ( 0 === existingInputs.length ) {
|
|
385
|
+
singleVariationForm.prepend( createHiddenInput( key, data[ key ] ) );
|
|
386
|
+
}
|
|
387
|
+
} );
|
|
388
|
+
}
|
|
389
|
+
} );
|
|
390
|
+
|
|
391
|
+
// Open the variations modal.
|
|
392
|
+
ev.preventDefault();
|
|
393
|
+
form.classList.remove( 'modal-processing' );
|
|
394
|
+
openModal( variationModal );
|
|
395
|
+
a11y.trapFocus( variationModal, false );
|
|
396
|
+
|
|
397
|
+
// For the variation modal we will not set `inCheckoutIntent = true` and
|
|
398
|
+
// let the `opened` event get triggered once the user selects a
|
|
399
|
+
// variation so we track the selection.
|
|
400
|
+
if ( ! inCheckoutIntent ) {
|
|
401
|
+
manageOpened( checkoutData );
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Append product data info to the modal itself, so we can grab it for manageDismissed:
|
|
405
|
+
document.getElementById( 'newspack_modal_checkout' ).setAttribute( 'data-checkout', JSON.stringify( checkoutData ) );
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Populate cart and redirect to checkout if there is an unsupported payment gateway.
|
|
411
|
+
if ( ! isModalCheckout && ! shouldPromptRegistration() ) {
|
|
412
|
+
generateCart( checkoutData ).then( url => {
|
|
413
|
+
// Remove modal checkout query string and trailing question mark (if any).
|
|
414
|
+
window.location.href = url;
|
|
415
|
+
} );
|
|
416
|
+
// Add some animation to the Checkout Button while the non-modal checkout is loading.
|
|
417
|
+
// For now, don't do it when any popup opens, just when we go right to the checkout page.
|
|
418
|
+
if ( ! ( checkoutData.is_variable && ! checkoutData.variation_id ) ) {
|
|
419
|
+
const buttons = form.querySelectorAll( 'button[type=submit]:focus' );
|
|
420
|
+
buttons.forEach( button => {
|
|
421
|
+
button.classList.add( 'non-modal-checkout-loading' );
|
|
422
|
+
const buttonText = button.innerHTML;
|
|
423
|
+
button.innerHTML = '<span>' + buttonText + '</span>';
|
|
424
|
+
} );
|
|
425
|
+
}
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
form.classList.remove( 'modal-processing' );
|
|
429
|
+
|
|
430
|
+
// Analytics.
|
|
431
|
+
if ( ! inCheckoutIntent ) {
|
|
432
|
+
manageOpened( checkoutData );
|
|
433
|
+
}
|
|
434
|
+
inCheckoutIntent = true;
|
|
435
|
+
|
|
436
|
+
if ( shouldPromptRegistration() ) {
|
|
437
|
+
ev.preventDefault();
|
|
438
|
+
|
|
439
|
+
const priceSummary = checkoutData.price_summary;
|
|
440
|
+
const content = priceSummary
|
|
441
|
+
? `<div class="order-details-summary ${ CLASS_PREFIX }__box ${ CLASS_PREFIX }__box--text-center"><p><strong>${ priceSummary }</strong></p></div>`
|
|
442
|
+
: '';
|
|
443
|
+
|
|
444
|
+
// Generate cart asynchroneously.
|
|
445
|
+
const cartReq = generateCart( checkoutData );
|
|
446
|
+
|
|
447
|
+
// Update pending checkout URL.
|
|
448
|
+
cartReq.then( url => {
|
|
449
|
+
window.newspackReaderActivation?.setPendingCheckout?.( url );
|
|
450
|
+
} );
|
|
451
|
+
// Initialize auth flow if reader is not authenticated.
|
|
452
|
+
window.newspackReaderActivation.openAuthModal( {
|
|
453
|
+
title: newspackBlocksModal.labels.auth_modal_title,
|
|
454
|
+
onSuccess: ( message, authData ) => {
|
|
455
|
+
cartReq
|
|
456
|
+
.then( url => {
|
|
457
|
+
// If registered and in a modal checkout, append the registration flag query param to the url.
|
|
458
|
+
if ( authData?.registered && isModalCheckout ) {
|
|
459
|
+
url += `&${ newspackBlocksModal.checkout_registration_flag }=1`;
|
|
460
|
+
}
|
|
461
|
+
// Populate cart and redirect to checkout if there is an unsupported payment gateway.
|
|
462
|
+
if ( ! isModalCheckout ) {
|
|
463
|
+
// Remove modal checkout query string, and trailing question mark (if any).
|
|
464
|
+
generateCart( checkoutData ).then( ( window.location.href = url ) );
|
|
465
|
+
} else {
|
|
466
|
+
const checkoutForm = generateCheckoutPageForm( url );
|
|
467
|
+
triggerFormSubmit( checkoutForm );
|
|
468
|
+
}
|
|
469
|
+
} )
|
|
470
|
+
.catch( error => {
|
|
471
|
+
console.warn( 'Unable to generate cart:', error ); // eslint-disable-line no-console
|
|
472
|
+
closeCheckout();
|
|
473
|
+
} );
|
|
474
|
+
},
|
|
475
|
+
onError: () => {
|
|
476
|
+
closeCheckout();
|
|
477
|
+
},
|
|
478
|
+
onDismiss: () => {
|
|
479
|
+
// Analytics: Track a dismissal event (modal has been manually closed without completing the checkout).
|
|
480
|
+
manageDismissed( checkoutData );
|
|
481
|
+
inCheckoutIntent = false;
|
|
482
|
+
document.getElementById( 'newspack_modal_checkout' ).removeAttribute( 'data-checkout' );
|
|
483
|
+
},
|
|
484
|
+
skipSuccess: true,
|
|
485
|
+
skipNewslettersSignup: true,
|
|
486
|
+
labels: {
|
|
487
|
+
signin: {
|
|
488
|
+
title: newspackBlocksModal.labels.signin_modal_title,
|
|
489
|
+
},
|
|
490
|
+
register: {
|
|
491
|
+
title: newspackBlocksModal.labels.register_modal_title,
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
content,
|
|
495
|
+
trigger: ev.submitter,
|
|
496
|
+
closeOnSuccess: isModalCheckout,
|
|
497
|
+
} );
|
|
498
|
+
} else {
|
|
499
|
+
// Otherwise initialize checkout.
|
|
500
|
+
openCheckout();
|
|
501
|
+
// Append product data info to the modal, so we can grab it for GA4 events outside of the iframe.
|
|
502
|
+
document.getElementById( 'newspack_modal_checkout' ).setAttribute( 'data-checkout', JSON.stringify( checkoutData ) );
|
|
503
|
+
}
|
|
504
|
+
activeCheckoutForm = form;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Generate checkout page form.
|
|
509
|
+
*
|
|
510
|
+
* A form that goes directly to checkout in case the cart has already been
|
|
511
|
+
* created.
|
|
512
|
+
*/
|
|
513
|
+
const generateCheckoutPageForm = checkoutUrl => {
|
|
514
|
+
const checkoutForm = document.createElement( 'form' );
|
|
515
|
+
checkoutForm.method = 'POST';
|
|
516
|
+
checkoutForm.action = checkoutUrl;
|
|
517
|
+
checkoutForm.target = IFRAME_NAME;
|
|
518
|
+
checkoutForm.style.display = 'none';
|
|
519
|
+
|
|
520
|
+
const submitButton = document.createElement( 'button' );
|
|
521
|
+
submitButton.setAttribute( 'type', 'submit' );
|
|
522
|
+
|
|
523
|
+
checkoutForm.appendChild( submitButton );
|
|
524
|
+
document.body.appendChild( checkoutForm );
|
|
525
|
+
|
|
526
|
+
checkoutForm.addEventListener( 'submit', handleCheckoutFormSubmit );
|
|
527
|
+
return checkoutForm;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
const iframeResizeObserver = new ResizeObserver( entries => {
|
|
531
|
+
if ( ! entries || ! entries.length ) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if ( ! iframe.contentDocument ) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const contentRect = entries[ 0 ].contentRect;
|
|
538
|
+
if ( contentRect ) {
|
|
539
|
+
const vh = 0.01 * Math.max( document.documentElement.clientHeight, window.innerHeight || 0 );
|
|
540
|
+
const headerHeight = modalCheckout.querySelector( `.${ MODAL_CLASS_PREFIX }__header` )?.offsetHeight || 0;
|
|
541
|
+
const maxHeight = 90 * vh - headerHeight;
|
|
542
|
+
const contentHeight = contentRect.top + contentRect.bottom;
|
|
543
|
+
const iframeHeight = Math.min( contentHeight, maxHeight );
|
|
544
|
+
if ( iframeHeight === 0 ) {
|
|
545
|
+
// If height is 0, hide iframe content instead of resizing to avoid layout shift.
|
|
546
|
+
iframe.style.visibility = 'hidden';
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
// Match iframe and modal content heights to avoid inner iframe scollbar.
|
|
550
|
+
modalContent.style.height = iframeHeight + 'px';
|
|
551
|
+
iframe.style.height = iframeHeight + 'px';
|
|
552
|
+
}
|
|
553
|
+
} );
|
|
554
|
+
|
|
555
|
+
const closeCheckout = () => {
|
|
556
|
+
const container = iframe?.contentDocument?.querySelector( `#${ IFRAME_CONTAINER_ID }` );
|
|
557
|
+
const afterSuccessUrlInput = container?.querySelector( 'input[name="after_success_url"]' );
|
|
558
|
+
const afterSuccessBehaviorInput = container?.querySelector( 'input[name="after_success_behavior"]' );
|
|
559
|
+
const hasNewsletterPopup = document?.querySelector( '.newspack-newsletters-signup-modal' );
|
|
560
|
+
|
|
561
|
+
const checkoutData = getCheckoutData( container?.querySelector( '#modal-checkout-product-details' ) );
|
|
562
|
+
|
|
563
|
+
// Empty cart if checkout is not complete.
|
|
564
|
+
if ( ! container?.checkoutComplete ) {
|
|
565
|
+
emptyCart();
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Only close the modal if the iframe contentDocument is null, the checkout is not complete, or we are not redirecting.
|
|
569
|
+
const shouldCloseModal = ! iframe.contentDocument || ! afterSuccessUrlInput || ! afterSuccessBehaviorInput || ! container?.checkoutComplete;
|
|
570
|
+
if ( shouldCloseModal || hasNewsletterPopup ) {
|
|
571
|
+
spinner.style.display = 'flex';
|
|
572
|
+
if ( iframe && modalContent.contains( iframe ) ) {
|
|
573
|
+
// Reset iframe and modal content heights.
|
|
574
|
+
iframe._ready = false;
|
|
575
|
+
iframe.src = 'about:blank';
|
|
576
|
+
iframe.style.height = initialHeight;
|
|
577
|
+
iframe.style.visibility = 'hidden';
|
|
578
|
+
modalContent.style.height = initialHeight;
|
|
579
|
+
modalContent.removeChild( iframe );
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if ( iframeResizeObserver ) {
|
|
583
|
+
iframeResizeObserver.disconnect();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
document.querySelectorAll( `.${ MODAL_CLASS_PREFIX }-container` ).forEach( el => closeModal( el ) );
|
|
587
|
+
|
|
588
|
+
if ( modalTrigger ) {
|
|
589
|
+
modalTrigger.focus();
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
document.dispatchEvent( checkoutClosedEvent );
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if ( container?.checkoutComplete ) {
|
|
596
|
+
const handleCheckoutComplete = () => {
|
|
597
|
+
if ( afterSuccessUrlInput && afterSuccessBehaviorInput ) {
|
|
598
|
+
const afterSuccessUrl = afterSuccessUrlInput.getAttribute( 'value' );
|
|
599
|
+
const afterSuccessBehavior = afterSuccessBehaviorInput.getAttribute( 'value' );
|
|
600
|
+
|
|
601
|
+
if ( 'custom' === afterSuccessBehavior ) {
|
|
602
|
+
window.location.href = afterSuccessUrl;
|
|
603
|
+
} else if ( 'referrer' === afterSuccessBehavior ) {
|
|
604
|
+
window.history.back();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
window?.newspackReaderActivation?.setPendingCheckout?.();
|
|
608
|
+
inCheckoutIntent = false;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
if ( checkoutData.action_type !== 'subscription_switch' && window?.newspackReaderActivation?.openNewslettersSignupModal ) {
|
|
612
|
+
window.newspackReaderActivation.openNewslettersSignupModal( {
|
|
613
|
+
onSuccess: handleCheckoutComplete,
|
|
614
|
+
onError: handleCheckoutComplete,
|
|
615
|
+
closeOnSuccess: shouldCloseModal,
|
|
616
|
+
} );
|
|
617
|
+
} else {
|
|
618
|
+
handleCheckoutComplete();
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Ensure we always reset the modal title and width once the modal closes.
|
|
622
|
+
if ( shouldCloseModal ) {
|
|
623
|
+
checkoutTitle = newspackBlocksModal.labels.checkout_modal_title;
|
|
624
|
+
setModalSize();
|
|
625
|
+
setModalTitle( checkoutTitle );
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
window?.newspackReaderActivation?.setPendingCheckout?.();
|
|
629
|
+
// Analytics: Track a dismissal event (modal has been manually closed without completing the checkout).
|
|
630
|
+
manageDismissed();
|
|
631
|
+
inCheckoutIntent = false;
|
|
632
|
+
document.getElementById( 'newspack_modal_checkout' ).removeAttribute( 'data-checkout' );
|
|
633
|
+
}
|
|
634
|
+
document.removeEventListener( 'keydown', handleKeydown );
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
const openCheckout = url => {
|
|
638
|
+
if ( url ) {
|
|
639
|
+
iframe.src = url;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
spinner.style.display = 'flex';
|
|
643
|
+
openModal( modalCheckout );
|
|
644
|
+
modalContent.appendChild( iframe );
|
|
645
|
+
modalCheckout.addEventListener( 'click', ev => {
|
|
646
|
+
if ( ev.target === modalCheckout ) {
|
|
647
|
+
closeCheckout();
|
|
648
|
+
}
|
|
649
|
+
} );
|
|
650
|
+
|
|
651
|
+
a11y.trapFocus( modalCheckout, iframe );
|
|
652
|
+
|
|
653
|
+
document.addEventListener( 'keydown', handleKeydown );
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
const openModal = el => {
|
|
657
|
+
if ( window.newspackReaderActivation?.overlays ) {
|
|
658
|
+
el.overlayId = window.newspackReaderActivation?.overlays.add();
|
|
659
|
+
}
|
|
660
|
+
el.setAttribute( 'data-state', 'open' );
|
|
661
|
+
document.body.style.overflow = 'hidden';
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Set the modal title.
|
|
666
|
+
*
|
|
667
|
+
* @param {string} title The title to set.
|
|
668
|
+
*/
|
|
669
|
+
const setModalTitle = title => {
|
|
670
|
+
const modalTitle = modalCheckout.querySelector( `.${ MODAL_CLASS_PREFIX }__header h2` );
|
|
671
|
+
if ( ! modalTitle ) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
modalTitle.innerText = title;
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Sets the size of the modal.
|
|
680
|
+
*
|
|
681
|
+
* @param {string} size Options are 'small' or 'default'. Default is 'default'.
|
|
682
|
+
*/
|
|
683
|
+
const setModalSize = ( size = 'default' ) => {
|
|
684
|
+
const modal = modalCheckout.querySelector( `.${ MODAL_CLASS_PREFIX }` );
|
|
685
|
+
if ( ! modal ) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if ( size === 'small' ) {
|
|
690
|
+
modal.classList.add( `${ MODAL_CLASS_PREFIX }--small` );
|
|
691
|
+
} else {
|
|
692
|
+
modal.classList.remove( `${ MODAL_CLASS_PREFIX }--small` );
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Handle modal checkout close button.
|
|
698
|
+
*/
|
|
699
|
+
modalCheckout.querySelectorAll( `.${ MODAL_CLASS_PREFIX }__close` ).forEach( button => {
|
|
700
|
+
button.addEventListener( 'click', ev => {
|
|
701
|
+
ev.preventDefault();
|
|
702
|
+
closeCheckout();
|
|
703
|
+
} );
|
|
704
|
+
} );
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Handle variations modal close button.
|
|
708
|
+
*/
|
|
709
|
+
document.querySelectorAll( '.newspack-blocks__modal-variation' ).forEach( variationModal => {
|
|
710
|
+
variationModal.addEventListener( 'click', ev => {
|
|
711
|
+
if ( ev.target === variationModal ) {
|
|
712
|
+
closeCheckout();
|
|
713
|
+
}
|
|
714
|
+
} );
|
|
715
|
+
variationModal.querySelectorAll( `.${ MODAL_CLASS_PREFIX }__close` ).forEach( button => {
|
|
716
|
+
button.addEventListener( 'click', ev => {
|
|
717
|
+
ev.preventDefault();
|
|
718
|
+
closeCheckout();
|
|
719
|
+
} );
|
|
720
|
+
} );
|
|
721
|
+
} );
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Escape key handler to close the modal checkout.
|
|
725
|
+
*/
|
|
726
|
+
const handleKeydown = ev => {
|
|
727
|
+
if ( ev.key === 'Escape' ) {
|
|
728
|
+
closeCheckout();
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Handle modal checkout triggers.
|
|
734
|
+
*/
|
|
735
|
+
document
|
|
736
|
+
.querySelectorAll( '.wpbnbd.wpbnbd--platform-wc, .wp-block-newspack-blocks-checkout-button, .newspack-blocks__modal-variation' )
|
|
737
|
+
.forEach( element => {
|
|
738
|
+
const forms = element.querySelectorAll( 'form' );
|
|
739
|
+
forms.forEach( form => {
|
|
740
|
+
if ( ! newspackBlocksModal.has_unsupported_payment_gateway ) {
|
|
741
|
+
form.prepend( modalCheckoutHiddenInput.cloneNode() );
|
|
742
|
+
}
|
|
743
|
+
form.target = IFRAME_NAME;
|
|
744
|
+
form.addEventListener( 'submit', handleCheckoutFormSubmit );
|
|
745
|
+
} );
|
|
746
|
+
} );
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Handle donation form triggers.
|
|
750
|
+
*
|
|
751
|
+
* @param {string} layout The donation layout.
|
|
752
|
+
* @param {string} frequency The donation frequency.
|
|
753
|
+
* @param {string} amount The donation amount.
|
|
754
|
+
* @param {string|null} other Optional. The custom amount when other is selected.
|
|
755
|
+
*/
|
|
756
|
+
const triggerDonationForm = ( layout, frequency, amount, other = null ) => {
|
|
757
|
+
let form;
|
|
758
|
+
document.querySelectorAll( '.wpbnbd.wpbnbd--platform-wc form' ).forEach( donationForm => {
|
|
759
|
+
const frequencyInput = donationForm.querySelector( `input[name="donation_frequency"][value="${ frequency }"]` );
|
|
760
|
+
if ( ! frequencyInput ) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if ( layout === 'tiered' ) {
|
|
764
|
+
const frequencyButton = document.querySelector( `button[data-frequency-slug="${ frequency }"]` );
|
|
765
|
+
if ( ! frequencyButton ) {
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
frequencyButton.click();
|
|
769
|
+
const submitButton = donationForm.querySelector( `button[type="submit"][name="donation_value_${ frequency }"][value="${ amount }"]` );
|
|
770
|
+
if ( ! submitButton ) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
submitButton.click();
|
|
774
|
+
} else {
|
|
775
|
+
const amountInput =
|
|
776
|
+
layout === 'untiered'
|
|
777
|
+
? donationForm.querySelector( `input[name="donation_value_${ frequency }_untiered"]` )
|
|
778
|
+
: donationForm.querySelector( `input[name="donation_value_${ frequency }"][value="${ amount }"]` );
|
|
779
|
+
if ( frequencyInput && amountInput ) {
|
|
780
|
+
frequencyInput.checked = true;
|
|
781
|
+
if ( layout === 'untiered' ) {
|
|
782
|
+
amountInput.value = amount;
|
|
783
|
+
} else if ( amount === 'other' ) {
|
|
784
|
+
amountInput.click();
|
|
785
|
+
const otherInput = donationForm.querySelector( `input[name="donation_value_${ frequency }_other"]` );
|
|
786
|
+
if ( otherInput && other ) {
|
|
787
|
+
otherInput.value = other;
|
|
788
|
+
}
|
|
789
|
+
} else {
|
|
790
|
+
amountInput.checked = true;
|
|
791
|
+
}
|
|
792
|
+
form = donationForm;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
} );
|
|
796
|
+
if ( form ) {
|
|
797
|
+
triggerFormSubmit( form );
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Handle checkout button form triggers.
|
|
803
|
+
*
|
|
804
|
+
* @param {number} productId The product ID.
|
|
805
|
+
* @param {number|null} variationId Optional. The variation ID.
|
|
806
|
+
*/
|
|
807
|
+
const triggerCheckoutButtonForm = ( productId, variationId = null ) => {
|
|
808
|
+
let form;
|
|
809
|
+
if ( variationId && variationId !== productId ) {
|
|
810
|
+
const variationModals = document.querySelectorAll( `.${ VARIATON_MODAL_CLASS_PREFIX }` );
|
|
811
|
+
const variationModal = [ ...variationModals ].find( modal => modal.dataset.productId === productId );
|
|
812
|
+
if ( variationModal ) {
|
|
813
|
+
const forms = variationModal.querySelectorAll( `form[target="${ IFRAME_NAME }"]` );
|
|
814
|
+
forms.forEach( variationForm => {
|
|
815
|
+
const productData = JSON.parse( variationForm.dataset.checkout );
|
|
816
|
+
if ( productData?.variation_id === Number( variationId ) ) {
|
|
817
|
+
form = variationForm;
|
|
818
|
+
}
|
|
819
|
+
} );
|
|
820
|
+
}
|
|
821
|
+
} else {
|
|
822
|
+
const checkoutButtons = document.querySelectorAll( '.wp-block-newspack-blocks-checkout-button' );
|
|
823
|
+
checkoutButtons.forEach( button => {
|
|
824
|
+
const checkoutButtonForm = button.querySelector( 'form' );
|
|
825
|
+
if ( ! checkoutButtonForm ) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const productData = JSON.parse( checkoutButtonForm.dataset.checkout );
|
|
829
|
+
if ( productData?.product_id === productId ) {
|
|
830
|
+
form = checkoutButtonForm;
|
|
831
|
+
}
|
|
832
|
+
} );
|
|
833
|
+
}
|
|
834
|
+
if ( form ) {
|
|
835
|
+
triggerFormSubmit( form );
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Handle modal checkout url param triggers.
|
|
841
|
+
*/
|
|
842
|
+
const handleModalCheckoutUrlParams = () => {
|
|
843
|
+
const urlParams = new URLSearchParams( window.location.search );
|
|
844
|
+
if ( ! urlParams.has( 'checkout' ) ) {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
const type = urlParams.get( 'type' );
|
|
848
|
+
if ( type === 'donate' ) {
|
|
849
|
+
const layout = urlParams.get( 'layout' );
|
|
850
|
+
const frequency = urlParams.get( 'frequency' );
|
|
851
|
+
const amount = urlParams.get( 'amount' );
|
|
852
|
+
const other = urlParams.get( 'other' );
|
|
853
|
+
if ( layout && frequency && amount ) {
|
|
854
|
+
triggerDonationForm( layout, frequency, amount, other );
|
|
855
|
+
}
|
|
856
|
+
} else if ( type === 'checkout_button' ) {
|
|
857
|
+
const productId = urlParams.get( 'product_id' );
|
|
858
|
+
const variationId = urlParams.get( 'variation_id' );
|
|
859
|
+
if ( productId ) {
|
|
860
|
+
triggerCheckoutButtonForm( productId, variationId );
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
const url = window.newspackReaderActivation?.getPendingCheckout?.();
|
|
864
|
+
if ( url ) {
|
|
865
|
+
const form = generateCheckoutPageForm( url );
|
|
866
|
+
triggerFormSubmit( form );
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
// Remove the URL param to prevent re-triggering.
|
|
870
|
+
window.history.replaceState( null, null, window.location.pathname );
|
|
871
|
+
};
|
|
872
|
+
handleModalCheckoutUrlParams();
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Open the modal checkout.
|
|
876
|
+
*
|
|
877
|
+
* @param {Object} options Modal checkout options object.
|
|
878
|
+
* @param {string} options.url The URL to open the modal checkout on.
|
|
879
|
+
* If not provided, the default checkout URL will be used.
|
|
880
|
+
* @param {string} options.title The title to set for the modal.
|
|
881
|
+
* @param {string} options.actionType The action type to set for the modal.
|
|
882
|
+
* @param {Object} options.afterSuccess The after success configuration object.
|
|
883
|
+
* @param {Function} options.onCheckoutComplete The callback to call when the checkout is complete.
|
|
884
|
+
* @param {Function} options.onClose The callback to call when the modal is closed.
|
|
885
|
+
*/
|
|
886
|
+
window.newspackOpenModalCheckout = ( {
|
|
887
|
+
url = null,
|
|
888
|
+
title = null,
|
|
889
|
+
actionType = null,
|
|
890
|
+
afterSuccess = {},
|
|
891
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
892
|
+
onCheckoutComplete = null,
|
|
893
|
+
onClose = null,
|
|
894
|
+
} ) => {
|
|
895
|
+
/**
|
|
896
|
+
* Title configuration.
|
|
897
|
+
*/
|
|
898
|
+
checkoutTitle = title || newspackBlocksModal.labels.checkout_modal_title;
|
|
899
|
+
// Set the modal title early, even though it may be overridden by the modal content.
|
|
900
|
+
setModalTitle( checkoutTitle );
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Start with the default checkout URL.
|
|
904
|
+
*/
|
|
905
|
+
url = new URL( url || newspackBlocksModal.checkout_url );
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* For integration purposes, remove `my_account_checkout` from the URL if it exists.
|
|
909
|
+
*/
|
|
910
|
+
if ( url.searchParams.has( 'my_account_checkout' ) ) {
|
|
911
|
+
url.searchParams.delete( 'my_account_checkout' );
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Add `modal_checkout` to the URL if it doesn't exist.
|
|
916
|
+
*/
|
|
917
|
+
if ( ! url.searchParams.has( 'modal_checkout' ) ) {
|
|
918
|
+
url.searchParams.set( 'modal_checkout', '1' );
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* Custom action type configuration.
|
|
923
|
+
*/
|
|
924
|
+
if ( actionType ) {
|
|
925
|
+
url.searchParams.set( 'action_type', actionType );
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* After success parameters.
|
|
930
|
+
*/
|
|
931
|
+
if ( afterSuccess?.url ) {
|
|
932
|
+
url.searchParams.set( 'after_success_url', afterSuccess.url );
|
|
933
|
+
}
|
|
934
|
+
if ( afterSuccess?.behavior || afterSuccess?.url ) {
|
|
935
|
+
url.searchParams.set( 'after_success_behavior', afterSuccess.behavior || 'custom' );
|
|
936
|
+
}
|
|
937
|
+
if ( afterSuccess?.buttonLabel ) {
|
|
938
|
+
url.searchParams.set( 'after_success_button_label', afterSuccess.buttonLabel );
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* On checkout complete callback.
|
|
943
|
+
*/
|
|
944
|
+
if ( onCheckoutComplete ) {
|
|
945
|
+
const handleCheckoutComplete = ( { detail: { action, data } } ) => {
|
|
946
|
+
if ( action !== 'checkout_completed' ) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
onCheckoutComplete( data );
|
|
950
|
+
};
|
|
951
|
+
window.newspackRAS.push( ras => {
|
|
952
|
+
ras.on( 'activity', handleCheckoutComplete );
|
|
953
|
+
// Unsubscribe from the checkout complete event when the modal is closed.
|
|
954
|
+
const closeHandler = () => {
|
|
955
|
+
ras.off( 'activity', handleCheckoutComplete );
|
|
956
|
+
document.removeEventListener( 'checkout-closed', closeHandler );
|
|
957
|
+
};
|
|
958
|
+
document.addEventListener( 'checkout-closed', closeHandler );
|
|
959
|
+
} );
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* On close callback.
|
|
964
|
+
*/
|
|
965
|
+
if ( onClose ) {
|
|
966
|
+
const closeHandler = () => {
|
|
967
|
+
onClose();
|
|
968
|
+
document.removeEventListener( 'checkout-closed', closeHandler );
|
|
969
|
+
};
|
|
970
|
+
document.addEventListener( 'checkout-closed', closeHandler );
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Open the modal checkout.
|
|
975
|
+
*/
|
|
976
|
+
openCheckout( url.toString() );
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Close the modal checkout.
|
|
981
|
+
*/
|
|
982
|
+
window.newspackCloseModalCheckout = closeCheckout;
|
|
983
|
+
} );
|