diff --git a/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee b/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee index d3dfde2f11..b27d1c2420 100644 --- a/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +++ b/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee @@ -52,5 +52,6 @@ $(document).on 'turbo:load', -> $(document).on 'turbo:before-fetch-request', -> # Ensure that all tinymce editors get removed before parsing a new page + Alchemy.Tinymce.removeIntersectionObserver() Alchemy.Tinymce.removeFrom $('.has_tinymce') return diff --git a/app/javascript/alchemy_admin/tinymce.js b/app/javascript/alchemy_admin/tinymce.js index 66b3acb86d..5cdb194e41 100644 --- a/app/javascript/alchemy_admin/tinymce.js +++ b/app/javascript/alchemy_admin/tinymce.js @@ -41,10 +41,6 @@ function initEditors(ids) { // initialize IntersectionObserver // the observer will initialize Tinymce if the textarea becomes visible function initializeIntersectionObserver() { - if (tinymceIntersectionObserver !== null) { - tinymceIntersectionObserver.disconnect() - } - const observerCallback = (entries, observer) => { entries.forEach((entry) => { if (entry.intersectionRatio > 0) { @@ -108,6 +104,12 @@ function removeEditor(editorId) { } } +function removeIntersectionObserver() { + if (tinymceIntersectionObserver !== null) { + tinymceIntersectionObserver.disconnect() + } +} + export default { // Initializes all TinyMCE editors with given ids // @@ -135,6 +137,8 @@ export default { }) }, + removeIntersectionObserver, + // set tinymce configuration for a given selector key setCustomConfig(key, configuration) { tinymceCustomConfigs[key] = configuration