UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

68 lines (67 loc) 2.46 kB
import { _handleBrazeAction as Q } from "../../Core/handle-braze-action.js"; import { logInAppMessageButtonClick } from "../log-in-app-message-button-click.js"; import { toRgba as ke } from "../../util/color-utils.js"; import { addPassiveEventListener as F } from "../../util/dom-utils.js"; import { KeyCodes as Ce } from "../../util/key-codes.js"; import { IamClickAction as $e, IamOpenTarget as ut } from "../constants.js"; const xe = { Po: (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 === Ce.Wo && (o.shiftKey || (a !== s && a !== t) ? !o.shiftKey || (a !== e && a !== t) || (o.preventDefault(), s.focus()) : (o.preventDefault(), e.focus())); }); } }, Qo: (t, o) => { o.setAttribute("role", "dialog"), o.setAttribute("aria-modal", "true"), t ? o.setAttribute("aria-labelledby", t) : o.setAttribute("aria-label", "Modal Message"); }, No: (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.tl(o, () => { logInAppMessageButtonClick(s, t), s.clickAction === $e.URI && Q(s.uri || "", e || t.openTarget === ut.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"), F(a, "touchstart"); let n = e.text; "" === e.text && (n = " "), a.appendChild(document.createTextNode(n)), t.Mo() || ((a.style.backgroundColor = ke(e.backgroundColor)), (a.style.color = ke(e.textColor)), (a.style.borderColor = ke(e.borderColor))), (a.onclick = l(e)), s.appendChild(a); } } }, }; export default xe;