Javascript 加载tinyMCE编辑器后添加样式\u格式

Javascript 加载tinyMCE编辑器后添加样式\u格式,javascript,tinymce,Javascript,Tinymce,初始化tinyMCE编辑器时,可以传递以下自定义样式 tinyMCE.init({ style_formats: [{ title: 'flow', selector: 'img', styles: { 'float': 'left', 'margin-right': '5px' } }]}); 但是,如果我想在加载tinyMCE som后为其提供自定义样式,该怎么办?我该怎么做呢。例如,我已经能够像这样将样式_格式添加到tinyMCE编辑器对象中 tinyMCE.editors[0].set

初始化tinyMCE编辑器时,可以传递以下自定义样式

tinyMCE.init({ style_formats: [{ title: 'flow', selector: 'img', styles: { 'float': 'left', 'margin-right': '5px' } }]});
但是,如果我想在加载tinyMCE som后为其提供自定义样式,该怎么办?我该怎么做呢。例如,我已经能够像这样将样式_格式添加到tinyMCE编辑器对象中

tinyMCE.editors[0].settings["style_formats"] = [{title:'flow', selector:'img', styles: {'float' : 'left'}}];
但是编辑器本身并没有得到更新。有没有办法让tinyMCE自己重新加载?或者有没有其他方法可以动态更新编辑器


干杯。

您真的想在现有设置之后添加它还是仅仅附加到现有设置?从版本4.0.13开始,现在有一个新属性可以在初始化期间使用,名为style\u formats\u merge。将此属性设置为true,它会将样式连接到默认集

tinymce.init({
    style_formats_merge: true,
    style_formats: [
        {
            title: 'Line Height',
            items: [
                { title: 'Normal Line Height', inline: 'span', styles: { "line-height": '100%' } },
                { title: 'Line Height + 10%', inline: 'span', styles: { "line-height": '110%' } },
                { title: 'Line Height + 50%', inline: 'span', styles: { "line-height": '150%' } },
                { title: 'Line Height + 100%', inline: 'span', styles: { "line-height": '200%' } }
            ]
        }
    ]
});

在tinymce配置文件之后,您可以通过向新的js文件添加以下代码来扩展tinymce设置

jQuery.extend(tinymce.settings,
{
   style_formats: [
        {
            title: 'Line Height',
            items: [
                { title: 'Normal Line Height', inline: 'span', styles: { "line-height": '100%' } },
                { title: 'Line Height + 10%', inline: 'span', styles: { "line-height": '110%' } },
                { title: 'Line Height + 50%', inline: 'span', styles: { "line-height": '150%' } },
                { title: 'Line Height + 100%', inline: 'span', styles: { "line-height": '200%' } }
            ]
        }
]
 });