X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/421dd93ffd59bbe881df1f7fa86066f7f353b596..444a23a419539b9236a3cf04cf5c76c2d216c49e:/resources/assets/js/components/wysiwyg-editor.js diff --git a/resources/assets/js/components/wysiwyg-editor.js b/resources/assets/js/components/wysiwyg-editor.js index eb9f025a7..c03c0d2aa 100644 --- a/resources/assets/js/components/wysiwyg-editor.js +++ b/resources/assets/js/components/wysiwyg-editor.js @@ -378,6 +378,27 @@ function customHrPlugin() { } +function listenForBookStackEditorEvents(editor) { + + // Replace editor content + window.$events.listen('editor::replace', ({html}) => { + editor.setContent(html); + }); + + // Append editor content + window.$events.listen('editor::append', ({html}) => { + const content = editor.getContent() + html; + editor.setContent(content); + }); + + // Prepend editor content + window.$events.listen('editor::prepend', ({html}) => { + const content = html + editor.getContent(); + editor.setContent(content); + }); + +} + class WysiwygEditor { constructor(elem) { @@ -553,6 +574,10 @@ class WysiwygEditor { editor.focus(); } + listenForBookStackEditorEvents(editor); + + // TODO - Update to standardise across both editors + // Use events within listenForBookStackEditorEvents instead (Different event signature) window.$events.listen('editor-html-update', html => { editor.setContent(html); editor.selection.select(editor.getBody(), true); @@ -583,6 +608,18 @@ class WysiwygEditor { let dom = editor.dom, rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint(event.clientX, event.clientY, editor.getDoc()); + // Template insertion + const templateId = event.dataTransfer.getData('bookstack/template'); + if (templateId) { + event.preventDefault(); + window.$http.get(`/templates/${templateId}`).then(resp => { + editor.selection.setRng(rng); + editor.undoManager.transact(function () { + editor.execCommand('mceInsertContent', false, resp.data.html); + }); + }); + } + // Don't allow anything to be dropped in a captioned image. if (dom.getParent(rng.startContainer, '.mceTemp')) { event.preventDefault();