@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
51 lines (50 loc) • 1.67 kB
JavaScript
import {
attachHtmlToIframeWithNonce as m,
buildBrazeBridge as b,
} from "../../util/html-display-utils.js";
import N from "../../../shared-lib/logger.js";
import { logBannerClick as E } 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 r = Object.assign(Object.assign({}, b(e)), {
logClick: function () {
E(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 = r),
(t.appboyBridge = r),
t.dispatchEvent(new CustomEvent("ab.BridgeReady"));
}),
e
);
}