Text Editor through AJAX

Text Editor through AJAX

by Conn Warwicker -
Number of replies: 3
Picture of Core developers Picture of Plugin developers

I'm loading up the moodle text editor on various pages loaded through ajax, so what i'm doing is:


require_once $CFG->dirroot.'/lib/form/editor.php';

require_once $CFG->dirroot . '/lib/editorlib.php';

$editor = \editors_get_preferred_editor();

$editor->use_editor("elbpfe_{$id}_{$this->id}");

$output .= "<textarea id='elbpfe_{$id}_{$this->id}'>".$this->getValue()."</textarea>";


So I'm getting the preferred editor and applying it to the textarea field which I output, then at the end of the content I do:

global $PAGE;

$code = $PAGE->requires->get_end_code();

return $code;


To get the javascript to actually create the texteditor.


It's working fine except for one thing, in that the strings for various things are not being changed from the defaults in the tinymce template.

E.g:


screenshot


So you can see that instead of things like "font family", "font size", etc.. the strings have come back as "advanced.font_size", "advanced.font_family", etc...


Does anyone know what else I need to do to sort this out?


Cheers.

Average of ratings: -
In reply to Conn Warwicker

Re: Text Editor through AJAX

by Conn Warwicker -
Picture of Core developers Picture of Plugin developers

Fixed this in the end. The tinymce had set itself to initialised, so it was skipping the loading of the language files.


Had to put this in before the js call in the ajax:


        $editor = \editors_get_preferred_editor();

        $class = get_class($editor);

        $editorName = substr( $class, 0, strpos($class, '_') );

        $output .= "<script>M.editor_{$editorName}.initialised = false;</script>";