mercredi 29 juin 2016

Tinymce Error - Failed to load plugin js files when dynamically loaded

I'm trying to load TinyMCE dynamically like so (on clicking a button):

$.getScript('path/to/mce4/tinymce.min.js', function(){
    var def = {
        selector: 'textarea',
        body_class: 'sp-mce-editor',
        content_css : "path/to/styles/mce.css",
        plugins: ['advlist autolink lists link image charmap print preview hr anchor pagebreak searchreplace wordcount visualblocks visualchars code insertdatetime media nonbreaking table contextmenu directionality emoticons template paste textcolor fullscreen autoresize'],
        toolbar: "bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | fontsizeselect forecolor backcolor | preview fullscreen | template",
        toolbar_items_size: 'small',
        relative_urls : false,
        convert_urls : true,
        external_plugins: { "nanospell": "path/to/mce4/nanospell/plugin.js" },
        nanospell_server:"php",
        file_browser_callback: RoxyFileBrowser,
        init_instance_callback: (typeof processEditor != 'undefined' ? processEditor : null)
   };


    tinymce.init(def);
});

With this configuration, tinyMCE fails to initialize. In the console I see several 404 errors, each with a message like this:

Failed to load: /path/to/mce4/plugins/textcolor/plugin.js

Sure on checking in the console the JS file tinymce.min.js loads correctly. Also, the /path/to/mce4/plugins/textcolor/plugin.js does not exist. But /path/to/mce4/plugins/textcolor/plugin.min.js exists, and this is true for all the js files involved (i.e. the .min.js files are there, but tinyMCE for whatever reason is looking for the .js files).

Now, when I load tinyMCE in a script tab in the <head>, there's no problem at all, and everything works well.

What could be causing this error, and how am I supposed to fix it? If this is the expected behaviour of tinyMCE, what is the correct way to dynamically load the its js file for the scenario such as I am working on?

Aucun commentaire:

Enregistrer un commentaire