Skip to content

@get-advantage/advantage / advantage/wrapper / AdvantageWrapper

Class: AdvantageWrapper ​

advantage/wrapper.AdvantageWrapper

Represents the AdvantageWrapper class, which extends the HTMLElement class and implements the IAdvantageWrapper interface. This class is responsible for creating and managing the wrapper element for Advantage ads.

Hierarchy ​

  • HTMLElement

    ↳ AdvantageWrapper

Implements ​

Constructors ​

constructor ​

• new AdvantageWrapper(): AdvantageWrapper

Creates an instance of AdvantageWrapper.

Returns ​

AdvantageWrapper

Overrides ​

HTMLElement.constructor

Defined in ​

src/advantage/wrapper.ts:51

Properties ​

#activeFormatIframe ​

• Private #activeFormatIframe: null | HTMLIFrameElement = null

Defined in ​

src/advantage/wrapper.ts:34


#disconnectTimeout ​

• Private #disconnectTimeout: null | number = null

Defined in ​

src/advantage/wrapper.ts:37


#mutationObserver ​

• Private #mutationObserver: null | MutationObserver = null

Defined in ​

src/advantage/wrapper.ts:35


#root ​

• Private #root: ShadowRoot

Defined in ​

src/advantage/wrapper.ts:30


#slotAdvantageContent ​

• Private #slotAdvantageContent: HTMLSlotElement

Defined in ​

src/advantage/wrapper.ts:31


#slotChangeHandler ​

• Private #slotChangeHandler: null | () => void = null

Defined in ​

src/advantage/wrapper.ts:36


#slotChangeRegistered ​

• Private #slotChangeRegistered: boolean = false

Defined in ​

src/advantage/wrapper.ts:32


#styleSheet ​

• Private #styleSheet: CSSStyleSheet | HTMLStyleElement

Defined in ​

src/advantage/wrapper.ts:29


#trackedIframes ​

• Private #trackedIframes: WeakSet<HTMLIFrameElement>

Defined in ​

src/advantage/wrapper.ts:33


allowedFormats ​

• allowedFormats: null | string[] = null

Implementation of ​

IAdvantageWrapper.allowedFormats

Defined in ​

src/advantage/wrapper.ts:39


container ​

• container: HTMLDivElement

Implementation of ​

IAdvantageWrapper.container

Defined in ​

src/advantage/wrapper.ts:41


content ​

• content: HTMLDivElement

Implementation of ​

IAdvantageWrapper.content

Defined in ​

src/advantage/wrapper.ts:42


currentFormat ​

• currentFormat: string = ""

Implementation of ​

IAdvantageWrapper.currentFormat

Defined in ​

src/advantage/wrapper.ts:44


messageHandler ​

• messageHandler: AdvantageAdSlotResponder

Defined in ​

src/advantage/wrapper.ts:45


simulating ​

• simulating: boolean = false

Defined in ​

src/advantage/wrapper.ts:46


uiLayer ​

• uiLayer: IAdvantageUILayer

Implementation of ​

IAdvantageWrapper.uiLayer

Defined in ​

src/advantage/wrapper.ts:43


DISCONNECT_TIMEOUT_MS ​

▪ Static Readonly DISCONNECT_TIMEOUT_MS: 100

Defined in ​

src/advantage/wrapper.ts:26

Accessors ​

contentNodes ​

• get contentNodes(): Node[]

Gets the content nodes assigned to the advantage-ad-slot.

Returns ​

Node[]

An array of content nodes.

Implementation of ​

IAdvantageWrapper.contentNodes

Defined in ​

src/advantage/wrapper.ts:220

Methods ​

#detectDOMChanges ​

▸ #detectDOMChanges(): void

Detects DOM changes and resets the wrapper if a new ad is loaded. Tracks iframes and resets the wrapper when an iframe that requested a format is removed.

Returns ​

void

Defined in ​

src/advantage/wrapper.ts:145


#updateCurrentFormatAttribute ​

▸ #updateCurrentFormatAttribute(): void

Updates the current-format attribute to match the currentFormat property. Sets the attribute when currentFormat has a value, removes it when empty.

Returns ​

void

Defined in ​

src/advantage/wrapper.ts:133


animateClose ​

▸ animateClose(callback?): void

Parameters ​

NameType
callback?() => void

Returns ​

void

Implementation of ​

IAdvantageWrapper.animateClose

Defined in ​

src/advantage/wrapper.ts:478


applyStylesToAllChildElements ​

▸ applyStylesToAllChildElements(styles): void

Applies styles to all child elements of the wrapper.

Parameters ​

NameTypeDescription
stylesstringThe CSS styles to apply.

Returns ​

void

Implementation of ​

IAdvantageWrapper.applyStylesToAllChildElements

Defined in ​

src/advantage/wrapper.ts:542


changeContent ​

▸ changeContent(content): void

Changes the content of the wrapper.

Parameters ​

NameTypeDescription
contentstring | HTMLElementThe new content to be added to the wrapper.

Returns ​

void

Implementation of ​

IAdvantageWrapper.changeContent

Defined in ​

src/advantage/wrapper.ts:419


clearAllowedFormats ​

▸ clearAllowedFormats(): void

Clears the programmatic whitelist so the wrapper falls back to attribute or default behaviour.

Returns ​

void

Implementation of ​

IAdvantageWrapper.clearAllowedFormats

Defined in ​

src/advantage/wrapper.ts:252


close ​

▸ close(): void

Closes the current ad format.

Returns ​

void

Implementation of ​

IAdvantageWrapper.close

Defined in ​

src/advantage/wrapper.ts:500


connectedCallback ​

▸ connectedCallback(): void

Lifecycle method called when the element is connected to the DOM. Clears the disconnect timeout if the element reconnects quickly.

Returns ​

void

Defined in ​

src/advantage/wrapper.ts:611


disconnectedCallback ​

▸ disconnectedCallback(): void

Lifecycle method called when the element is disconnected from the DOM. Uses a timeout to distinguish between temporary removal and actual cleanup.

Returns ​

void

Defined in ​

src/advantage/wrapper.ts:582


forceFormat ​

▸ forceFormat(format, iframe?, options?): Promise<void>

Forces a specific ad format without waiting for a message from the iframe. This allows publishers to directly control which format to display.

Parameters ​

NameTypeDescription
formatstringThe format to apply
iframe?HTMLIFrameElementThe iframe element to use for the ad (optional)
options?anyAdditional options to pass to the format's setup function

Returns ​

Promise<void>

A promise that resolves when the format has been applied

Implementation of ​

IAdvantageWrapper.forceFormat

Defined in ​

src/advantage/wrapper.ts:380


insertCSS ​

▸ insertCSS(CSS): void

Inserts CSS into the shadow root of the wrapper.

Parameters ​

NameTypeDescription
CSSstringThe CSS to insert.

Returns ​

void

Implementation of ​

IAdvantageWrapper.insertCSS

Defined in ​

src/advantage/wrapper.ts:559


morphIntoFormat ​

▸ morphIntoFormat(format, message?): Promise<void>

Morphs the wrapper into a specific ad format. If allowed-formats is set (via attribute or API) it takes precedence over exclude-formats. Comparisons are case-insensitive.

Parameters ​

NameTypeDescription
formatstringThe format to morph into.
message?AdvantageMessage-

Returns ​

Promise<void>

A promise that resolves when the morphing is complete.

Implementation of ​

IAdvantageWrapper.morphIntoFormat

Defined in ​

src/advantage/wrapper.ts:265


reset ​

▸ reset(): void

Resets the current ad format.

Returns ​

void

Implementation of ​

IAdvantageWrapper.reset

Defined in ​

src/advantage/wrapper.ts:443


resetCSS ​

▸ resetCSS(): void

Resets the CSS in the shadow root of the wrapper.

Returns ​

void

Implementation of ​

IAdvantageWrapper.resetCSS

Defined in ​

src/advantage/wrapper.ts:570


setAllowedFormats ​

▸ setAllowedFormats(formats): void

Restrict this wrapper to the given list of formats. Calling this method overrides any list previously set via attribute or API.

Parameters ​

NameTypeDescription
formatsstring[]Array of format names that are allowed for this wrapper.

Returns ​

void

Implementation of ​

IAdvantageWrapper.setAllowedFormats

Defined in ​

src/advantage/wrapper.ts:245


simulateFormat ​

▸ simulateFormat(format): Promise<void>

Simulates a specific ad format.

Parameters ​

NameTypeDescription
formatstringThe format to simulate.

Returns ​

Promise<void>

Implementation of ​

IAdvantageWrapper.simulateFormat

Defined in ​

src/advantage/wrapper.ts:228