From 98c6ea7c92095efb69f33335a6549403f630fccf Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 17 May 2021 11:59:32 +0200 Subject: [PATCH] fix tinymce loading when dom is updated --- assets/js/addons/editor.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/assets/js/addons/editor.js b/assets/js/addons/editor.js index f4573b2..5ccb2e7 100644 --- a/assets/js/addons/editor.js +++ b/assets/js/addons/editor.js @@ -1,16 +1,12 @@ -module.exports = function() { - if (typeof tinymce === 'undefined') { - return; - } - +const initEditor = function(element) { tinymce.init({ - selector: '*[data-tinymce]', + selector: element, base_url: '/vendor/tinymce/', cache_suffix: '?v=4.1.6', language: 'fr_FR', plugins: 'print preview importcss searchreplace visualblocks visualchars fullscreen template table charmap hr pagebreak nonbreaking toc insertdatetime advlist lists wordcount textpattern noneditable help charmap quickbars link', menubar: 'file edit view insert format tools table tc help', - toolbar: 'undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap | fullscreen preview | code', + toolbar: 'undo redo | bold italic underline strikethrough | link | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap | fullscreen preview | code', importcss_append: true, image_caption: true, quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable', @@ -20,4 +16,19 @@ module.exports = function() { tinycomments_mode: 'embedded', contextmenu: "link image imagetools table configurepermanentpen", }); +} + +module.exports = function() { + if (typeof tinymce === 'undefined') { + return; + } + + const doInitEditor = function() { + initEditor('*[data-tinymce]'); + } + const observer = new MutationObserver(doInitEditor); + const config = {attributes: false, childList: true, subtree: true}; + + doInitEditor(); + observer.observe(document.querySelector('body'), config); };