bound[formId] = true;
}
// Primary path: HubSpot tells us a form is ready.
window.addEventListener("message", function (e) {
if (!e.data || e.data.type !== "hsFormCallback") return;
if (e.data.eventName !== "onFormReady") return;
var id = e.data.id;
setTimeout(function () { // let HubSpot finish painting the fields
bindForm(document.getElementById("hsForm_" + id), id);
}, 0);
});
// Fallback: if our listener registered after HubSpot already fired onFormReady,
// the message is gone and the primary path never runs. Sweep for rendered forms
// so placement in the page (header vs footer) cannot cause a silent no-op.
// bindForm is idempotent, so a form caught by both paths binds exactly once.
var tries = 0;
var sweep = setInterval(function () {
var forms = document.querySelectorAll("form.hs-form");
for (var i = 0; i < forms.length; i++) {
var id = (forms[i].id || "").replace(/^hsForm_/, "");
if (id) bindForm(forms[i], id);
}
if (++tries >= 20) clearInterval(sweep); // give up after 10s
}, 500);
})();