-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
79 lines (75 loc) · 2.49 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Widget</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
function raiseEvent(eventName, data) {
console.group("raiseEvent");
var event = new CustomEvent(eventName, {
detail: data,
});
console.log("event", event);
console.log("window.parent", window.parent);
if (window.parent) {
window.parent.postMessage(JSON.stringify(data), "*");
console.log("postMessage");
} else {
window.dispatchEvent(event);
console.log("this doc is not in iFrame");
}
console.groupEnd();
}
$(document).ready(function () {
console.log("parent message listener");
window.addEventListener("message", function (event) {
console.log("Message received from the parent: " + event.data);
});
console.log($("button"));
$("button").on("click", function () {
var $button = $(this);
var type = $button.attr("data-type");
//leave as customEvent, event name that will be listed to by parent
var eventName = "customEvent";
//action name
var action = "OPEN_ITEM";
//param to send to action
var config = "test_item";
//event payload
var payload = {
type: type,
config: config
};
var data = {
type: eventName,
payload: payload,
action: action,
componentId: "vizhub",
config: config,
};
console.log("button click", data);
raiseEvent(eventName, data);
});
});
</script>
</head>
<body>
<h3>Open form Github Pages:</h3>
<div>
<button class="btn btn-primary" data-type="identity">Identity</button>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"
></script>
</body>
</html>