|
1 | | -import { log } from '@guardian/libs'; |
2 | 1 | import { createAdSlot } from '../lib/create-ad-slot'; |
3 | 2 | import fastdom from '../lib/fastdom-promise'; |
4 | 3 | import { shouldIncludeMobileSticky } from '../lib/header-bidding/utils'; |
@@ -32,36 +31,27 @@ const createAdWrapper = () => { |
32 | 31 | * Initialise mobile sticky ad slot |
33 | 32 | * @returns Promise |
34 | 33 | */ |
35 | | - |
36 | | -const renderMobileStickySlot = async () => { |
37 | | - log('commercial', '🪵 Rendering MobileSticky'); |
38 | | - const mobileStickyWrapper = createAdWrapper(); |
39 | | - await fastdom.mutate(() => { |
40 | | - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Is body really always defined? |
41 | | - if (document.body && mobileStickyWrapper) { |
42 | | - document.body.appendChild(mobileStickyWrapper); |
43 | | - } |
44 | | - }); |
45 | | - if (mobileStickyWrapper) { |
46 | | - const mobileStickyAdSlot = |
47 | | - mobileStickyWrapper.querySelector<HTMLElement>( |
48 | | - '#dfp-ad--mobile-sticky', |
49 | | - ); |
50 | | - if (mobileStickyAdSlot) { |
51 | | - void fillDynamicAdSlot(mobileStickyAdSlot, true); |
52 | | - } |
53 | | - } |
54 | | -}; |
55 | | - |
56 | 34 | export const init = (): Promise<void> => { |
57 | | - const handleBannerEvent = () => { |
58 | | - log('commercial', '🪵 Handle Banner Event'); |
59 | | - void renderMobileStickySlot(); |
60 | | - }; |
61 | | - |
62 | 35 | if (shouldIncludeMobileSticky()) { |
63 | | - document.addEventListener('banner:close', handleBannerEvent); |
64 | | - document.addEventListener('banner:none', handleBannerEvent); |
| 36 | + const mobileStickyWrapper = createAdWrapper(); |
| 37 | + return fastdom |
| 38 | + .mutate(() => { |
| 39 | + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Is body really always defined? |
| 40 | + if (document.body && mobileStickyWrapper) { |
| 41 | + document.body.appendChild(mobileStickyWrapper); |
| 42 | + } |
| 43 | + }) |
| 44 | + .then(() => { |
| 45 | + if (mobileStickyWrapper) { |
| 46 | + const mobileStickyAdSlot = |
| 47 | + mobileStickyWrapper.querySelector<HTMLElement>( |
| 48 | + '#dfp-ad--mobile-sticky', |
| 49 | + ); |
| 50 | + if (mobileStickyAdSlot) { |
| 51 | + void fillDynamicAdSlot(mobileStickyAdSlot, true); |
| 52 | + } |
| 53 | + } |
| 54 | + }); |
65 | 55 | } |
66 | 56 |
|
67 | 57 | return Promise.resolve(); |
|
0 commit comments