-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
embed.html
119 lines (113 loc) · 2.91 KB
/
embed.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Embed Test</title>
<style media="screen">
body {
margin: 0;
padding: 30px;
font-family: sans-serif;
}
.row {
width: 100%;
display: flex;
justify-content: space-between;
align-items: stretch;
}
body > .row {
flex-grow: 1;
min-width: 200px;
flex-wrap: wrap;
margin-top: 1em;
}
body > .row > * {
flex-grow: 1;
min-width: 200px;
}
.row input,
.row textarea {
width: 100% !important;
margin-bottom: 1em;
}
#sendMessage,
#clearOutput {
position: sticky;
top: 1em;
}
#output {
font-family: monospace;
white-space: pre-wrap;
}
</style>
</head>
<body>
<iframe
id="ninja"
src="http://localhost:8080/&showControls=false&showPlayButton=false&showPTN=true&showText=true&showBoardPrefsBtn=true"
width="100%"
height="600px"
style="width: 100%; height: 600px; max-height: 100vh"
frameborder="0"
allowfullscreen
></iframe>
<div class="row">
<fieldset>
<legend>Send Message</legend>
<form id="sendMessage" method="post">
<input name="action" placeholder="Action" />
<textarea name="value" placeholder="Value"></textarea>
<div class="row">
<input type="reset" value="Clear" />
<input type="submit" value="Send" />
</div>
</form>
</fieldset>
<fieldset>
<legend>Received Messages</legend>
<input
id="clearOutput"
type="button"
value="Clear"
onclick="output.value = ''"
/>
<output id="output"></output>
</fieldset>
</div>
<script type="text/javascript">
const form = document.getElementById("sendMessage");
window.addEventListener(
"message",
(event) => {
document.getElementById("output").value +=
JSON.stringify(event.data, null, 2) + "\n";
},
false
);
form.addEventListener(
"submit",
(event) => {
event.preventDefault();
const ninja = document.getElementById("ninja");
const data = new FormData(event.target);
const action = data.get("action");
const valueString = data.get("value");
let value;
try {
value = JSON.parse(valueString);
} catch (error) {
value = valueString;
}
try {
ninja.contentWindow.postMessage({ action, value }, "*");
} catch (error) {
console.error(error);
}
return false;
},
true
);
</script>
</body>
</html>