UNPKG

@68publishers/amp-client

Version:

JS Client for 68publishers/amp

79 lines (60 loc) 1.93 kB
import { Fingerprint } from '../fingerprint.mjs'; import { Contents } from '../responsive/contents.mjs'; export class BannerData { #data; #contents; #fingerprint = null; constructor(data, breakpointType, dimensionsProvider) { this.#data = data; this.#contents = new Contents(dimensionsProvider, breakpointType); for (let content of this.#data.contents) { if ('img' === content.type && !('dimensions' in content)) { // BC compatibility content.dimensions = { width: null, height: null }; } this.#contents.addContent(content['breakpoint'], content); } } set fingerprint(fingerprint) { if (!(fingerprint instanceof Fingerprint)) { throw new TypeError(`The value must be instance of Fingerprint object.`); } this.#fingerprint = fingerprint; } get fingerprint() { return this.#fingerprint; } get id() { return this.#data.id; } get name() { return this.#data.name || null; } get score() { return this.#data.score; } /** * @deprecated Use property `campaignCode` instead */ get campaign() { console.warn('Usage of deprecated property `BannerData.campaign`. Please use property `campaignCode` instead.'); return this.campaignCode(); } get campaignId() { return this.#data.campaign_id || null; } get campaignCode() { return this.#data.campaign_code || this.#data.campaign || null; } get campaignName() { return this.#data.campaign_name || null; } get closedExpiration() { return 'closed_expiration' in this.#data ? this.#data.closed_expiration : null; } get content() { return this.#contents.content?.data || null; } needRedraw() { return this.#contents.needRedraw(); } }