-
Notifications
You must be signed in to change notification settings - Fork 1
/
tinymce-plugin-base64insert.js
74 lines (65 loc) · 2.08 KB
/
tinymce-plugin-base64insert.js
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
/**
* Tinymce-v5-base64-image-insert
*
* @author Matěj Půhoný
* @link https://puhony.eu/
*
*/
tinymce.PluginManager.add("base64_image_insert", function(editor, f) {
function _onAction() {
_dialog = editor.windowManager.open({
title: 'Insert Image',
onSubmit: function (api) {
if (api.getData().dropzone[0].size > 1024 * 1024) {
alert("Your image have more then 1MB, consider using this image. (It's too big)");
}
const classFilereader = new FileReader();
classFilereader.onload = function(base64) {
const imgData = base64.target.result;
const img = new Image();
img.src = imgData;
editor.insertContent("<img src='" + imgData + "' height='200px'/>");
api.close()
};
classFilereader.onerror = function(err) {
alert("Error reading file - " + err.getMessage());
};
classFilereader.readAsDataURL(api.getData().dropzone[0]);
},
body: {
type: 'panel',
items: [
{
type: 'dropzone',
name: 'dropzone',
label: 'Dropzone',
}
]
},
buttons: [
{
text: 'Close',
type: 'cancel',
onclick: 'close'
},
{
text: 'Insert',
type: 'submit',
primary: true,
}
]
});
}
editor.ui.registry.addButton("base64_image_insert", {
text: '',
tooltip: 'Insert embedded image',
onAction: _onAction,
icon: 'image',
});
editor.ui.registry.addMenuItem("base64_image_insert", {
text: '',
context: 'insert',
icon: 'image',
onAction: _onAction
});
});