【问题标题】:Add style_formats after tinyMCE editor is loaded在加载 tinyMCE 编辑器后添加 style_formats
【发布时间】:2013-11-11 12:34:35
【问题描述】:

当您初始化 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 自己重新加载它?还是有其他方法可以即时更新编辑器?

干杯。

【问题讨论】:

    标签: javascript tinymce


    【解决方案1】:

    您真的是要在现有设置之后添加还是只是附加到现有设置?从 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%' } }
                ]
            }
        ]
    });
    

    【讨论】:

      【解决方案2】:

      在您的 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%' } }
                  ]
              }
      ]
       });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-03
        • 2012-10-27
        • 1970-01-01
        相关资源
        最近更新 更多