-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathmonaco-with-sibling.php
More file actions
40 lines (40 loc) · 1.71 KB
/
monaco-with-sibling.php
File metadata and controls
40 lines (40 loc) · 1.71 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
<?php $initial = isset($_GET['initial']) ? $_GET['initial'] : ''; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Monaco in iframe with sibling input</title>
</head>
<body>
<h1>Monaco in iframe with sibling input</h1>
<form id="outer-form" method="post" action="/richtext_submit">
<input id="outer-title" name="outer-title" placeholder="Title" type="search" autofocus>
<iframe id="monaco-frame" src="/form/richtext/monaco<?php echo $initial !== '' ? '?initial=' . urlencode($initial) : ''; ?>" style="width: 100%; height: 320px; border: 1px solid #ccc;"></iframe>
<input type="hidden" name="content" id="content-sync">
<button type="submit" id="submit">Submit</button>
</form>
<script>
window.__editorReady = false;
const frame = document.getElementById('monaco-frame');
frame.addEventListener('load', function () {
const poll = setInterval(function () {
try {
if (frame.contentWindow && frame.contentWindow.__editorReady) {
window.__editorReady = true;
clearInterval(poll);
}
} catch (e) {}
}, 100);
});
document.getElementById('outer-form').addEventListener('submit', function () {
try {
const getValue = frame.contentWindow && frame.contentWindow.__editorContent;
document.getElementById('content-sync').value = getValue ? getValue() : '';
} catch (e) {
document.getElementById('content-sync').value = '';
}
});
document.getElementById('outer-title').focus();
</script>
</body>
</html>