Skip to content

Commit 9564f38

Browse files
authored
refactor: use seamless instead of caja
1 parent 90d610d commit 9564f38

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

index.html

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>BinaryNumberContentEditor</title>
6-
<script type="application/javascript">
7-
function init() {
8-
window.data = getData();
9-
setDataGetter(dataGetter)
10-
}
11-
</script>
6+
<!-- Since GitHub Raw files use text/plain as MIME type the script cannot be executed when linking directly, instead routed over jsdelivr-->
7+
<script src='https://cdn.jsdelivr.net/gh/MicroContent/BinaryNumberContentEditor/seamless.child.min.js'></script>
128
</head>
139
<body>
10+
<script type="text/javascript">
11+
12+
// Connect to the parent page.
13+
var parent = window.seamless.connect({
14+
url: window.location.url,
15+
allowStyleInjection: true,
16+
});
17+
18+
19+
</script>
1420
<div>
1521
<label for="numberInput">Enter Number between 0 and 255:</label>
1622
<input id="numberInput" type="number"/>
1723
</div>
24+
<button onclick="sendToParent(event)">
25+
Send to toolkit
26+
</button>
1827
<script type="application/javascript">
28+
1929
function dataGetter() {
2030
var val = parseInt(document.getElementById('numberInput').value);
2131
if (val < 0) {
@@ -27,18 +37,24 @@
2737
document.getElementById('numberInput').value = val;
2838
return {
2939
// return data object
40+
type: 'toViewer',
3041
number: val,
3142
// preview metadata
3243
title: "Binary Representation of " + val,
3344
description: "Click on the switches to set the correct binary representation of " + val,
3445
imageUrl: "https://raw.githubusercontent.com/MicroContent/BinaryNumberContentViewer/8306856c7abc9999ea07316f79e78c0d2b6468a4/example.png"
3546
}
3647
}
48+
// Send a message
49+
window.sendToParent = function(event) {
50+
event.preventDefault();
51+
var result = dataGetter()
52+
parent.send(result);
53+
};
3754

38-
init();
3955
if (typeof window.data !== 'undefined' && typeof window.data.number == 'number') {
4056
document.getElementById('numberInput').value = window.data.number;
4157
}
4258
</script>
4359
</body>
44-
</html>
60+
</html>

0 commit comments

Comments
 (0)