【问题标题】:TinyMCE template plugin insert last in editorTinyMCE 模板插件在编辑器中最后插入
【发布时间】:2018-06-21 21:32:40
【问题描述】:

我正在使用 TinyMCE v4.7.9

使用模板时 (https://www.tinymce.com/docs/plugins/template/)

我想在内容编辑器中最后插入模板,而不是我所在的位置,是否有一些技巧可以做到这一点?我可以在对话框上添加一个“插入之后”按钮吗?

现在我被其他一些 P 标签困住了,我的模板是 DIV。

问候

【问题讨论】:

    标签: tinymce tinymce-4


    【解决方案1】:

    经过反复试验,没有办法找到答案,我找到了解决方法。

    我用

    开始模板

    在事件“BeforeSetContent”的设置中:

    editor.on('BeforeSetContent', function (e) {
        if (e.content.indexOf("<div data-insertafter") === 0) { //okej, insert after
    
            editor.setContent(editor.getContent() + '<div class="row"></div>');//add an element to in the end
            editor.selection.select(editor.getBody(), true);//select al
            editor.selection.collapse(false);//set focus on that last div by inverting selection
    
            e.content = e.content.replace("data-insertafter", "");//remove
        }
    });
    

    【讨论】:

      【解决方案2】:

      您当然可以修改模板插件来做到这一点...每个插件都附带一个缩小版和非缩小版,因此您只需修改非缩小版即可满足此需求。

      【讨论】:

      • 谢谢,这是一种方式,但是 TinyMCE 是内置在 Episerver CMS 中的,这不是一个选项,我不想复制插件代码,然后我没有得到新的东西,有吗一种拦截插入事件并在之后插入的方法,或者我可以为使这个插件更好吗?
      猜你喜欢
      • 1970-01-01
      • 2011-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多