(function () { if (window.__donationPluginLoaded) return; window.__donationPluginLoaded = true; let currentStep = 1; const STEP_RANGES = { 1: [800, 1000], 2: [1000, 1600], 3: [800, 1000], 4: [800, 1000], }; const iframeState = new WeakMap(); function applyHeight(iframe, rawHeight) { if (!iframe) return; let state = iframeState.get(iframe); if (!state) { state = { heightHistory: [0, 0, 0, 0, 0] }; iframeState.set(iframe, state); } const [min, max] = STEP_RANGES[currentStep] || [0, Infinity]; let h = rawHeight; if (h > min && h < max) { state.heightHistory[currentStep] = h; } else { h = state.heightHistory[currentStep]; } if (h) { iframe.style.height = h + "px"; } } window.addEventListener("message", function (event) { const { type, height, currentStep: step } = event.data || {}; if (type === "donationIframeHeightonBtnClick") { currentStep = step; } if (type === "donationIframeHeight") { const iframe = Array .from(document.querySelectorAll(".donation-widget iframe")) .find(f => f.contentWindow === event.source); if (iframe) { applyHeight(iframe, height); } } }); function createIframe(target) { const url = target.dataset.src; if (!url) return; if (target.querySelector("iframe")) return; const iframe = document.createElement("iframe"); iframe.src = url; iframe.loading = "lazy"; iframe.style.width = "100%"; iframe.style.height = "100%"; iframe.style.minHeight = "100vh"; iframe.style.border = "0"; iframe.style.overflow = "hidden"; iframe.setAttribute("scrolling", "yes"); target.appendChild(iframe); } function initPlugin() { document .querySelectorAll(".donation-widget") .forEach(createIframe); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", initPlugin); } else { initPlugin(); } })();