This repository has been archived by the owner on May 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
55 lines (49 loc) · 1.51 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
<html>
<head>
<link rel="stylesheet" href="static/yui-pure-min.css">
<link rel="stylesheet" href="static/robot.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body >
<div class="header">
<h1>Code.org robot </h1>
</div>
<div class="content-wrapper content">
<form class="pure-form pure-form-stacked" id="codeform">
<fieldset>
<legend>Copy-paste the code here:</legend>
<textarea id="code" cols="50" rows="20">moveForward(50);
turnLeft(90);
</textarea>
<button class="pure-button pure-button-primary">Run</button>
</fieldset>
</form>
</div>
<script type="text/javascript">
(function() {
var httpRequest;
document.getElementById('codeform').onsubmit = function(e) {
e.preventDefault();
sendCode();
};
function sendCode() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = alertContents;
httpRequest.open('POST', '/');
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var code = document.getElementById('code').value;
httpRequest.send('code=' + encodeURIComponent(code));
}
function alertContents() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
alert(httpRequest.responseText);
} else {
alert('There was a problem with the request.');
}
}
}
})();
</script>
</body>
</html>