X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/63d62722825b9ba77f75db531363d29f9dcc6c68..refs/pull/3918/head:/resources/js/markdown/display.js diff --git a/resources/js/markdown/display.js b/resources/js/markdown/display.js index 742198b46..2c78da189 100644 --- a/resources/js/markdown/display.js +++ b/resources/js/markdown/display.js @@ -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() { @@ -26,7 +34,7 @@ export class Display { this.doc.body.className = 'page-content'; // Prevent markdown display link click redirect - this.doc.addEventListener('click', this.onDisplayClick) + this.doc.addEventListener('click', this.onDisplayClick.bind(this)); } /** @@ -91,8 +99,8 @@ export class Display { * @param {Number} index */ scrollToIndex(index) { - const elems = this.doc.body.children; - if (elems.length <= index) return; + 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'});