加载tinyMCE编辑器后添加style_formats

时间:2013-10-31 13:19:15

标签: javascript tinymce

当您初始化一个tinyMCE编辑器时,您可以传递以下客户样式。

tinyMCE.init({ style_formats: [{ title: 'flow', selector: 'img', styles: { 'float': 'left', 'margin-right': '5px' } }]});

但是,如果我想在加载后给tinyMCE som自定义样式怎么办?我怎样才能做到这一点。例如,我已经能够将style_formats添加到tinyMCE编辑器对象中。

tinyMCE.editors[0].settings["style_formats"] = [{title:'flow', selector:'img', styles: {'float' : 'left'}}];

但编辑本身并没有得到更新。有没有办法告诉tinyMCE自己重装?或者还有其他方法可以动态更新编辑器吗?

干杯。

2 个答案:

答案 0 :(得分:2)

你真的想在之后添加它或者只是附加到现有设置吗?从版本4.0.13开始,现在可以在init期间使用一个名为 style_formats_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%' } }
            ]
        }
    ]
});

答案 1 :(得分:0)

在你的配置文件之后,你可以通过添加以下代码在新的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%' } }
            ]
        }
]
 });