-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
136 lines (118 loc) · 3.92 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
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
<html>
<meta charset="utf-8">
<head>
<style>
#editor
{
margin-top: 0;
margin-bottom: 0;
width: 100%;
height: 95%;
}
#render
{
border: 0;
width: 100%;
height: 100%;
}
div
{
/*
border-style: dashed;
border-color: grey;
*/
}
#container
{
text-align: center;
}
#center
{
width: 1360px;
display: inline-block;
}
#left
{
float: left;
width: 540px;
}
#right
{
float: right;
width: 800px;
}
#run
{
padding-top: 10px;
padding-bottom: 10px;
margin-bottom: 10px;
border-color: grey;
border-style: solid;
border-width: 1px;
}
</style>
</head>
<script type="text/javascript" src="ace.js"></script>
<body>
<!--
Topic: How do you easily horizontally center a <div> using CSS?
Source: https://stackoverflow.com/a/10797328
-->
<div id="container">
<div id="center">
<div id="left">
<center>
<div id="run">
<button onclick="run()">Run</button>
</div>
</center>
<pre id="editor"></pre>
</div>
<div id="right">
<iframe id="render" src="render.html">
<p>ERROR Your browser does not support iframes</p>
</iframe>
</div>
</div>
</div>
<script type="text/javascript">
const query = window.location.search.substring(1);
const pairs = query.split("&");
var arguments = {};
for (var i = 0; i < pairs.length; ++i)
{
var pair = pairs[i].split("=");
arguments[pair[0]] = pair[1];
}
// Initialize ACE editor and set its language to Lua.
var editor = ace.edit("editor");
editor.session.setMode("ace/mode/lua");
function run()
{
var iframe = document.getElementById("render");
const script = btoa(editor.session.getValue());
iframe.src = "render.html?base64script=" + script;
// Update `base64script` argument value each time `Run` is hit.
// NOTE Using URLSearchParams' toString() function doesn't work
// NOTE because toString() converts valid Base64 `=` to invalid `%3D`
// NOTE So, this is not applicable: https://stackoverflow.com/a/41542008
var path = window.location.pathname + "?base64script=" + script
history.pushState(null, "", path);
}
// Run provided code at the start.
if ("base64code" in arguments)
{
const code = atob(arguments["base64code"]);
editor.session.setValue(code);
run();
}
// Run provided script at the start.
if ("base64script" in arguments)
{
const code = atob(arguments["base64script"]);
editor.session.setValue(code);
run();
}
</script>
</body>
</html>