]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/common-events.js
Mail: updated peer verify option name and added test
[bookstack] / resources / js / wysiwyg / common-events.js
1 /**
2  * @param {Editor} editor
3  */
4 export function listen(editor) {
5
6     // Replace editor content
7     window.$events.listen('editor::replace', ({html}) => {
8         editor.setContent(html);
9     });
10
11     // Append editor content
12     window.$events.listen('editor::append', ({html}) => {
13         const content = editor.getContent() + html;
14         editor.setContent(content);
15     });
16
17     // Prepend editor content
18     window.$events.listen('editor::prepend', ({html}) => {
19         const content = html + editor.getContent();
20         editor.setContent(content);
21     });
22
23     // Insert editor content at the current location
24     window.$events.listen('editor::insert', ({html}) => {
25         editor.insertContent(html);
26     });
27
28     // Focus on the editor
29     window.$events.listen('editor::focus', () => {
30         if (editor.initialized) {
31             editor.focus();
32         }
33     });
34 }