diff --git a/Assets/easymde/editor.js b/Assets/easymde/editor.js index 3c63796..f72e2ce 100644 --- a/Assets/easymde/editor.js +++ b/Assets/easymde/editor.js @@ -16,6 +16,8 @@ function injectButtonWrapperEasyMDE() { `; $('.text-editor-write-mode').each(function() { + // check if button already injected + if (this.querySelector('.easymde-button-wrapper')) return; const buttonWrapper = document.createElement('span'); buttonWrapper.className = 'easymde-button-wrapper'; @@ -221,8 +223,9 @@ function injectButtonWrapperEasyMDE() { $(function() { injectButtonWrapperEasyMDE(); -}); -KB.on('modal.afterRender', function () { - injectButtonWrapperEasyMDE(); + var observerRenderEasyMDE = new MutationObserver(function() { + injectButtonWrapperEasyMDE(); + }); + observerRenderEasyMDE.observe(document, { subtree: true, childList: true }); }); diff --git a/Assets/stackedit/editor.js b/Assets/stackedit/editor.js index 18eb95d..1dea3ae 100644 --- a/Assets/stackedit/editor.js +++ b/Assets/stackedit/editor.js @@ -5,6 +5,9 @@ function injectButtonWrapperStackEdit() { $('.text-editor-write-mode').each(function() { + // check if button already injected + if (this.querySelector('.stackedit-button-wrapper')) return; + const buttonWrapper = document.createElement('span'); buttonWrapper.className = 'stackedit-button-wrapper'; buttonWrapper.style = 'margin: 0px 0px 0px 20px; cursor: pointer;'; @@ -47,8 +50,9 @@ function injectButtonWrapperStackEdit() { $(function() { injectButtonWrapperStackEdit(); -}); -KB.on('modal.afterRender', function () { - injectButtonWrapperStackEdit(); + var observerRenderEasyMDE = new MutationObserver(function() { + injectButtonWrapperStackEdit(); + }); + observerRenderEasyMDE.observe(document, { subtree: true, childList: true }); });