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

Function affinity

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

Source from the content-addressed store, hash-verified

5 * @param {!Object} data
6 */
7export function affinity(global, data) {
8 validateData(
9 data,
10 ['width', 'height', 'adtype', ['adslot', 'slot']],
11 [
12 'affLayout',
13 'multiSize',
14 'affSticky',
15 'affTitle',
16 'affJson',
17 'affRtcConfig',
18 'jsontargeting',
19 'extras',
20 ]
21 );
22
23 const runV1 = function (g, d) {
24 if (false === g.isInitCalled) {
25 g.isInitCalled = true;
26 loadScript(g, gGPT, () => {
27 loadScript(g, affCDN + '/amp/v2022/amp.js', () => {
28 (function () {
29 window.affinity.initAMP(g, d);
30 })();
31 });
32 });
33 }
34 },
35 O2s = Object.prototype.toString,
36 isObject = function (val) {
37 return '[object Object]' == O2s.call(val);
38 },
39 chkIsvalidContext = function (mixContext) {
40 if ('string' == typeof mixContext) {
41 try {
42 mixContext = JSON.parse(mixContext);
43 } catch (e) {
44 return false;
45 }
46 }
47 if (isObject(mixContext) && mixContext.sourceUrl) {
48 return true;
49 }
50 return false;
51 },
52 getAmpContext = function () {
53 if (chkIsvalidContext(W.context)) {
54 return W.context;
55 }
56 if (chkIsvalidContext(W.AMP_CONTEXT_DATA)) {
57 return W.AMP_CONTEXT_DATA;
58 }
59
60 return undefined;
61 },
62 jsonParse = function (strJson) {
63 let ret = null;
64 try {

Callers

nothing calls this directly

Calls 10

validateDataFunction · 0.90
loadScriptFunction · 0.90
jsonParseFunction · 0.85
runV1Function · 0.85
nowMethod · 0.80
getAmpContextFunction · 0.70
StringFunction · 0.50
replaceMethod · 0.45
pushMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected