Files
2026-04-28 15:13:50 +02:00

1 line
2.1 KiB
JavaScript

(function(){function a(a){const b=document.querySelector(a);return b?((b.value||"")+"").trim():""}const b=window.wpoIpsPeppol||{};if(!b.endpoint_derivation)return;const c=b.billing_country_selector,d=b.vat_field_selector,e=b.peppol_input_wrapper_selector,f=e?e+" input":"",g=window.WPO_IPS_PeppolEndpointDerivation.init(b,{getBillingCountry:function(){try{const a=window.wp?.data?.select?.("wc/store/cart");if(a&&"function"==typeof a.getCustomerData){const b=a.getCustomerData()||{},c=b.billingAddress?.country||b.billing_address?.country||b.customer?.billingAddress?.country||b.customer?.billing_address?.country;if(c)return g.log("billing country resolved from store",c),(c+"").trim()}}catch(a){g.log("error reading billing country from store",a)}const b=a(c);return g.log("billing country resolved from DOM",b),b},getEndpointNodes(){const a=e?document.querySelector(e):null,b=f?document.querySelector(f):null;return g.log("getEndpointNodes",{wrapperSelector:e,endpointSelector:f,wrapperFound:!!a,endpointFound:!!b,currentValue:b?b.value:""}),{wrapper:a,endpoint:b}},onSetFieldValue(a,b){g.log("setting endpoint value",b);const c=a.closest(".wc-block-components-text-input");c&&b?c.classList.add("is-active"):c&&!b&&c.classList.remove("is-active")}});g.log("engine initialized",{countrySelector:c,vatSelector:d,endpointWrapperSelector:e,endpointSelector:f,debug:b.debug});const h=document.querySelector("#order-fields")||document.querySelector(".wc-block-checkout")||document.documentElement;g.log("mutation observer attached",h),new MutationObserver(()=>{g.log("mutation observed -> scheduling apply"),g.schedule("mutation")}).observe(h,{childList:!0,subtree:!0}),document.addEventListener("input",a=>{c&&a.target&&a.target.matches(c)&&(g.log("country input detected",a.target.value),g.schedule("country-input")),d&&a.target&&a.target.matches(d)&&(g.log("vat input detected",a.target.value),g.schedule("vat-input"))}),window.wp?.data?.subscribe&&(g.log("subscribed to wp.data store"),window.wp.data.subscribe(()=>{g.log("store change detected"),g.schedule("store")})),g.log("initial schedule"),g.schedule("init")})();