Skip to content

Commit

Permalink
Merge pull request #2519 from tvdeyen/fix-intersection-observer-disco…
Browse files Browse the repository at this point in the history
…nnect

Fix disconnecting Tinymce intersection observer
  • Loading branch information
tvdeyen authored Jul 6, 2023
2 parents 830e5dc + 53d9c1c commit 148a161
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions app/javascript/alchemy_admin/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -108,6 +104,12 @@ function removeEditor(editorId) {
}
}

function removeIntersectionObserver() {
if (tinymceIntersectionObserver !== null) {
tinymceIntersectionObserver.disconnect()
}
}

export default {
// Initializes all TinyMCE editors with given ids
//
Expand Down Expand Up @@ -135,6 +137,8 @@ export default {
})
},

removeIntersectionObserver,

// set tinymce configuration for a given selector key
setCustomConfig(key, configuration) {
tinymceCustomConfigs[key] = configuration
Expand Down

0 comments on commit 148a161

Please sign in to comment.