X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8e4bb32b779747c3d62673e21588632cd265677f..refs/pull/5280/head:/resources/js/markdown/display.js diff --git a/resources/js/markdown/display.js b/resources/js/markdown/display.js index 7e1925431..60be26b5f 100644 --- a/resources/js/markdown/display.js +++ b/resources/js/markdown/display.js @@ -1,4 +1,4 @@ -import {patchDomFromHtmlString} from "../services/vdom"; +import {patchDomFromHtmlString} from '../services/vdom.ts'; export class Display { @@ -17,6 +17,14 @@ export class Display { } else { this.container.addEventListener('load', this.onLoad.bind(this)); } + + this.updateVisibility(editor.settings.get('showPreview')); + editor.settings.onChange('showPreview', show => this.updateVisibility(show)); + } + + updateVisibility(show) { + const wrap = this.container.closest('.markdown-editor-wrap'); + wrap.style.display = show ? null : 'none'; } onLoad() { @@ -73,7 +81,7 @@ export class Display { * @param {String} html */ patchWithHtml(html) { - const body = this.doc.body; + const {body} = this.doc; if (body.children.length === 0) { const wrap = document.createElement('div'); @@ -94,8 +102,8 @@ export class Display { const elems = this.doc.body?.children[0]?.children; if (elems && elems.length <= index) return; - const topElem = (index === -1) ? elems[elems.length-1] : elems[index]; - topElem.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth'}); + const topElem = (index === -1) ? elems[elems.length - 1] : elems[index]; + topElem.scrollIntoView({block: 'start', inline: 'nearest', behavior: 'smooth'}); } -} \ No newline at end of file +}