1+ import { log } from '@guardian/libs' ;
12import { createAdSlot } from '../lib/create-ad-slot' ;
23import fastdom from '../lib/fastdom-promise' ;
34import { shouldIncludeMobileSticky } from '../lib/header-bidding/utils' ;
@@ -33,15 +34,17 @@ const createAdWrapper = () => {
3334 */
3435export const init = ( ) : Promise < void > => {
3536 if ( shouldIncludeMobileSticky ( ) ) {
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 ( ( ) => {
37+ document . addEventListener ( 'banner:close' , ( ) => {
38+ void ( async ( ) => {
39+ log ( 'commercial' , '🪵 Supporter revenue banner closed' ) ;
40+ const mobileStickyWrapper = createAdWrapper ( ) ;
41+
42+ await fastdom . mutate ( ( ) => {
43+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Is body really always defined?
44+ if ( document . body && mobileStickyWrapper ) {
45+ document . body . appendChild ( mobileStickyWrapper ) ;
46+ }
47+ } ) ;
4548 if ( mobileStickyWrapper ) {
4649 const mobileStickyAdSlot =
4750 mobileStickyWrapper . querySelector < HTMLElement > (
@@ -51,7 +54,8 @@ export const init = (): Promise<void> => {
5154 void fillDynamicAdSlot ( mobileStickyAdSlot , true ) ;
5255 }
5356 }
54- } ) ;
57+ } ) ( ) ;
58+ } ) ;
5559 }
5660
5761 return Promise . resolve ( ) ;
0 commit comments