-
Notifications
You must be signed in to change notification settings - Fork 4
/
complex-editor.html
127 lines (103 loc) · 4.78 KB
/
complex-editor.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Complex Editor Demo</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
</head>
<body>
<nav class=" navbar navbar-expand-lg navbar-dark" style="background-color: #3498db;">
<div class="container-fluid">
<a class="navbar-brand" href="index.html">OneCompiler Embedding Demos</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.html">Simple Editor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="complex-editor.html">Complex Editor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="lab.html">Lab</a>
</li>
<li class="nav-item">
<a class="nav-link" href="challenges.html">Challenges</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<br /><br />
<iframe frameBorder="0" height="400px" id="oc-editor" width="100%"
src="https://onecompiler.com/embed/python?codeChangeEvent=true&listenToEvents=true&hideNew=true"></iframe>
<br />
<p>automatically catching content on parent's website </p>
<div class="input-group">
<span class="input-group-text">code</span>
<textarea class="form-control" rows="10" aria-label="With textarea" id="parent-code-capture"></textarea>
</div>
<br />
<button type="button" onclick="javascript:triggerRun()" class="btn btn-primary">Trigger Run</button>
<button type="button" onclick="javascript:sendCodeToEditor()" class="btn btn-warning">
Send Code to Editor</button>
</div>
<script>
window.onmessage = function (e) {
if (e.data && e.data.language) {
console.log(e.data)
document.getElementById('parent-code-capture').value = JSON.stringify(e.data, null, 2);
}
};
function triggerRun() {
var iFrame = document.getElementById('oc-editor');
iFrame.contentWindow.postMessage({
eventType: 'triggerRun'
}, "*");
}
function sendCodeToEditor() {
let currentCode = document.getElementById('parent-code-capture').value;
if (!currentCode) {
alert('No code to send');
return;
}
let currentCodeObj = JSON.parse(currentCode);
if (!currentCodeObj.language) {
alert('Language missing');
return;
}
if (!currentCodeObj.files || currentCodeObj.files.length === 0) {
alert('Files missing');
return;
}
var iFrame = document.getElementById('oc-editor');
iFrame.contentWindow.postMessage({
eventType: 'populateCode',
language: currentCodeObj.language,
files: currentCodeObj.files,
stdin: currentCodeObj.stdin,
result: currentCodeObj.result
}, "*");
}
</script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Xe+8cL9oJa6tN/veChSP7q+mnSPaj5Bcu9mPX5F5xIGE0DVittaqT5lorf0EI7Vk"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-ODmDIVzN+pFdexxHEHFBQH3/9/vQ9uori45z4JjnFsRydbmQbmL5t1tQ0culUzyK"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa"
crossorigin="anonymous"></script>
</body>
</html>