-
-
Notifications
You must be signed in to change notification settings - Fork 751
Expand file tree
/
Copy pathsummernote.php
More file actions
38 lines (38 loc) · 1.7 KB
/
summernote.php
File metadata and controls
38 lines (38 loc) · 1.7 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
<?php $initial = isset($_GET['initial']) ? $_GET['initial'] : ''; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Summernote</title>
<link href="https://cdn.jsdelivr.net/npm/summernote@0.9.0/dist/summernote-lite.min.css" rel="stylesheet">
</head>
<body>
<h1>Summernote</h1>
<form id="richtext-form" method="post" action="/richtext_submit">
<div id="editor">
<div id="editor-inner"></div>
</div>
<input type="hidden" name="content" id="content-sync">
<button type="submit" id="submit">Submit</button>
</form>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/summernote@0.9.0/dist/summernote-lite.min.js"></script>
<script>
$(document).ready(function() {
$('#editor-inner').summernote({ height: 150 });
const initial = <?php echo json_encode($initial, JSON_UNESCAPED_UNICODE); ?>;
if (initial) $('#editor-inner').summernote('code', initial.split(/\n{2,}/).map(p => '<p>' + p.replace(/</g, '<') + '</p>').join(''));
window.__editor = $('#editor-inner');
window.__editorContent = () => {
const div = document.createElement('div');
div.innerHTML = $('#editor-inner').summernote('code') || '';
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>