From a77719847b678e029969534eb0526b1ffe645a7d Mon Sep 17 00:00:00 2001 From: soufiane Date: Tue, 12 Aug 2025 17:47:04 +0200 Subject: [PATCH] wait #7691 @2:00 --- resources/markdowneditor/js/markdowneditor.js | 48 +++++++++++++------ resources/markdowneditor/style/style.sass | 24 ++++++++++ 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/resources/markdowneditor/js/markdowneditor.js b/resources/markdowneditor/js/markdowneditor.js index 455e2b144..f181745fc 100644 --- a/resources/markdowneditor/js/markdowneditor.js +++ b/resources/markdowneditor/js/markdowneditor.js @@ -51,6 +51,8 @@ function MarkdownEditor() { this.currentPage = Math.max(1,parseInt(window.location.hash.substring(1))) || 1; this.editor = null; this.contentMarkdown = null; + this.theme = false; + this.options = {}; this.init() } @@ -62,6 +64,22 @@ MarkdownEditor.prototype = { this.versions = new MarkdowneditorVersions(this); this.zoom = new MarkdowneditorZoom(this); + this.options = { + el: document.querySelector('#editor'), + initialEditType: 'wysiwyg', + previewStyle: 'vertical', + theme: this.theme, + cursorToEnd: false, + autofocus: false, + toolbarItems: [ + ['heading', 'bold', 'italic'], + ['hr', 'quote'], + ['ul'], + ['table', 'image', 'link'], + ['scrollSync'], + ] + } + this.open = false this.savedScroll = null; @@ -86,6 +104,20 @@ MarkdownEditor.prototype = { } }, true); + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + $this.editor.destroy() + $this.editor = new Editor({ ...$this.options, theme: 'dark' }) + $this.changePage($this.currentPage) + } + + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { + const newColorScheme = event.matches ? "dark" : "light"; + $this.save.save() + $this.editor.destroy() + $this.editor = new Editor({ ...$this.options, theme: newColorScheme }) + $this.changePage($this.currentPage) + }); + $(window).on('hashchange', function () { /*if ($this.maskHashEvent) { return; @@ -220,21 +252,7 @@ MarkdownEditor.prototype = { }, markdown: function() { - this.editor = new Editor({ - el: document.querySelector('#editor'), - initialEditType: 'wysiwyg', - previewStyle: 'vertical', - theme: 'dark', - cursorToEnd: false, - autofocus: false, - toolbarItems: [ - ['heading', 'bold', 'italic'], - ['hr', 'quote'], - ['ul'], - ['table', 'image', 'link'], - ['scrollSync'], - ] - }); + this.editor = new Editor(this.options); this.editor.getMarkdown(); }, diff --git a/resources/markdowneditor/style/style.sass b/resources/markdowneditor/style/style.sass index 86acabb3c..975ebae57 100644 --- a/resources/markdowneditor/style/style.sass +++ b/resources/markdowneditor/style/style.sass @@ -306,3 +306,27 @@ input::-webkit-inner-spin-button .ProseMirror, .toastui-editor-md-preview @include tinyscrollbars + +.toastui-editor-dark + .toastui-editor-defaultUI-toolbar + .scroll-sync.active::before + color: #bbb !important + input:checked + .switch::before + background-color: #bbb !important + .toastui-editor-defaultUI-toolbar, + .toastui-editor-md-container, + .toastui-editor-ww-container + @include dark-theme + background-color: #222 !important + + .toastui-editor-mode-switch + @include dark-theme + background-color: #444 !important + .tab-item + @include dark-theme + background-color: transparent !important + color: #bbb !important + &.active + @include dark-theme + background-color: #222 !important + border-top-color: #222 !important -- 2.39.5