1

I've built a form that calls for an editor to be loaded through AJAX, but when I insert the fetched contents I get only a <textarea>. If I hit the toggle editor button, then the editor gets built, but it uses the default configuration for TinyMCE instead of how Joomla tries to configure it.

My Javascript:

$.ajax({
    method:'GET',
    url:'fetchEditor.php'
}).done(function(response) {
    $('#main').append(response);
});

fetchEditor.php:

<?php
$editor = JFactory::getEditor('tinymce');
echo $editor->display('text', '', 'auto', 'auto', 55, 15, false);
?>

I tried throwing in some Javascript to re-init TinyMCE for this editor, but it also just uses the default configuration instead of what Joomla uses.

1 Answer 1

2

After spending more time searching for possibilities, I found that Joomla includes the file /media/editors/tinymce/js/tinymce.min.js, and upon opening the uncompressed version of the file and reading through it, I saw that it has the function Joomla.JoomlaTinyMCE.setupEditors(); which handles the initialization of all instances of TinyMCE on the page.

So, after the AJAX loads the new editor, recalling Joomla.JoomlaTinyMCE.setupEditors(); will handle everything.

1
  • Well, after going through some of my use cases, I noticed that some config options weren't being set properly unless another editor was already on the page. Trying to resolve now.
    – Chaosxmk
    Commented Nov 6, 2020 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.