1 && path.charAt(path.length - 1) === "/") { path = path.slice(0, -1); } if (path === "/contact") { fab.hidden = true; return; } /* browsers without keep the plain link to /contact/ */ if (typeof dlg.showModal !== "function") { return; } var form = $("edcForm"), body = $("edcBody"), done = $("edcDone"), err = $("edcErr"), send = $("edcSend"), subj = $("edcSubject"), topic = $("edcTopic"), page = $("edcPage"); function openDlg(){ if (page) { page.value = window.location.href; } dlg.showModal(); document.documentElement.style.overflow = "hidden"; fab.setAttribute("aria-expanded", "true"); var first = $("edcName"); if (first && body.style.display !== "none") { first.focus(); } } function closeDlg(){ if (dlg.open) { dlg.close(); } } function resetDlg(){ form.reset(); body.style.display = ""; done.style.display = "none"; err.style.display = "none"; send.disabled = false; send.textContent = "Send message"; } fab.addEventListener("click", function(e){ e.preventDefault(); openDlg(); }); $("edcClose").addEventListener("click", closeDlg); $("edcDoneBtn").addEventListener("click", closeDlg); dlg.addEventListener("click", function(e){ if (e.target === dlg) { closeDlg(); } }); dlg.addEventListener("close", function(){ document.documentElement.style.overflow = ""; fab.setAttribute("aria-expanded", "false"); if (done.style.display !== "none") { resetDlg(); } fab.focus(); }); if (topic && subj) { topic.addEventListener("change", function(){ subj.value = "Contact form: " + topic.value; }); } if (!window.fetch || !window.FormData) { return; } form.addEventListener("submit", function(e){ e.preventDefault(); err.style.display = "none"; send.disabled = true; send.textContent = "Sending..."; window.fetch(form.action, { method: "POST", body: new window.FormData(form), headers: { "Accept": "application/json" } }).then(function(res){ if (!res.ok) { return res.json().then(function(d){ var m = (d && d.errors && d.errors.length && d.errors[0].message) ? d.errors[0].message : ""; throw new Error(m || "status " + res.status); }, function(){ throw new Error("status " + res.status); }); } body.style.display = "none"; done.style.display = "block"; done.focus(); if (typeof window.gtag === "function") { try { window.gtag("event", "generate_lead", { form_name: "contact_popup", topic: topic ? topic.value : "" }); } catch (x) {} } }).catch(function(ex){ send.disabled = false; send.textContent = "Send message"; var msg = ex && ex.message && ex.message.indexOf("status") !== 0 ? ex.message + "." : "The message didn't send."; err.textContent = msg + " Check your details and try again, or email us via the contact page."; err.style.display = "block"; }); }); })();