X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/921131f99949960f448b2cfbb0ad78edc8d4f24a..refs/pull/3247/head:/resources/js/wysiwyg/plugin-codeeditor.js diff --git a/resources/js/wysiwyg/plugin-codeeditor.js b/resources/js/wysiwyg/plugin-codeeditor.js index 97bfebf9a..f0ec78afc 100644 --- a/resources/js/wysiwyg/plugin-codeeditor.js +++ b/resources/js/wysiwyg/plugin-codeeditor.js @@ -1,5 +1,3 @@ -import Code from "../services/code"; - function elemIsCodeBlock(elem) { return elem.className === 'CodeMirrorContainer'; } @@ -31,8 +29,10 @@ function showPopup(editor) { const editorElem = selectedNode.querySelector('.CodeMirror'); const cmInstance = editorElem.CodeMirror; if (cmInstance) { - Code.setContent(cmInstance, code); - Code.setMode(cmInstance, lang, code); + window.importVersioned('code').then(Code => { + Code.setContent(cmInstance, code); + Code.setMode(cmInstance, lang, code); + }); } const textArea = selectedNode.querySelector('textarea'); if (textArea) textArea.textContent = code; @@ -69,7 +69,7 @@ function register(editor, url) { editor.ui.registry.addIcon('codeblock', '') editor.ui.registry.addButton('codeeditor', { - title: 'Insert code block', + tooltip: 'Insert code block', icon: 'codeblock', onAction() { editor.execCommand('codeeditor'); @@ -93,7 +93,7 @@ function register(editor, url) { showPopup(editor); }); - function parseCodeMirrorInstances() { + function parseCodeMirrorInstances(Code) { // Recover broken codemirror instances $('.CodeMirrorContainer').filter((index ,elem) => { @@ -111,17 +111,18 @@ function register(editor, url) { }); } - editor.on('init', function() { + editor.on('init', async function() { + const Code = await window.importVersioned('code'); // Parse code mirror instances on init, but delay a little so this runs after // initial styles are fetched into the editor. editor.undoManager.transact(function () { - parseCodeMirrorInstances(); + parseCodeMirrorInstances(Code); }); // Parsed code mirror blocks when content is set but wait before setting this handler // to avoid any init 'SetContent' events. setTimeout(() => { editor.on('SetContent', () => { - setTimeout(parseCodeMirrorInstances, 100); + setTimeout(() => parseCodeMirrorInstances(Code), 100); }); }, 200); });