UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

210 lines (209 loc) 5.55 kB
import { convertMsToSeconds as X, dateFromUnixTimestamp as V, } from "../../util/date-utils.js"; import { FEED_ANIMATION_DURATION as W } from "../../common/constants.js"; import u from "../../managers/subscription-manager.js"; import N from "../../../shared-lib/logger.js"; export default class Card { constructor(t, i, s, h, l, n, e, r, u, E, T, o, a, I, N, A) { (this.id = t), (this.viewed = i), (this.title = s), (this.imageUrl = h), (this.description = l), (this.updated = n), (this.expiresAt = e), (this.url = r), (this.linkText = u), (this.aspectRatio = E), (this.extras = T), (this.pinned = o), (this.dismissible = a), (this.clicked = I), (this.language = N), (this.altImageText = A), (this.id = t), (this.viewed = i || !1), (this.title = s || ""), (this.imageUrl = h), (this.description = l || ""), (this.updated = n || null), (this.expiresAt = e || null), (this.url = r), (this.linkText = u), null == E ? (this.aspectRatio = null) : ((E = parseFloat(E.toString())), (this.aspectRatio = isNaN(E) ? null : E)), (this.extras = T || {}), (this.pinned = o || !1), (this.dismissible = a || !1), (this.dismissed = !1), (this.clicked = I || !1), (this.isControl = !1), (this.language = N || null), (this.altImageText = A || null), (this.test = !1), (this.ti = null), (this.ii = null), (this.si = null); } subscribeToClickedEvent(t) { return this.hi().Dt(t); } subscribeToDismissedEvent(t) { return this.li().Dt(t); } removeSubscription(t) { this.hi().removeSubscription(t), this.li().removeSubscription(t); } removeAllSubscriptions() { this.hi().removeAllSubscriptions(), this.li().removeAllSubscriptions(); } dismissCard() { if (!this.dismissible || this.dismissed) return; "function" == typeof this.logCardDismissal && this.logCardDismissal(); let t = this.te; !t && this.id && (t = document.getElementById(this.id)), t && ((t.style.height = t.offsetHeight + "px"), (t.className = t.className + " ab-hide"), setTimeout(function () { t && t.parentNode && ((t.style.height = "0"), (t.style.margin = "0"), setTimeout(function () { t && t.parentNode && t.parentNode.removeChild(t); }, Card.ni)); }, W)); } hi() { return null == this.ti && (this.ti = new u()), this.ti; } li() { return null == this.ii && (this.ii = new u()), this.ii; } Yt() { const t = new Date().valueOf(); return ( !(null != this.si && t - this.si < Card.ei) && ((this.si = t), (this.viewed = !0), !0) ); } $t() { (this.viewed = !0), (this.clicked = !0), this.hi().X(); } Pt() { return ( !(!this.dismissible || this.dismissed) && ((this.dismissed = !0), this.li().X(), !0) ); } ri(t) { if (null == t || t[Card.ui.os] !== this.id) return !0; if (t[Card.ui.Ei]) return !1; if ( null != t[Card.ui.us] && null != this.updated && parseInt(t[Card.ui.us]) < X(this.updated.valueOf()) ) return !0; if ( (t[Card.ui.cs] && !this.viewed && (this.viewed = !0), t[Card.ui.zs] && !this.clicked && (this.clicked = t[Card.ui.zs]), null != t[Card.ui.ns] && (this.title = t[Card.ui.ns]), null != t[Card.ui.ds] && (this.imageUrl = t[Card.ui.ds]), null != t[Card.ui.ps] && (this.description = t[Card.ui.ps]), null != t[Card.ui.us]) ) { const i = V(t[Card.ui.us]); null != i && (this.updated = i); } if (null != t[Card.ui.ls]) { let i; (i = t[Card.ui.ls] === Card.Ti ? null : V(t[Card.ui.ls])), (this.expiresAt = i); } if ( (null != t[Card.ui.URL] && (this.url = t[Card.ui.URL]), null != t[Card.ui.fs] && (this.linkText = t[Card.ui.fs]), null != t[Card.ui.xs]) ) { const i = parseFloat(t[Card.ui.xs].toString()); this.aspectRatio = isNaN(i) ? null : i; } return ( null != t[Card.ui.bs] && (this.extras = t[Card.ui.bs]), null != t[Card.ui.gs] && (this.pinned = t[Card.ui.gs]), null != t[Card.ui.js] && (this.dismissible = t[Card.ui.js]), null != t[Card.ui.ks] && (this.language = t[Card.ui.ks]), null != t[Card.ui.qs] && (this.altImageText = t[Card.ui.qs]), null != t[Card.ui.vs] && (this.test = t[Card.ui.vs]), !0 ); } bt() { N.error("Must be implemented in a subclass"); } } (Card.Ti = -1), (Card.ui = { os: "id", cs: "v", js: "db", Ei: "r", us: "ca", gs: "p", ls: "ea", bs: "e", ss: "tp", ds: "i", ns: "tt", ps: "ds", URL: "u", fs: "dm", xs: "ar", zs: "cl", vs: "t", ks: "language", qs: "image_alt", }), (Card.rs = { es: "captioned_image", oi: "text_announcement", ai: "short_news", Ii: "banner_image", Ni: "control", }), (Card.hs = { os: "id", cs: "v", js: "db", Ai: "cr", us: "ca", gs: "p", ci: "t", ls: "ea", bs: "e", ss: "tp", ds: "i", ns: "tt", ps: "ds", URL: "u", fs: "dm", xs: "ar", zs: "cl", vs: "s", ks: "l", qs: "ia", }), (Card.mi = { Si: "ADVERTISING", Di: "ANNOUNCEMENTS", pi: "NEWS", di: "SOCIAL", }), (Card.ni = 400), (Card.ei = 1e4);