Skip to content

Commit

Permalink
Merge pull request #2494 from sascha-karnatz/2485-tinymce-does-not-lo…
Browse files Browse the repository at this point in the history
…ad-if-routing-with-turbolinks

Fix TinyMCE loading behavior after page change
  • Loading branch information
tvdeyen authored Jun 20, 2023
2 parents 5f0a70a + 82e2e29 commit 22024f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package/dist/admin.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package/dist/admin.js.map

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions package/src/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,32 @@ function initEditors(ids) {
})
}

// initialize IntersectionObserver if it is not already initialized
// initialize IntersectionObserver
// the observer will initialize Tinymce if the textarea becomes visible
function initializeIntersectionObserver() {
if (tinymceIntersectionObserver === null) {
const observerCallback = (entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
initTinymceEditor(entry.target)
// disable observer after the Tinymce was initialized
observer.unobserve(entry.target)
}
})
}
const options = {
root: Alchemy.ElementEditors.element_area.get(0),
rootMargin: "0px",
threshold: [0.05]
}
if (tinymceIntersectionObserver !== null) {
tinymceIntersectionObserver.disconnect()
}

tinymceIntersectionObserver = new IntersectionObserver(
observerCallback,
options
)
const observerCallback = (entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
initTinymceEditor(entry.target)
// disable observer after the Tinymce was initialized
observer.unobserve(entry.target)
}
})
}
const options = {
root: Alchemy.ElementEditors.element_area.get(0),
rootMargin: "0px",
threshold: [0.05]
}

tinymceIntersectionObserver = new IntersectionObserver(
observerCallback,
options
)
}

// Initializes one specific TinyMCE editor
Expand Down

0 comments on commit 22024f0

Please sign in to comment.