MCPcopy Create free account
hub / github.com/ampproject/amphtml / adunity

Function adunity

ads/vendors/adunity.js:7–81  ·  view source on GitHub ↗
(global, data)

Source from the content-addressed store, hash-verified

5 * @param {!Object} data
6 */
7export function adunity(global, data) {
8 const doc = global.document;
9
10 validateData(
11 data,
12 ['auAccount', 'auSite'],
13 [
14 'auSection',
15 'auZone',
16 'auDemo',
17 'auIsdemo',
18 'auAd',
19 'auOrder',
20 'auSegment',
21 'auOptions',
22 'auSources',
23 'auAds',
24 'auTriggerFn',
25 'auTriggerVal',
26 'auCallbackVal',
27 'auCallbackFn',
28 'auPassbackFn',
29 'auPassbackVal',
30 'auClick',
31 'auDual',
32 'auImpression',
33 'auVideo',
34 ]
35 );
36
37 //prepare tag structure
38 const tag = doc.createElement('div');
39 tag.classList.add('au-tag');
40 tag.setAttribute('data-au-width', data['width']);
41 tag.setAttribute('data-au-height', data['height']);
42
43 if (data != null) {
44 for (const key in data) {
45 //skip not valid attributes
46 if (!hasOwnProperty.call(data, key)) {
47 continue;
48 }
49
50 //skip if attribute is type or ampSlotIndex
51 if (key.startsWith('type') || key.startsWith('ampSlotIndex')) {
52 continue;
53 }
54
55 if (key.startsWith('au')) {
56 if (key == 'auVideo') {
57 tag.setAttribute('class', 'au-video');
58 } else {
59 const auKey = key.substring(2).toLowerCase();
60 tag.setAttribute('data-au-' + auKey, data[key]);
61 }
62 }
63 }
64 }

Callers

nothing calls this directly

Calls 7

validateDataFunction · 0.90
renderTagsFunction · 0.85
observeIntersectionMethod · 0.80
addMethod · 0.45
setAttributeMethod · 0.45
forEachMethod · 0.45
getElementByIdMethod · 0.45

Tested by

no test coverage detected