diff --git a/app/static/scripts/editor.js b/app/static/scripts/editor.js index 793656a..5074f3c 100644 --- a/app/static/scripts/editor.js +++ b/app/static/scripts/editor.js @@ -23,7 +23,7 @@ function editor_event_source(event) } if(!button || !editor) return; - const ta = editor.querySelector("textarea"); + const ta = editor.querySelector(".editor textarea"); return [editor, button, ta]; } @@ -283,6 +283,36 @@ function editor_separator(event) { editor_insert_around(event, "", "\n---\n"); } +function editor_display_emoji_modal(event) { + event.currentTarget.children[1].style = {'display': 'block'}; +} + +/* This request the server to get a complete render of the current text in the textarea */ +function preview() { + const previewArea = document.querySelector("#editor_content_preview"); + + const textarea = document.querySelector(".editor textarea"); + const payload = {text: ta.value}; + + const headers = new Headers(); + headers.append("Content-Type", "application/json"); + + const params = { + method: "POST", + body: JSON.stringify(payload), + headers + }; + + fetch("/api/markdown", params).then( + (response) => { + response.text().then( + (text) => { + previewArea.innerHTML = text; + } + ); + }); +} + previewTimeout = null; ta = document.querySelector(".editor textarea"); @@ -325,29 +355,9 @@ ta.addEventListener('keydown', function(e) { previewTimeout = setTimeout(preview, 3000); }); +document.querySelector('emoji-picker').addEventListener('emoji-click', event => { + editor_clear_modals(event); + editor_insert_around(event, "", event.detail.unicode) -function preview() { - const previewArea = document.querySelector("#editor_content_preview"); - - const textarea = document.querySelector(".editor textarea"); - const payload = {text: ta.value}; - - const headers = new Headers(); - headers.append("Content-Type", "application/json"); - - const params = { - method: "POST", - body: JSON.stringify(payload), - headers - }; - - fetch("/api/markdown", params).then( - (response) => { - response.text().then( - (text) => { - previewArea.innerHTML = text; - } - ); - }); -} - + preview(); +}); diff --git a/app/templates/base/scripts.html b/app/templates/base/scripts.html index 4405157..0f08ce6 100644 --- a/app/templates/base/scripts.html +++ b/app/templates/base/scripts.html @@ -1,3 +1,4 @@ {% for s in scripts %} {% endfor %} + diff --git a/app/templates/widgets/editor.html b/app/templates/widgets/editor.html index 0b76a0c..400af6d 100644 --- a/app/templates/widgets/editor.html +++ b/app/templates/widgets/editor.html @@ -80,8 +80,7 @@ - - + - + - --> + + +