TinyMCE 模板插件最后插入编辑器
TinyMCE template plugin insert last in editor
我正在使用 TinyMCE v4.7.9
使用模板时(https://www.tinymce.com/docs/plugins/template/)
我想在内容编辑器中最后插入模板,而不是我站的地方,有什么技巧可以做到这一点吗?我可以在对话框中添加一个按钮 "insert after" 吗?
现在我陷入了其他一些 P 标签,我的模板是 DIV。
此致
您当然可以修改模板插件来做到这一点...每个插件都以缩小版和非缩小版发布,因此您只需修改非缩小版即可满足此需求。
经过反复试验但无法找到答案后,我找到了解决方法。
我用
启动模板
在事件设置中 "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
}
});
我正在使用 TinyMCE v4.7.9
使用模板时(https://www.tinymce.com/docs/plugins/template/)
我想在内容编辑器中最后插入模板,而不是我站的地方,有什么技巧可以做到这一点吗?我可以在对话框中添加一个按钮 "insert after" 吗?
现在我陷入了其他一些 P 标签,我的模板是 DIV。
此致
您当然可以修改模板插件来做到这一点...每个插件都以缩小版和非缩小版发布,因此您只需修改非缩小版即可满足此需求。
经过反复试验但无法找到答案后,我找到了解决方法。
我用
启动模板
在事件设置中 "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
}
});