-
-
Notifications
You must be signed in to change notification settings - Fork 652
/
editor.html
99 lines (92 loc) · 2.9 KB
/
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0" />
<title></title>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/pell/dist/pell.min.css">
<style>
body {
margin: 0;
padding: 0;
}
main {
height: 100vh;
display: flex;
flex-direction: column;
}
.pell-content {
flex: auto;
}
</style>
</head>
<body>
<main></main>
<script src="https://unpkg.com/pell"></script>
<script>
var sendMessage = function(action, value) {
window.parent.postMessage({
action: action,
value: value
}, '*');
};
window.addEventListener("message", function(e) {
if (e.data && e.data.action) {
switch (e.data.action) {
case "setContent":
window.editor.content.innerHTML = e.data.value;
break;
case "getContent":
sendMessage('setContent', window.editor.content.innerHTML);
break;
}
}
}, false);
window.editor = window.pell.init({
element: document.querySelector("main"),
onChange(html) {
sendMessage("setContent", html);
},
defaultParagraphSeparator: 'div',
styleWithCSS: false,
actions: [
'bold',
'italic',
'underline',
'strikethrough',
'heading1',
'heading2',
'paragraph',
'quote',
'olist',
'ulist',
'code',
'line',
{
name: 'link',
result: function() {
const url = window.prompt('Enter the link URL');
if (url) {
window.pell.exec('createLink', url);
}
}
},
{
name: 'close',
icon: 'Close',
title: 'Close Notes',
result: function() {
sendMessage('closeEditor', true);
}
}
],
classes: {
actionbar: 'pell-actionbar',
button: 'pell-button',
content: 'pell-content',
selected: 'pell-button-selected'
}
})
</script>
</body>
</html>