(function () { var IFRAME_ID = "bakegenie-enquiry"; function getIframe() { return document.getElementById(IFRAME_ID); } window.addEventListener("message", function (event) { var data = event.data; // Accept object OR JSON string (some platforms send strings) if (typeof data === "string") { try { data = JSON.parse(data); } catch (e) { return; } } if (!data || typeof data !== "object") return; var type = data.type; if (!type || !String(type).startsWith("BAKEGENIE_")) return; var iframe = getIframe(); if (!iframe) return; if (type === "BAKEGENIE_HEIGHT") { var height = data.height; if (height && height > 0) iframe.style.height = height + "px"; } if (type === "BAKEGENIE_SCROLL") { var deltaY = data.deltaY; if (deltaY) window.scrollBy({ top: deltaY, behavior: "auto" }); } if (type === "BAKEGENIE_MODAL_OPEN") { iframe.scrollIntoView({ behavior: "smooth", block: "start" }); } }); // Optional: helps if the iframe is injected dynamically function initIframe() { var iframe = getIframe(); if (iframe) { if (!iframe.style.minHeight) iframe.style.minHeight = "100vh"; return true; } return false; } if (!initIframe()) { var observer = new MutationObserver(function (_, obs) { if (initIframe()) obs.disconnect(); }); observer.observe(document.body, { childList: true, subtree: true }); } })();