Question

I want to try and load the style formats from an external source like I do for link_list. The way it works for link_list unfortunately does not work for style_formats. I have tried multiple solutions as shown below. How can I do this? Nothing seems to work except for changing the options directly. If I paste my response it works, so my syntax is correct. Please, any help or directions to where I should look would be very helpful! Here are some things I have tried regarding getting and handling a response;

Directly paste link, exactly the same as for link_list

$.getJSON
var stylesFormats = JSON.stringify(jqXHR.responseText); 
var stylesFormats = JSON.stringify(data); 
var stylesFormats = data;
var stylesFormats = jqXHR.responseText; 
var stylesFormats = $.parseJSON(data); 
var stylesFormats = $.parseJSON(jqXHR.responseText); 

Ajax; No encoded response, no datatype
var stylesFormats = result; 
var stylesFormats = JSON.stringify(result); 
var stylesFormats = $.parseJSON(result); 

Ajax; No encoded response, script datatype
var stylesFormats = result; 
var stylesFormats = JSON.stringify(result); 
var stylesFormats = $.parseJSON(result); 

Ajax; json encoded response, script datatype
var stylesFormats = result; 
var stylesFormats = JSON.stringify(result); 
var stylesFormats = $.parseJSON(result); 

Ajax; json encoded response, html datatype
var stylesFormats = result; 
var stylesFormats = JSON.stringify(result); 
var stylesFormats = $.parseJSON(result); 

Ajax: header as javascript, no encoded response, no datatype
var stylesFormats = result; 
var stylesFormats = JSON.stringify(result); 
var stylesFormats = $.parseJSON(result); 

I have also made a topic on the tinymce forum but after no responses I thought I tried my luck here. The tinymce post can be found here.

Was it helpful?

Solution

tinymce doesn't handle the style_formats being a Promise. The easiest way to go around that is to put the tinymce.init call in the success callback of your getJSON.

$.getJSON(...url, data...
    ).done(function(style_formats) {
               tinymce.init({
                   style_formats: style_formats
                   ...other settings...
               });
           });

Alternative is walking all editors and updating the formatters and ui elements...

OTHER TIPS

Sadly, this seems not possible. The only way you can get the editor to respect your new style settings is to recreate it upon load, which is very inefficient. It works for link_list because that dialog is reconstructed when it loads, yet the style_settings only get used upon initialization. The only real option you have is to first load all styles and then initialize tinymce.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top