forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost.html
More file actions
151 lines (132 loc) · 4.15 KB
/
host.html
File metadata and controls
151 lines (132 loc) · 4.15 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<html>
<head>
<style>
html, body {
height: 100%;
margin: 0;
}
iframe {
position:absolute;
left:20%;
top:0;
width:80%;
height:100%;
border: 0;
}
#toolbox {
position: absolute;
left:0;
right:80%;
height:100%;
width:20%;
}
</style>
<script>
'use strict';
function start() {
}
function toBlocks() {
sendMessage({
type: "pxteditor",
action: "switchblocks"
})
}
function toJavascript() {
sendMessage({
type: "pxteditor",
action: "switchjavascript"
})
}
function startSimulator() {
sendMessage({
type: "pxteditor",
action: "startsimulator"
})
}
function stopSimulator() {
sendMessage({
type: "pxteditor",
action: "stopsimulator"
})
}
function restartSimulator() {
sendMessage({
type: "pxteditor",
action: "restartsimulator"
})
}
function hideSimulator() {
sendMessage({
type: "pxteditor",
action: "hidesimulator"
})
}
function showSimulator() {
sendMessage({
type: "pxteditor",
action: "showsimulator"
})
}
function newProject() {
sendMessage({
type: "pxteditor",
action: "newProject"
})
}
function sendSimulatorCustom() {
var content = document.getElementById('simContent');
sendMessage({
type: "pxteditor",
action: "proxytosim",
noresponse: true,
content: content.value
})
}
function sendMessage(message) {
var workspace = document.getElementById('workspace');
workspace.contentWindow.postMessage(message, "*");
}
function handleMessage(ev) {
var msg = ev.data;
switch(msg.type) {
case "custom":
console.log("Received a custom message from host");
console.log(msg);
break;
default:
break;
}
}
window.addEventListener("message", handleMessage);
</script>
</head>
<body onload="start()">
<div id="toolbox">
<h1>MakeCode Host Test</h1>
<p>
<h3>Workspace Controls</h3>
<input type="button" value="Switch to Blocks" onclick="toBlocks()">
<input type="button" value="Switch to Javascript" onclick="toJavascript()">
<input type="button" value="New Project" onclick="newProject()">
<br>
<h3>Simulator Controls</h3>
<input type="button" value="Start Simulator" onclick="startSimulator()">
<input type="button" value="Restart Simulator" onclick="restartSimulator()">
<input type="button" value="Stop Simulator" onclick="stopSimulator()">
<br>
<input type="button" value="Hide Simulator" onclick="hideSimulator()">
<input type="button" value="Show Simulator" onclick="showSimulator()">
<br>
<textarea id="simContent" style="width: 90%; height: 12em"></textarea>
<br>
<input type="button" value="Send Custom Message" onclick="sendSimulatorCustom()">
</p>
</div>
<iframe id="workspace" src="http://localhost:3232/index.html?editorlayout=ide"/>
</body>
</html>