forked from ashimjk/ckeditor-plain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert-image.js
38 lines (30 loc) · 1.19 KB
/
insert-image.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
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from "@ckeditor/ckeditor5-ui/src/button/buttonview";
import image from "@ckeditor/ckeditor5-image/src/image";
export class InsertImage extends Plugin {
init() {
console.log('InsertImage was initialized');
const editor = this.editor;
editor.ui.componentFactory.add('insertImage', locale => {
const view = new ButtonView(locale);
view.set({
label: 'Insert Image',
// icon: imageIcon,
tooltip: true,
withText: true
});
// Callback executed once the image is clicked
view.on('execute', () => {
const imageURL = prompt('Image URL');
editor.model.change(writer => {
const imageElement = writer.createElement('image', {
src: imageURL
});
// Insert the image in the current selection location.
editor.model.insertContent(imageElement, editor.model.document.selection);
});
});
return view;
});
}
}