🚧 Minor refactoring in boot.js

This commit is contained in:
Philipp Stracker 2024-10-07 15:18:51 +02:00
parent c00c9c2e13
commit d80e92b5e8
No known key found for this signature in database

View file

@ -4,7 +4,7 @@ import ApplePayManager from './ApplepayManager';
import { setupButtonEvents } from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper'; import { setupButtonEvents } from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper';
( function ( { buttonConfig, ppcpConfig } ) { ( function ( { buttonConfig, ppcpConfig } ) {
const bootstrap = function () { function bootstrapPayButton() {
if ( ! buttonConfig || ! ppcpConfig ) { if ( ! buttonConfig || ! ppcpConfig ) {
return; return;
} }
@ -14,8 +14,12 @@ import { setupButtonEvents } from '../../../ppcp-button/resources/js/modules/Hel
setupButtonEvents( function () { setupButtonEvents( function () {
manager.reinit(); manager.reinit();
} ); } );
}; }
function bootstrap() {
bootstrapPayButton();
// Other Apple Pay bootstrapping could happen here.
}
document.addEventListener( 'DOMContentLoaded', () => { document.addEventListener( 'DOMContentLoaded', () => {
if ( ! buttonConfig || ! ppcpConfig ) { if ( ! buttonConfig || ! ppcpConfig ) {
@ -29,13 +33,13 @@ import { setupButtonEvents } from '../../../ppcp-button/resources/js/modules/Hel
return; return;
} }
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled; const usedInMiniCart = ppcpConfig.mini_cart_buttons_enabled;
const isButton = const pageHasButton =
null !== document.getElementById( buttonConfig.button.wrapper ); null !== document.getElementById( buttonConfig.button.wrapper );
// If button wrapper is not present then there is no need to load the scripts. // If button wrapper is not present then there is no need to load the scripts.
// minicart loads later? // minicart loads later?
if ( ! isMiniCart && ! isButton ) { if ( ! usedInMiniCart && ! pageHasButton ) {
return; return;
} }