UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

74 lines (73 loc) 2.82 kB
import ro from "../../util/browser-detector.js"; import { logInAppMessageHtmlClick } from "../index.js"; import { OperatingSystems as so } from "../../util/device-constants.js"; import { buildHtmlClickHandler as ct } from "./html-message-display-utils.js"; import { attachHtmlToIframeWithNonce as b } from "../../util/html-display-utils.js"; import { buildBrazeBridge as N } from "../../util/html-display-utils.js"; import { IamServerTypes as dt } from "../constants.js"; export default function ft(t, o, s, e, n) { const i = document.createElement("iframe"); i.setAttribute("title", "Modal Message"), e && (i.style.zIndex = (e + 1).toString()); if ( (b(i, t.message, n), (i.onload = () => { const e = i.contentWindow; e.focus(); const a = e.document.getElementsByTagName("head")[0]; if (null != a) { if (t.Mo()) { const o = document.createElement("style"); (o.innerHTML = t.css || ""), (o.id = t.Oo() || ""), null != n && o.setAttribute("nonce", n), a.appendChild(o); } const o = e.document.createElement("base"); null != o && (o.setAttribute("target", "_parent"), a.appendChild(o)); } const l = e.document.getElementsByTagName("title"); l && l.length > 0 && i.setAttribute("title", l[0].textContent || ""); const r = Object.assign( Object.assign( {}, N(i, (o, s) => t.tl(o, s)), ), { closeMessage: function () { t.tl(i); }, logClick: function () { logInAppMessageHtmlClick(t, ...arguments); }, }, ); if (((e.appboyBridge = r), (e.brazeBridge = r), t.ko !== dt.PE)) { const o = e.document.getElementsByTagName("a"); for (let e = 0; e < o.length; e++) o[e].onclick = ct(t, i, o[e], s); const n = e.document.getElementsByTagName("button"); for (let o = 0; o < n.length; o++) n[o].onclick = ct(t, i, n[o], s); } const c = e.document.body; if (null != c) { t.Bo() && (c.id = t.htmlId || ""); const o = document.createElement("hidden"); (o.onclick = r.closeMessage), (o.className = "ab-programmatic-close-button"), c.appendChild(o); } e.dispatchEvent(new CustomEvent("ab.BridgeReady")), -1 !== i.className.indexOf("ab-start-hidden") && ((i.className = i.className.replace("ab-start-hidden", "")), o(i)); }), (i.className = "ab-in-app-message ab-start-hidden ab-html-message ab-modal-interactions"), ro.OS === so.co) ) { const o = document.createElement("div"); return ( (o.className = "ab-ios-scroll-wrapper"), o.appendChild(i), (t.Eo = o), o ); } return (t.Eo = i), i; }