diff --git a/Models/Editor.js b/Models/Editor.js index 75c5ba0..89988ee 100644 --- a/Models/Editor.js +++ b/Models/Editor.js @@ -1,16 +1,18 @@ +import { Markdown } from '../../../jsOMS/Utils/Parser/Markdown.js'; + export class Editor { constructor (id) { - this.id = id; - this.editor = document.getElementById(id); + this.id = id; + this.editor = document.getElementById(id); + this.markdown = new Markdown.Converter({extensions: [], sanitize: true}); }; bind () { const editorButtons = document.querySelectorAll('#' + this.id + '-tools .editor-button'), - editorTitle = this.editor.getElementsByClassName('editor-title')[0], - editorContent = this.editor.getElementsByClassName('editor-content')[0], - editorPreview = this.editor.getElementsByClassName('editor-preview')[0], + editorContent = this.editor.getElementsByTagName('textarea')[0], + editorPreview = this.editor.getElementsByTagName('article')[0], length = editorButtons.length, self = this; @@ -20,6 +22,10 @@ export class Editor { self.toolsButton(this, event); }); } + + editorContent.addEventListener('change', function() { + editorPreview.innerHTML = self.markdown.makeHtml(editorContent.value); + }) }; toolsButton (e, event) diff --git a/Theme/Backend/Components/Editor/BaseView.php b/Theme/Backend/Components/Editor/BaseView.php index c2a1f1a..e235003 100644 --- a/Theme/Backend/Components/Editor/BaseView.php +++ b/Theme/Backend/Components/Editor/BaseView.php @@ -47,9 +47,9 @@ class BaseView extends View $this->addData('text', $view); } - public function getId() : string + public function renderId() : string { - return $this->id; + return $this->printHtml($this->id); } /** diff --git a/Theme/Backend/Components/Editor/TextView.php b/Theme/Backend/Components/Editor/TextView.php index 225a70b..8930a6c 100644 --- a/Theme/Backend/Components/Editor/TextView.php +++ b/Theme/Backend/Components/Editor/TextView.php @@ -47,39 +47,39 @@ class TextView extends View $this->setTemplate('/Modules/Editor/Theme/Backend/Components/Editor/inline-editor'); } - public function getId() : string + public function renderId() : string { - return $this->id; + return $this->printHtml($this->id); } - public function getName() : string + public function renderName() : string { - return $this->name; + return $this->printHtml($this->name); } - public function getForm() : string + public function renderForm() : string { - return $this->form; + return $this->printHtml($this->form); } - public function getPreview() : string + public function renderPreview() : string { return $this->preview; } - public function getPlain() : string + public function renderPlain() : string { - return $this->plain; + return $this->printHtml($this->plain); } - public function getTplText() : string + public function renderTplText() : string { - return $this->tplText; + return $this->printHtml($this->tplText); } - public function getTplValue() : string + public function renderTplValue() : string { - return $this->tplValue; + return $this->printHtml($this->tplValue); } /** diff --git a/Theme/Backend/Components/Editor/inline-editor-tools.tpl.php b/Theme/Backend/Components/Editor/inline-editor-tools.tpl.php index b05e880..5d6a319 100644 --- a/Theme/Backend/Components/Editor/inline-editor-tools.tpl.php +++ b/Theme/Backend/Components/Editor/inline-editor-tools.tpl.php @@ -1,5 +1,5 @@ -