Skip to content

Commit 817f0e7

Browse files
authored
chore: add update button to embed demo (#281)
1 parent 6e0bca1 commit 817f0e7

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

src/embed.html

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@
99
body {
1010
background: #ccc;
1111
}
12+
13+
#interactive-embed {
14+
position: relative;
15+
}
16+
17+
button#update-interactive-embed {
18+
position: absolute;
19+
top: 25px;
20+
right: 25px;
21+
}
1222
</style>
1323
<body>
1424
<!--
15-
This is a test file to test the embed mode,
16-
to try this run `npm run start`, and after that run
17-
`npm run start:embed` in a second terminal
25+
This is a test file to test the embed mode,
26+
to try this run `npm run start`, and after that run
27+
`npm run start:embed` in a second terminal
1828
19-
-->
29+
-->
2030

2131
<div
2232
data-testing-playground
@@ -55,23 +65,28 @@
5565
</script>
5666
</template>
5767

58-
<template data-testing-playground data-class="messaging-iframe"></template>
59-
<script type="text/javascript">
60-
function updatePlayground() {
61-
const iframe = document.querySelector('.messaging-iframe');
62-
iframe.contentWindow.postMessage(
63-
{ type: 'UPDATE_DATA', markup: 'new markup', query: 'new query' },
64-
'http://localhost:1234',
65-
);
66-
}
68+
<div id="interactive-embed">
69+
<template data-testing-playground data-class="messaging-iframe"></template>
70+
<button id="update-interactive-embed">update-content</button>
6771

68-
window.addEventListener('message', ({ data }) => {
69-
if (data.source === 'embedded-testing-playground' && data.type === 'READY') {
70-
updatePlayground();
72+
<script type="text/javascript">
73+
function updatePlayground() {
74+
const iframe = document.querySelector('.messaging-iframe');
75+
iframe.contentWindow.postMessage(
76+
{ type: 'UPDATE_DATA', markup: `<div>${Date.now()}</div>`, query: `// ${Date.now()}` },
77+
'http://localhost:1234',
78+
);
7179
}
72-
});
73-
</script>
7480

81+
document.getElementById('update-interactive-embed').addEventListener('click', updatePlayground);
82+
83+
window.addEventListener('message', ({ data }) => {
84+
if (data.source === 'embedded-testing-playground' && data.type === 'READY') {
85+
updatePlayground();
86+
}
87+
});
88+
</script>
89+
</div>
7590
<script async src="embed.js"></script>
7691
</body>
7792
</html>

0 commit comments

Comments
 (0)