(function() { // Récupère l'attribut data-booking const scriptTag = document.currentScript; const bookingId = scriptTag.getAttribute("data-booking"); if (!bookingId) { console.error("WeddingPlan Embed Error: data-booking manquant."); return; } // Crée un wrapper const wrapper = document.createElement("div"); wrapper.style.width = "100%"; wrapper.style.position = "relative"; // Crée l'iframe const iframe = document.createElement("iframe"); iframe.src = "https://form.weddingplan.fr/fr/store-booking/" + bookingId + "/new2/1"; iframe.style.width = "100%"; iframe.style.border = "0"; iframe.style.overflow = "hidden"; iframe.style.display = "block"; iframe.setAttribute("scrolling", "no"); iframe.setAttribute("id", "weddingplan-booking-" + bookingId); wrapper.appendChild(iframe); // Insère dans le DOM juste à la place du script scriptTag.parentNode.insertBefore(wrapper, scriptTag); // Réception des messages via postMessage window.addEventListener("message", function(event) { if (event.data.type === "wp-booking-height") { iframe.style.height = event.data.height + "px"; } if (event.data.type === "wp-booking-scroll") { var iframeTop = iframe.getBoundingClientRect().top + window.pageYOffset; window.scrollTo({ top: iframeTop + event.data.offset - 80, behavior: "smooth" }); } }); })();