X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a83a7f34f4d4c85bfb208eb1abfdd77743856680..refs/pull/2022/head:/resources/js/components/markdown-editor.js diff --git a/resources/js/components/markdown-editor.js b/resources/js/components/markdown-editor.js index 331cf2f01..4dc240d48 100644 --- a/resources/js/components/markdown-editor.js +++ b/resources/js/components/markdown-editor.js @@ -76,6 +76,7 @@ class MarkdownEditor { return; } if (action === 'insertDrawing') this.actionStartDrawing(); + if (action === 'fullscreen') this.actionFullScreen(); }); // Mobile section toggling @@ -126,7 +127,13 @@ class MarkdownEditor { loadStylesIntoDisplay() { if (this.displayStylesLoaded) return; - this.displayDoc.documentElement.className = 'markdown-editor-display'; + this.displayDoc.documentElement.classList.add('markdown-editor-display'); + // Set display to be dark mode if parent is + + if (document.documentElement.classList.contains('dark-mode')) { + this.displayDoc.documentElement.style.backgroundColor = '#222'; + this.displayDoc.documentElement.classList.add('dark-mode'); + } this.displayDoc.head.innerHTML = ''; const styles = document.head.querySelectorAll('style,link[rel=stylesheet]'); @@ -410,17 +417,23 @@ class MarkdownEditor { }); } + getDrawioUrl() { + const drawioUrlElem = document.querySelector('[drawio-url]'); + return drawioUrlElem ? drawioUrlElem.getAttribute('drawio-url') : false; + } + // Show draw.io if enabled and handle save. actionStartDrawing() { - if (document.querySelector('[drawio-enabled]').getAttribute('drawio-enabled') !== 'true') return; - let cursorPos = this.cm.getCursor('from'); + const url = this.getDrawioUrl(); + if (!url) return; + + const cursorPos = this.cm.getCursor('from'); - DrawIO.show(() => { + DrawIO.show(url,() => { return Promise.resolve(''); }, (pngData) => { - // let id = "image-" + Math.random().toString(16).slice(2); - // let loadingImage = window.baseUrl('/loading.gif'); - let data = { + + const data = { image: pngData, uploaded_to: Number(document.getElementById('page-editor').getAttribute('page-id')) }; @@ -444,15 +457,15 @@ class MarkdownEditor { // Show draw.io if enabled and handle save. actionEditDrawing(imgContainer) { - const drawingDisabled = document.querySelector('[drawio-enabled]').getAttribute('drawio-enabled') !== 'true'; - if (drawingDisabled) { + const drawioUrl = this.getDrawioUrl(); + if (!drawioUrl) { return; } const cursorPos = this.cm.getCursor('from'); const drawingId = imgContainer.getAttribute('drawio-diagram'); - DrawIO.show(() => { + DrawIO.show(drawioUrl, () => { return DrawIO.load(drawingId); }, (pngData) => { @@ -480,6 +493,13 @@ class MarkdownEditor { }); } + // Make the editor full screen + actionFullScreen() { + const alreadyFullscreen = this.elem.classList.contains('fullscreen'); + this.elem.classList.toggle('fullscreen', !alreadyFullscreen); + document.body.classList.toggle('markdown-fullscreen', !alreadyFullscreen); + } + // Scroll to a specified text scrollToText(searchText) { if (!searchText) {