Skip to content

Commit

Permalink
Fix tinyMCE Stimulus compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Feb 18, 2025
1 parent 31ee5b9 commit f1c8774
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Resources/public/js/be_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ var removeTinyMCEs = function(element) {
}
textareas.push({
textarea: textarea,
isStimulus: !!textarea.tinymceConfig,
settings: Object.append({}, settings)
});
element.store('rsce_tinyMCE_textareas', textareas);
editors[i].remove();
textarea.removeAttribute('data-controller');
textarea.removeAttribute('data-action');
}
}

Expand All @@ -88,6 +91,13 @@ var restoreTinyMCEs = function(element) {

if (window.tinymce && window.tinymce.Editor) {
element.retrieve('rsce_tinyMCE_textareas', []).each(function(data) {
if (data.isStimulus) {
setTimeout(() => {
data.textarea.setAttribute('data-action', 'turbo:before-visit@window->contao--tinymce#leave');
data.textarea.setAttribute('data-controller', 'contao--tinymce');
});
return;
}
new window.tinymce.Editor(
data.textarea.get('id'),
data.settings,
Expand Down Expand Up @@ -419,6 +429,9 @@ var copyTinyMceConfigs = function(origItem, origKey, newItem, newKey) {
var textareas = [];

origItem.retrieve('rsce_tinyMCE_textareas', []).each(function(data) {
if (data.isStimulus) {
return;
}
var newData = {
settings: Object.append({}, data.settings)
};
Expand Down Expand Up @@ -485,6 +498,10 @@ var duplicateElement = function(linkElement) {
// The order is important to prevent id conflicts:
// remove tinyMCEs => duplicate the element => rename => restoring tinyMCEs

element.getAllNext('.rsce_list_item').each(function(el) {
removeTinyMCEs(el);
});

removeTinyMCEs(element);
removePicker(listInner);
restoreSelectorScripts(element);
Expand Down

0 comments on commit f1c8774

Please sign in to comment.