-
Notifications
You must be signed in to change notification settings - Fork 406
/
Demo.html
167 lines (161 loc) · 5.22 KB
/
Demo.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="UTF-8">
<title>Squire Editor Demo</title>
<style type="text/css" media="screen">
body {
position: relative;
margin: 0 auto;
padding: 50px;
width: 540px;
font: 400 14px/1.24 helvetica, arial, sans-serif;
text-shadow: 0 1px 0 white;
}
h1 {
font-size: 1.95em;
}
span {
cursor: pointer;
text-decoration: underline;
}
p {
margin: 5px 0;
}
#editor {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
min-height: 200px;
border: 1px solid #888;
padding: 1em;
background: transparent;
color: #2b2b2b;
font: 13px/1.35 Helvetica, arial, sans-serif;
cursor: text;
}
a {
text-decoration: underline;
}
h2 {
font-size: 123.1%;
}
h3 {
font-size: 108%;
}
h1,h2,h3,p {
margin: 1em 0;
}
h4,h5,h6 {
margin: 0;
}
ul, ol {
margin: 0 1em;
padding: 0 1em;
}
blockquote {
border-left: 2px solid blue;
margin: 0;
padding: 0 10px;
}
pre {
white-space: pre-wrap;word-wrap: break-word;overflow-wrap: break-word;border-radius: 3px;border: 1px solid #ccc; padding: 7px 10px; background: #f6f6f6; font-family: menlo, consolas, monospace; font-size: 90%; }
code {
border-radius: 3px;
border: 1px solid #ccc;
padding: 1px 3px;
background: #f6f6f6;
font-family: menlo, consolas, monospace;
font-size: 90%;
}
</style>
</head>
<body>
<h1>Squire Editor Demo</h1>
<header>
<p>Squire is a rich text editor primarily built for email apps. It’s designed to be integrated with your own UI framework, and so does not provide its own UI toolbar, widgets or overlays. This is a really simple demo, with the most trivial of UI integrations, to show the raw component in action. <a href="https://github.com/fastmail/squire">Learn more and see the source on GitHub</a>.</p>
<p>
<span id="bold">Bold</span>
<span id="removeBold">Unbold</span>
<span id="italic">Italic</span>
<span id="removeItalic">Unitalic</span>
<span id="underline">Underline</span>
<span id="removeUnderline">Deunderline</span>
<span id="removeAllFormatting">Remove formatting</span>
<span id="setFontSize" class="prompt">Font size</span>
<span id="setFontFace" class="prompt">Font face</span>
</p>
<p>
<span id="setTextColor" class="prompt">Text color</span>
<span id="setHighlightColor" class="prompt">Text highlight</span>
<span id="makeLink" class="prompt">Link</span>
</p>
<p>
<span id="increaseQuoteLevel">Quote</span>
<span id="decreaseQuoteLevel">Dequote</span>
<span id="makeUnorderedList">List</span>
<span id="removeList">Unlist</span>
<span id="increaseListLevel">Increase list level</span>
<span id="decreaseListLevel">Decrease list level</span>
<span id="code">Code</span>
<span id="removeCode">Uncode</span>
<span id="insertImage" class="prompt">Insert image</span>
<span id="setHTML" class="prompt">Set HTML</span>
<span id="undo">Undo</span>
<span id="redo">Redo</span>
</p>
</header>
<div id="editor"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.4.3/purify.min.js" integrity="sha512-3dcbndbDLLWfKWevQu8C/1qVRcxx6h+eRDSnn3/pcBZHISRJgsj3u71U/Ad6nQVHrEi05hOSr6Hnb/p0pWc94w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript" src="dist/squire-raw.js"></script>
<script type="module" charset="utf-8">
var div = document.getElementById( 'editor' );
var editor = window.editor = new Squire( div, {
blockTag: 'div',
blockAttributes: {'class': 'paragraph'},
tagAttributes: {
ul: {'class': 'UL'},
ol: {'class': 'OL'},
li: {'class': 'listItem'},
a: {'target': '_blank'},
pre: {
style: 'border-radius:3px;border:1px solid #ccc;padding:7px 10px;background:#f6f6f6;font-family:menlo,consolas,monospace;font-size:90%;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:break-word;'
},
code: {
style: 'border-radius:3px;border:1px solid #ccc;padding:1px 3px;background:#f6f6f6;font-family:menlo,consolas,monospace;font-size:90%;'
},
}
});
editor.addEventListener('pasteImage', function(event) {
const items = [...event.detail.clipboardData.items];
const imageItems = items.filter((item) => /image/.test(item.type));
if (!imageItems.length) {
return false;
}
let reader = new FileReader();
reader.onload = (loadEvent) => {
this.insertImage(loadEvent.target.result);
}
reader.readAsDataURL(imageItems[0].getAsFile());
});
document.addEventListener( 'click', function ( e ) {
var id = e.target.id,
value;
if ( id && editor && editor[ id ] ) {
if ( e.target.className === 'prompt' ) {
value = prompt( 'Value:' );
}
editor[ id ]( value );
}
}, false );
</script>
</body>
</html>