forked from appnexus/cmp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiframeExample.jsx
More file actions
88 lines (78 loc) · 1.86 KB
/
Copy pathiframeExample.jsx
File metadata and controls
88 lines (78 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { h, render } from 'preact';
import Example from '../components/examples/example';
import queryString from 'query-string';
import '../style';
import codeStyle from '../../../node_modules/codemirror/lib/codemirror.css'; // eslint-disable-line no-unused-vars
let root;
const commonSetup =
`function receiveMessage(event) {
if (event && event.data && event.data.__cmpReturn) {
myLogger('Received Message:\\n' + JSON.stringify(event.data, null, 2));
}
}
window.addEventListener('message', receiveMessage);`;
const iframeMap =
{
getVendorConsents: {
title: 'Get Vendor Consent From IFrame',
message:
`var message = {
__cmpCall: {
callId: 'iframe:' + (++this.callId),
command: 'getVendorConsents',
parameter: [0,1,2]
}
};`
},
showConsentTool: {
title: 'Show Consent Tool From IFrame',
message:
`var message = {
__cmpCall: {
callId: 'iframe:' + (++this.callId),
command: 'showConsentTool'
}
};`
},
getConsentData: {
title: 'Get Consent Data From IFrame',
message:
`var message = {
__cmpCall: {
callId: 'iframe:' + (++this.callId),
command: 'getConsentData'
}
};`
},
addEventListeners: {
title: 'Add Event Listeners From IFrame',
message:
`var message = {
__cmpCall: {
callId: 'iframe:' + (++this.callId),
command: 'addEventListener',
parameter: 'onSubmit'
}
}`
}
};
class App extends Example {
constructor(props) {
super(props);
const search = queryString.parse(window.location.search);
const { title, message, setup='' } = iframeMap[search.iframeId];
const execute = message ? `this.callId = this.callId || 0;
${message}
myLogger('Sending Message:\\n' + JSON.stringify(message, null, 2));
window.top.postMessage(message, '*');` : undefined;
this.state = {
setup: commonSetup + setup,
title,
execute
};
}
}
function init() {
root = render(<App />, document.body, root);
}
init();