-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathcodemirror5-with-sibling.php
More file actions
33 lines (32 loc) · 1.48 KB
/
codemirror5-with-sibling.php
File metadata and controls
33 lines (32 loc) · 1.48 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
<?php $initial = isset($_GET['initial']) ? $_GET['initial'] : ''; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CodeMirror 5 with sibling input</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/lib/codemirror.css">
<style>.CodeMirror { border: 1px solid #ccc; height: 200px; }</style>
</head>
<body>
<h1>CodeMirror 5 with sibling input</h1>
<form id="richtext-form" method="post" action="/richtext_submit">
<input id="outer-title" name="outer-title" placeholder="Title" type="search" autofocus>
<div id="editor">
<textarea id="editor-inner"><?php echo htmlspecialchars($initial, ENT_QUOTES | ENT_HTML5, 'UTF-8'); ?></textarea>
</div>
<input type="hidden" name="content" id="content-sync">
<button type="submit" id="submit">Submit</button>
</form>
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/lib/codemirror.js"></script>
<script>
const editor = CodeMirror.fromTextArea(document.getElementById('editor-inner'), {});
window.__editor = editor;
window.__editorContent = () => editor.getValue();
window.__editorReady = true;
document.getElementById('richtext-form').addEventListener('submit', function() {
document.getElementById('content-sync').value = window.__editorContent ? window.__editorContent() : '';
});
document.getElementById('outer-title').focus();
</script>
</body>
</html>