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

Function dable

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

Source from the content-addressed store, hash-verified

5 * @param {!Object} data
6 */
7export function dable(global, data) {
8 // check required props
9 validateData(data, ['widgetId']);
10
11 global.dable =
12 global.dable ||
13 function () {
14 (global.dable.q = global.dable.q || []).push(arguments);
15 };
16 global.dable(
17 'setService',
18 data['serviceName'] || global.window.context.location.hostname
19 );
20 global.dable(
21 'setURL',
22 global.window.context.canonicalUrl || global.window.context.sourceUrl
23 );
24 global.dable('setRef', global.window.context.referrer);
25
26 const slot = global.document.createElement('div');
27 slot.id = '_dbl_' + Math.floor(Math.random() * 100000);
28 slot.setAttribute('data-widget_id', data['widgetId']);
29
30 const divContainer = global.document.getElementById('c');
31 if (divContainer) {
32 divContainer.appendChild(slot);
33 }
34
35 const itemId = data['itemId'] || '';
36 const channel = data['channel'] || '';
37 const articleSection = data['articleSection'] || '';
38 const articleSection2 = data['articleSection2'] || '';
39 const articleSection3 = data['articleSection3'] || '';
40 const orgServiceId = data['orgServiceId'] || '';
41 const widgetOpts = {};
42 const logOpts = {};
43
44 if (channel) {
45 widgetOpts.channel = channel;
46 }
47 if (articleSection) {
48 widgetOpts.category1 = articleSection;
49 logOpts.category1 = articleSection;
50 }
51 if (articleSection2) {
52 widgetOpts.category2 = articleSection2;
53 logOpts.category2 = articleSection2;
54 }
55 if (articleSection3) {
56 widgetOpts.category3 = articleSection3;
57 logOpts.category3 = articleSection3;
58 }
59 if (orgServiceId) {
60 widgetOpts.orgServiceId = orgServiceId;
61 logOpts.orgServiceId = orgServiceId;
62 }
63
64 if (itemId) {

Callers

nothing calls this directly

Calls 7

validateDataFunction · 0.90
loadScriptFunction · 0.90
renderStartMethod · 0.80
noContentAvailableMethod · 0.80
pushMethod · 0.45
setAttributeMethod · 0.45
getElementByIdMethod · 0.45

Tested by

no test coverage detected