PageSourceSearch

https://www.rd.com/wp-content/plugins/tmbi-ad-density/js/ad-markup.js?ver=9.0.0

js rd.com collected 2026-09-24 07:15:00 UTC 4,227 bytes, 144 lines download raw bytes

1/**
2 * Method to get the AY ad markup
3 * 
4 * @param {string} id Values like ABC,123, AB123, etc.
5 * @param {object} options Object of options for the ad
6 * @param {string} defaultClasses Default class for wrapper
7 * 
8 * @returns {string} HTML markup for the ad
9 */
10function tmbiDAIGetAYAdMarkup ( id, options, defaultClasses = '', adCounter = 0 ) {
11	if ( tmbiDAIIsServiceBlocked() ) {
12		throw new Error( 'DAI Service is blocked.' );
13	}
14
15	// check if options is empty.
16	if ( !options ) {
17		throw new Error( 'DAI Widget is not configured.' );
18	}
19	if ( !options[ 'slot_name' ] ) {
20		throw new Error( 'DAI Slot name is required.' );
21	}
22
23	if ( wp.hooks.applyFilters( 'exclude_ad_slot', false, options[ 'slot_name' ] ) ) {
24		return '';
25	}
26
27	let classList = 'tmbi-ad-slot ay-ad-unit-wrapper dai-ad-wrapper';
28	classList += ' ad-type-' + ( options['ad_type'] ? options['ad_type'] : 'content' );
29	
30	let adOptions                 = {};
31	let adUnitPath                = window.daiSettings?.adUnitPath ?? '';
32	adOptions['slot' ]            = id;
33	adOptions['ad-unit-path' ]    = adUnitPath + options['slot_name'];
34	adOptions['glide-on-desktop'] = options['glide_on_desktop'] ? 1 : 0;
35	adOptions['glide-on-mobile']  = options['glide_on_mobile'] ? 1 : 0;
36	adOptions['is-sticky']        = options['is_sticky'] ? 1 : 0;
37
38	let glideOnDesktop = !!adOptions[ 'glide-on-desktop' ];
39	let glideOnMobile = !!adOptions[ 'glide-on-mobile' ];
40	let isSticky = !!adOptions[ 'is-sticky' ];
41
42	defaultClasses = defaultClasses.trim();
43
44	let wrapperClasses = tmbiDAIGetAdWrapperClasses( defaultClasses, glideOnDesktop, glideOnMobile, isSticky );
45
46	let style = ' style="';
47	if ( options[ 'height' ] ) {
48		style += ` height: ${ options[ 'height' ] }px;`;
49	}
50
51	style += '"';
52
53	let markup = `<div class="${ wrapperClasses }"${ style }>`;
54	classList += isSticky ? ' sticky-ad' : '';
55
56	let adId = tmbiDAIGetStaticDivId( options['slot_name'], id );
57
58	// Set targeting for DAI ads.
59	adOptions[ 'targeting' ] = options[ 'targeting' ] || {};
60	if ( adOptions.targeting.DAI && 'y' === adOptions.targeting.DAI ) {
61		adOptions.targeting.slot = adCounter;
62	}
63
64	tmbiDAILog( adOptions );
65
66	markup += `<div id="${ adId }" class="${ classList }" ${ tmbiDAIAdOptionsToAttributes( adOptions ).join( ' ' ) }></div>`;
67
68	markup += '</div>';
69
70	return markup;
71}
72
73/**
74 * Method to convert ad options to attributes
75 * 
76 * @param {object} adOptions Object of options for the ad
77 * 
78 * @returns {string} String of attributes
79 */
80function tmbiDAIAdOptionsToAttributes ( adOptions ) {
81	return Object.keys( adOptions ).map( key => {
82		let attributeName = `data-${ key.replace( /[_ ]/g, '-' ) }`;
83		let value = adOptions[ key ];
84
85		if ( typeof value === 'boolean' ) {
86			return value ? attributeName : '';
87		} else if ( Array.isArray( value ) || typeof value === 'object' ) {
88			return `${ attributeName }='${ JSON.stringify( value ) }'`;
89		} else {
90			return `${ attributeName }="${ value }"`;
91		}
92	} ).filter( Boolean );
93}
94
95/**
96 * Method to get the ID for ad div
97 * 
98 * @param {object} adOptions Object of options for the ad
99 * @param {string} id ID for the ad
100 * 
101 * @returns {string} New ID for the ad
102 */
103function tmbiDAIGetStaticDivId ( slotName, id ) {
104	let slotNameParts = slotName.split( '/' );
105	let adId = slotNameParts[ 2 ] || slotNameParts[ 1 ] || id;
106	adId = adId.replaceAll( '_', '-' );
107
108	if ( 'cm-right-rail' === adId ) {
109		return adId;
110	}
111	return 'dai-' + adId;
112}
113
114/**
115 * Method to get class for ad wrapper div
116 * 
117 * @param {string} defaultClasses Default classes or ad wrapper div
118 * @param {boolean} glideOnDesktop Status of glide on desktop
119 * @param {boolean} glideOnMobile Status of glide on mobile
120 * @param {boolean} isSticky Is sticky enabled or not
121 * 
122 * @returns {string} Classes of ad wrappper div
123 */
124function tmbiDAIGetAdWrapperClasses ( defaultClasses, glideOnDesktop, glideOnMobile, isSticky ) {
125	let wrapperClasses = 'ad-container-wrapper dai-ad-wrapper';
126
127	if ( isSticky ) {
128		wrapperClasses += ' sticky-ad-container';
129	}
130
131	if ( glideOnDesktop ) {
132		wrapperClasses += ' glide-on-desktop';
133	}
134
135	if ( glideOnMobile ) {
136		wrapperClasses += ' glide-on-mobile';
137	}
138
139	if ( defaultClasses ) {
140		wrapperClasses += ` ${ defaultClasses }`;
141	}
142
143	return wrapperClasses;
144}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.