javascript - 在加载 tinyMCE 编辑器后添加 style_formats

标签 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 自己重新加载它?还是有另一种方法可以即时更新编辑器?

干杯。

最佳答案

您的意思是在现有设置之后添加还是仅附加到现有设置?从 4.0.13 版开始,现在有一个新属性可以在初始化期间使用,名为 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%' } }
            ]
        }
    ]
});

关于javascript - 在加载 tinyMCE 编辑器后添加 style_formats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707621/

相关文章:

javascript - 如果接下来 10 秒内没有隐藏则隐藏 div

javascript - 具有复杂数据模型的自定义 Wicket (Ajax) 控件

WordPress tinyMCE 窗口管理器上传按钮未将 url 添加到文本字段

javascript - tinymce 不支持 React hook 形式

jquery - 将 jQuery Validate 插件与 TinyMCE 编辑器结合使用

javascript - Ionic 2 - 传单 map onclick 事件

javascript - 嵌套循环忽略其他元素

javascript - 制作二维码全 Angular

php - 停止 TinyMCE 在 WordPress 中剥离空标签 - 是的,我已经研究过了

php - 当我通过 jQuery .load() 加载 tinyMCE 时浏览器卡住