Skip to content

Commit

Permalink
* automated editors buttons to be injected on DOM change rather than …
Browse files Browse the repository at this point in the history
…once only on document load

* also prevented cyclic injection
  • Loading branch information
imfx77 committed Apr 20, 2024
1 parent 94af0ae commit 8b4ac7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Assets/easymde/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
});
10 changes: 7 additions & 3 deletions Assets/stackedit/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;';
Expand Down Expand Up @@ -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 });
});

0 comments on commit 8b4ac7d

Please sign in to comment.