Skip to content

Commit

Permalink
TinyMCE, make sure iframe is fully loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Jan 21, 2023
1 parent 725d772 commit 6e8bb56
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions build/media_source/plg_editors_tinymce/js/tinymce.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,32 @@

// Work around iframe behavior, when iframe element changes location in DOM and losing its content.
// Re init editor when iframe is reloaded.
ed.on('PostRender', () => {
const $iframe = ed.getContentAreaContainer().querySelector('iframe');
if ($iframe) {
if (!ed.inline) {
let isReady = false;
let isRendered = false;
const listenIframeReload = () => {
const $iframe = ed.getContentAreaContainer().querySelector('iframe');

$iframe.addEventListener('load', () => {
debounceReInit(ed, element, pluginOptions);
});
}
});
};

// Make sure iframe is fully loaded.
// This works differently in different browsers, so have to listen both "load" and "PostRender" events.
ed.on('load', () => {
isReady = true;
if (isRendered) {
listenIframeReload();
}
});
ed.on('PostRender', () => {
isRendered = true;
if (isReady) {
listenIframeReload();
}
});
}

ed.render();

Expand Down

0 comments on commit 6e8bb56

Please sign in to comment.