GROW WITH US
“The truth is not for all men but only for those who seek it.”
Ayn Rand
“The truth is not for all men but only for those who seek it.”
Ayn Rand
(function(){
if (window.__ET_POPUP_LOADED__) return;
window.__ET_POPUP_LOADED__ = true;
const HOMEPAGE_PATHS = ["/", "/home"];
const OPEN_AFTER_MS = 30000;
const OPEN_AT_SCROLL_PERCENT = 50;
const HUBSPOT_PORTAL_ID = "8742080";
const HUBSPOT_FORM_GUID = "34f8e2d7-d5e9-4a8a-aa51-02e2d95c058b";
const HUBSPOT_ENDPOINT =
`https://api.hsforms.com/submissions/v3/integration/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}`;
const RATIO = 197 / 255;
const THANK_YOU_MS = 5000;
const POPUP_SCALE_DESKTOP = 0.92;
const POPUP_SCALE_PHONE = 0.96;
const normPath = (p) => (p || "/").replace(/\/+$/,"") || "/";
const onHomepage = () => HOMEPAGE_PATHS.includes(normPath(window.location.pathname));
const isPhone = () => window.matchMedia && window.matchMedia("(max-width: 480px)").matches;
const overlay = document.getElementById("etPopupOverlay");
const overlayBg = document.getElementById("etPopupOverlayBg");
const modal = document.getElementById("etPopupModal");
const closeBtn = document.getElementById("etPopupClose");
const form = document.getElementById("etPopupForm");
const firstInp = document.getElementById("etPopupFirst");
const lastInp = document.getElementById("etPopupLast");
const emailInp = document.getElementById("etPopupEmail");
const consentCb = document.getElementById("etPopupConsent");
const thanks = document.getElementById("etThanks");
const submitBtn = document.getElementById("etSubmitBtn");
const errBox = document.getElementById("etPopupError");
if (!overlay || !overlayBg || !modal || !closeBtn || !form || !emailInp || !thanks || !submitBtn) return;
if (!onHomepage()) return;
let opened = false;
let timerId = null;
function showError(msg){
if (!errBox) return;
errBox.textContent = msg || "Sorry — something went wrong. Please try again.";
errBox.classList.add("is-visible");
}
function clearError(){
if (!errBox) return;
errBox.textContent = "";
errBox.classList.remove("is-visible");
}
function cleanupTriggers(){
if (timerId) clearTimeout(timerId);
window.removeEventListener("scroll", onScroll, {passive:true});
}
function lockPage(){
document.documentElement.classList.add("et-popup-open");
document.body.classList.add("et-popup-open");
}
function unlockPage(){
document.documentElement.classList.remove("et-popup-open");
document.body.classList.remove("et-popup-open");
}
function viewport(){
const vv = window.visualViewport;
const w = vv ? vv.width : window.innerWidth;
const h = vv ? vv.height : window.innerHeight;
return { w, h };
}
function fitModal(){
if (!overlay.classList.contains("is-open")) return;
const { w:vw, h:vh } = viewport();
const pad = isPhone() ? 20 : 46;
const scale = isPhone() ? POPUP_SCALE_PHONE : POPUP_SCALE_DESKTOP;
const maxW = Math.floor((vw - pad) * (isPhone() ? 0.96 : 0.44) * scale);
const maxH = Math.floor((vh - pad) * (isPhone() ? 0.82 : 0.78) * scale);
const hFromW = maxW / RATIO;
let w, h;
if (hFromW <= maxH) { w = maxW; h = Math.floor(hFromW); }
else { h = maxH; w = Math.floor(h * RATIO); }
w = Math.max(300, w);
h = Math.max(420, h);
modal.style.width = w + "px";
modal.style.height = h + "px";
modal.style.setProperty("--etW", w + "px");
modal.style.setProperty("--etH", h + "px");
}
function openPopup(){
if (opened) return;
opened = true;
lockPage();
overlay.classList.add("is-open");
overlay.setAttribute("aria-hidden","false");
cleanupTriggers();
fitModal();
const vv = window.visualViewport;
if (vv) vv.addEventListener("resize", fitModal);
window.addEventListener("resize", fitModal);
window.addEventListener("orientationchange", fitModal);
setTimeout(() => (firstInp || emailInp).focus({preventScroll:true}), 60);
}
function closePopup(){
overlay.classList.remove("is-open");
overlay.setAttribute("aria-hidden","true");
unlockPage();
cleanupTriggers();
const vv = window.visualViewport;
if (vv) vv.removeEventListener("resize", fitModal);
window.removeEventListener("resize", fitModal);
window.removeEventListener("orientationchange", fitModal);
}
function onScroll(){
const doc = document.documentElement;
const scrollTop = (window.pageYOffset || doc.scrollTop);
const scrollHeight = doc.scrollHeight - doc.clientHeight;
if (scrollHeight <= 0) return;
const pct = (scrollTop / scrollHeight) * 100;
if (pct >= OPEN_AT_SCROLL_PERCENT) openPopup();
}
timerId = setTimeout(openPopup, OPEN_AFTER_MS);
window.addEventListener("scroll", onScroll, {passive:true});
closeBtn.addEventListener("click", closePopup);
overlayBg.addEventListener("click", closePopup);
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && overlay.classList.contains("is-open")) closePopup();
});
async function submitToHubSpot({firstname, lastname, email, consent}){
const payload = {
submittedAt: Date.now(),
fields: [
{ name: "firstname", value: firstname },
{ name: "lastname", value: lastname },
{ name: "email", value: email },
{ name: "et_email_consent", value: consent ? "true" : "false" }
],
context: { pageUri: window.location.href, pageName: document.title },
legalConsentOptions: {
consent: {
consentToProcess: true,
text: "I agree to receive Eagle Talon Partners’ email insights. I can unsubscribe anytime."
}
}
};
const res = await fetch(HUBSPOT_ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
let data = null;
try { data = await res.json(); } catch(e) {}
if (!res.ok) {
const msg =
(data && (data.message || data.error)) ||
(data && data.errors && data.errors[0] && data.errors[0].message) ||
`HubSpot rejected the submission (HTTP ${res.status}).`;
throw new Error(msg);
}
}
form.addEventListener("submit", async (e) => {
e.preventDefault();
clearError();
const firstname = (firstInp?.value || "").trim();
const lastname = (lastInp?.value || "").trim();
const email = (emailInp?.value || "").trim();
const consent = !!consentCb?.checked;
if (!firstname || !lastname || !email) {
showError("Please complete First Name, Last Name, and Email Address.");
return;
}
if (!consent) {
showError("Please check the consent box to subscribe.");
return;
}
submitBtn.disabled = true;
submitBtn.textContent = "Submitting…";
try {
await submitToHubSpot({ firstname, lastname, email, consent });
thanks.classList.add("is-visible");
setTimeout(() => {
thanks.classList.remove("is-visible");
form.reset();
submitBtn.disabled = false;
submitBtn.textContent = "Subscribe";
closePopup();
}, THANK_YOU_MS);
} catch (err) {
submitBtn.disabled = false;
submitBtn.textContent = "Subscribe";
showError(err?.message || "Sorry — something went wrong. Please try again.");
console.error("ET Popup submit error:", err);
}
});
})();