var hsfw_formId = "3014d264-6358-47e4-bb78-8f3f4889ec1f"; var hsfw_prod = "false"; const init = () => { const pageUrl = hsfw_getPageUrl(); const formattedUrl = hsfw_formatUrl(pageUrl); const container = hsfw_createContainer(); const clientInfo = hsfw_getClientInfo(); hsfw_setContainerStyle(container); const iframe = hsfw_createIframe(hsfw_formId, formattedUrl, clientInfo); hsfw_addMessageListener(); container.appendChild(iframe); return container } //#region Functions /** * Sets the style for the container element. * @param {HTMLElement} container - The container element. */ function hsfw_setContainerStyle(container) { // set container styles to expand to full width and height of the parent element container.style.width = "100%"; container.style.height = "100%"; container.style.zIndex = "10000"; container.style.backgroundColor = "transparent"; container.style.overflow = "hidden"; container.style.display = "block"; container.style.margin = "0"; container.style.padding = "0"; container.style.border = "none"; } /** * Gets the URL of the current page. * @returns {URL} The URL of the current page. */ function hsfw_getPageUrl() { if (window.parent !== window) { return new URL(document.referrer); } else { return new URL(window.location.href); } } /** * Gets the domain of the current page. * @returns {string} The domain of the current page. */ function hsfw_getPageDomain() { if (window.parent !== window) { return window.parent.location.hostname; } else { return window.location.hostname; } } /** * Gets the source URL for the iframe. * @returns {string} The source URL for the iframe. */ function hsfw_getSrc() { var clientDomain = hsfw_getPageDomain(); var qaDomains = [ "hsformwidget-test.azurewebsites.net", "hopesync2.wpcomstaging.com", "hopesync.wpcomstaging.com", ]; var devDomains = ["hsformwidget-dev.azurewebsites.net"]; if (hsfw_prod) { return "https://hsformwidget.azurewebsites.net"; } if (qaDomains.includes(clientDomain)) return "https://hsformwidget-test.azurewebsites.net"; if (devDomains.includes(clientDomain)) return "https://hsformwidget-dev.azurewebsites.net"; return "https://hsformwidget.azurewebsites.net"; } /** * Formats the URL of the current page. * @param {URL} pageUrl - The URL of the current page. * @returns {string} The formatted URL. */ function hsfw_formatUrl(pageUrl) { var pageProtocol = pageUrl.protocol; var pageHostname = pageUrl.hostname; var pagePathname = pageUrl.pathname; var formattedUrl = pageProtocol + "//" + pageHostname; if (pagePathname !== "/") { formattedUrl += pagePathname; } return formattedUrl; } /** * Creates a container element for the form widget. * @returns {HTMLElement} The container element. */ function hsfw_createContainer() { var container = document.createElement("div"); container.id = "hopesync_formwidget_container"; return container; } /** * Gets client information for the form widget. * @returns {string} The client information as a JSON string. */ function hsfw_getClientInfo() { return encodeURIComponent( JSON.stringify({ referringSiteURL: window.location.href, referringPageName: window.document.title, previousPage: document.referrer, referringPageVariables: hsfw_getReferringPageVariables(), deviceScreenSizeSmallerDimension: Math.min( window.screen.width, window.screen.height ), deviceScreenSizeLargerDimension: Math.max( window.screen.width, window.screen.height ), deviceOS: navigator.platform, deviceBrowser: navigator.userAgent, deviceBrowserVersion: navigator.appVersion, isMobile: hsfw_isMobileDevice(), cookiesAllowed: navigator.cookieEnabled, }) ); } /** * Gets the query parameters from the referring page. * @returns {string} The query parameters as a comma-separated string. */ function hsfw_getReferringPageVariables() { const searchParams = new URLSearchParams(window.location.search); let params = ""; for (let [key, value] of searchParams.entries()) { params += key + "=" + value + ","; } return params; } /** * Checks if the device is a mobile device. * @returns {boolean} True if the device is a mobile device, false otherwise. */ function hsfw_isMobileDevice() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ); } /** * Resizes the container element based on the height received from the message event. * @param {MessageEvent} event - The message event. */ function hsfw_resizeContainer(event) { const hsfw_height = event.data.hsfw_height; if (hsfw_height) { document.getElementById("hopesync_formwidget_container").style.height = 200 + hsfw_height + "px"; } } /** * Creates an iframe element for the form widget. * @param {string} formId - The form ID. * @param {string} formattedUrl - The formatted URL of the current page. * @param {string} clientInfo - The client information. * @returns {HTMLIFrameElement} The iframe element. */ function hsfw_createIframe(formId, formattedUrl, clientInfo) { var iframe = document.createElement("iframe"); var src = hsfw_getSrc(); iframe.title = "hopesync_formwidget_iframe"; iframe.src = `${src}/widget.html?formId=${formId}&domain=${formattedUrl}&clientInfo=${clientInfo}&src=${src}`; iframe.style.width = "100%"; iframe.style.height = "100%"; iframe.style.border = "none"; iframe.style.backgroundColor = "transparent"; return iframe; } /** * Adds a message listener to handle messages from the form widget. */ function hsfw_addMessageListener() { var gaFirstTime = true; window.addEventListener("message", (event) => { handleMessageEvent(event, gaFirstTime); }); } /** * Sends a Google Analytics message to the parent window. * @param {MessageEvent} event - The message event. */ function hsfw_sendGaMessage(event) { event.source.postMessage( { hs_gaID: event.data.hs_gaID, hs_gaGTMID: event.data.hs_gaGTMID, }, "*" ); } /** * Updates the Google Analytics iframe with the new page URL. * @param {MessageEvent} event - The message event. */ function hsfw_updateGaIframe(event) { console.info("Updating GA iframe", event.data.hs_gaPageToOpen); const iframe2 = window.parent.document.getElementById( "hsformwidget-ga-iframe" ); iframe2.setAttribute("src", event.data.hs_gaPageToOpen); } /** * Executes a function specified in the message event. * @param {MessageEvent} event - The message event. */ function hsfw_executeFunction(event) { const { calledFunction, functionParams } = event.data; try { console.info("Proceding to execute: ", calledFunction); if (typeof window[calledFunction] === "function") { window[calledFunction](functionParams); } else if (typeof window.parent[calledFunction] === "function") { window.parent[calledFunction](functionParams); } else { console.warn(`Function ${calledFunction} not found`); return; } console.info(`Function ${calledFunction} executed successfully`); } catch (error) { console.warn( `An internal error occurred while executing ${calledFunction}:`, error ); } } /** * Handles the message event from the form widget. * @param {MessageEvent} event - The message event. * @param {boolean} gaFirstTime - Flag to indicate if it's the first time handling GA message. */ function handleMessageEvent(event, gaFirstTime) { if ((event.data.hs_gaID || event.data.hs_gaGTMID) && gaFirstTime) { hsfw_sendGaMessage(event); gaFirstTime = false; } if (event.data.hs_gaPageToOpen) { hsfw_updateGaIframe(event); } if (event.data.calledFunction) { hsfw_executeFunction(event); } if (event.data.hsfw_height) { hsfw_resizeContainer(event); } } class FormWidget extends HTMLElement { constructor() { super() } connectedCallback(){ this.appendChild(init()) } } customElements.define('wix-hs-form-widget-element', FormWidget )
top of page
Donation Box
Image by Christin Noelle
Image by Kelly Sikkema

for women

for families

for LIFE

GET INVOLVED

Volunteer, be an advocate, throw a baby shower or give!

GIVE LIFE

Save lives, share truth, and transform hearts

EVENTS

Learn about ways you can partner with us all year long!

Saving lives. Bringing hope.

We exist to share hope and life-affirming options with women and men facing pregnancy decisions.

Image by Jonathan Borba
Image by Alex Pasarelu

Make an eternal impact

Your support helps us reach women considering abortion with truth, love, and options, and helps provide resources for families.

Get Involved

Thanks for submitting!

Someone from our staff will contact you soon. 

Supporters Contact
bottom of page