-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
134 lines (127 loc) · 3.04 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
<html>
<head>
<script src="codemirror.js"></script>
<link rel="stylesheet" href="codemirror.css">
<script src="codemirror_python.js"></script>
<script src="matchbrackets.js"></script>
<script src="closebrackets.js"></script>
<style>
body{
background-color: #ccc;
overflow: hidden;
}
.CodeMirror {
height: 100%;
width: 50%;
float:left
}
#repl{
float:left;
height:100%;
width:50%;
position: absolute;
right: 0;
box-sizing: border-box;
padding: 6px;
}
#repl::before {
content: '';
background-color: #ccc;
position: absolute;
left: 0;
width: 6px;
height: 100%;
cursor: ew-resize;
}
#msg{
background-color: black;
padding: 20px;
height: 80%;
color:white;
font-family: consolas,"courier new",monospace!important;
word-wrap: break-word;
}
Button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 4px 2px;
cursor: pointer;
}
@media only screen and (max-width: 600px) {
#repl{
width: 100%;
position: initial;
float: none;
}
.CodeMirror {
width: 100%;
height: 80%;
float: none;
}
body{
overflow: auto;
}
}
</style>
</head>
<body>
<div>
<textarea id="code" name="code"></textarea>
<div id="repl"><div style="text-align: center;"><button id="runButton">Run ></button></div><div id="msg"></div></div>
</div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "python",
version: 3,
singleLineStringErrors: false},
lineNumbers: true,
lineWrapping: true,
indentUnit: 4,
matchBrackets: true,
autoCloseBrackets: true,
});
// resizing the container with dragging
const BORDER_SIZE = 6;
const panel = document.getElementById("repl");
const code = document.querySelector(".CodeMirror");
let m_pos;
function resize(e){
const dx = m_pos - e.x;
m_pos = e.x;
panel.style.width = (parseInt(getComputedStyle(panel, '').width) + dx) + "px";
code.style.width = (parseInt(getComputedStyle(code, '').width) - dx) + "px";
}
panel.addEventListener("mousedown", function(e){
if (e.offsetX < BORDER_SIZE) {
m_pos = e.x;
document.addEventListener("mousemove", resize, false);
}
}, false);
document.addEventListener("mouseup", function(){
document.removeEventListener("mousemove", resize, false);
}, false);
//send to server
document.querySelector("#runButton").onclick = function(){
const repl_interface = document.getElementById("msg");
fetch('http://localhost:8080/run', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({python: editor.getValue()})
}).then(response => response.json()).then(function(data){
console.log(data["result"])
repl_interface.innerHTML = data["result"].replace(/\n/g, "<br>");;
});
}
</script>
</body>
</html>