UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

63 lines (62 loc) 2.04 kB
import { attachHtmlToIframeWithNonce as m, buildBrazeBridge as b, } from "../../util/html-display-utils.js"; import r from "../../managers/braze-instance.js"; import N from "../../../shared-lib/logger.js"; import { BRAZE_MUST_BE_INITIALIZED_ERROR as p } from "../../common/constants.js"; import { logBannerClick } from "../log-banner-click.js"; export const BANNER_PLACEMENT_ID = "data-ab-banner-placement-id"; export const BANNER_HTML_CLASS = "ab-html-banner"; export const CONTROL_BANNER_HTML_CLASS = "ab-html-control-banner"; export function controlBannerToHtml(n) { const t = document.createElement("div"); return ( (t.id = n.id), (t.className = "ab-html-control-banner"), t.setAttribute(BANNER_PLACEMENT_ID, n.placementId), t ); } export function bannerToHtml(n, t) { if (n.Jt()) return controlBannerToHtml(n); const e = document.createElement("iframe"); return ( (e.id = n.id), t && e.setAttribute("nonce", t), (e.className = "ab-html-banner"), e.setAttribute(BANNER_PLACEMENT_ID, n.placementId), e.setAttribute("title", "Banner"), m(e, n.html, t), (e.onload = () => { const t = e.contentWindow, o = t.document.getElementsByTagName("title"); o && o.length > 0 && e.setAttribute("title", o[0].textContent || ""); const a = Object.assign( Object.assign( {}, b(e, () => { import("../../Feed/ui/show-feed.js").then((n) => { r.nn() ? n.showFeed() : N.error(p); }); }), ), { logClick: function () { logBannerClick(n, ...arguments); }, closeMessage: function () {}, setBannerHeight: (n) => { isNaN(n) || !isFinite(n) || n < 0 ? N.warn(`Invalid banner height: ${n}`) : (e.style.height = `${n}px`); }, }, ); (t.brazeBridge = a), (t.appboyBridge = a), t.dispatchEvent(new CustomEvent("ab.BridgeReady")); }), e ); }