UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

72 lines (71 loc) 2.54 kB
import InAppMessage from "../models/in-app-message.js"; import { _handleBrazeAction as O } from "../../Core/handle-braze-action.js"; import { logInAppMessageButtonClick } from "../log-in-app-message-button-click.js"; import { toRgba as ae } from "../../util/color-utils.js"; import { addPassiveEventListener as J } from "../../util/dom-utils.js"; import { KeyCodes as ie } from "../../util/key-codes.js"; const ne = { wo: (t) => { const o = t.querySelectorAll(".ab-close-button, .ab-message-button"); let e; for (let t = 0; t < o.length; t++) (e = o[t]), (e.tabIndex = 0); if (o.length > 0) { const e = o[0], s = o[o.length - 1]; t.addEventListener("keydown", (o) => { const a = document.activeElement; o.keyCode === ie.yo && (o.shiftKey || (a !== s && a !== t) ? !o.shiftKey || (a !== e && a !== t) || (o.preventDefault(), s.focus()) : (o.preventDefault(), e.focus())); }); } }, vo: (t, o) => { o.setAttribute("role", "dialog"), o.setAttribute("aria-modal", "true"), t ? o.setAttribute("aria-labelledby", t) : o.setAttribute("aria-label", "Modal Message"); }, jo: (t, o, e) => { if (t.buttons && t.buttons.length > 0) { const s = document.createElement("div"); (s.className = "ab-message-buttons"), o.appendChild(s); const a = o.getElementsByClassName("ab-message-text")[0]; null != a && (a.className += " ab-with-buttons"); const l = (s) => (a) => ( t.ll(o, () => { logInAppMessageButtonClick(s, t), s.clickAction === InAppMessage.ClickAction.URI && O( s.uri || "", e || t.openTarget === InAppMessage.OpenTarget.BLANK, a, ); }), a.stopPropagation(), !1 ); for (let o = 0; o < t.buttons.length; o++) { const e = t.buttons[o], a = document.createElement("button"); (a.className = "ab-message-button"), a.setAttribute("type", "button"), J(a, "touchstart"); let n = e.text; "" === e.text && (n = " "), a.appendChild(document.createTextNode(n)), t.Oe() || ((a.style.backgroundColor = ae(e.backgroundColor)), (a.style.color = ae(e.textColor)), (a.style.borderColor = ae(e.borderColor))), (a.onclick = l(e)), s.appendChild(a); } } }, }; export default ne;