-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathckeditor4.php
More file actions
34 lines (34 loc) · 1.32 KB
/
ckeditor4.php
File metadata and controls
34 lines (34 loc) · 1.32 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
<?php $initial = isset($_GET['initial']) ? $_GET['initial'] : ''; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CKEditor 4</title>
</head>
<body>
<h1>CKEditor 4</h1>
<form id="richtext-form" method="post" action="/richtext_submit">
<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.ckeditor.com/4.22.1/standard/ckeditor.js"></script>
<script>
CKEDITOR.replace('editor-inner');
CKEDITOR.on('instanceReady', function(e) {
window.__editor = e.editor;
window.__editorContent = () => {
const div = document.createElement('div');
div.innerHTML = e.editor.getData() || '';
return (div.textContent || '').replace(/\u00a0/g, ' ').trim();
};
window.__editorReady = true;
});
document.getElementById('richtext-form').addEventListener('submit', function() {
document.getElementById('content-sync').value = window.__editorContent ? window.__editorContent() : '';
});
</script>
</body>
</html>