Tinymce 4.x 扩展插件 [英] Tinymce 4.x extend plugin
问题描述
我正在寻找一些关于如何扩展现有 tinymce (4.x) 插件的示例,例如链接"插件.
I'm looking for some examples on how to extend a existing tinymce (4.x) plugin, e.g. the "link" plugin.
链接插件会打开一个对话框窗口...我想做的是在对话框打开时添加一个事件并修改正文(插入一些带有点击事件的额外 HTML).
The link plugin opens a dialog window... what I'd like to do is add an event when the dialog is opened and modify the body (insert some extra HTML with click events).
做得好似乎有问题......我想避免一些顶部"代码,如 $('#mce_13').click(...);
而不是使用类似
It seems to be problematic to do it nicely... I want to avoid some "on top" code like $('#mce_13').click(...);
and rather use something like
editor.on('DialogOpen', function(e) {
// if link dialog then
$(e.body).append('<div>My HTML</div>');
});
然而,没有像 onDialogOpen
这样的事件......是否有实现这一目标的最佳实践?
However there are no such events like onDialogOpen
... is there a best practice to achieve this?
推荐答案
我设法为模态窗口执行此操作(我需要打开/关闭回调)也许您可以在它的基础上检测打开的窗口类型:
I managed to do this for modal windows ( i needed callbacks for open/close ) maybe you could build on it to also detect what type of window is opened:
tinymce.init({
//... code and setup here
setup: function(editor) {
editor.on('init',function(e) {
setModalEvents(editor);
});
},
//... and more here perhaps
});
然后是函数本身:
// override modal methods to insert events
function setModalEvents(editor) {
editor.windowManager.oldOpen = editor.windowManager.open; // save for later
editor.windowManager.open = function(t,r) { // replace with our own function
alert("modal window opened, insert callback here");
var modal = this.oldOpen.apply(this, [t,r]); // call original
modal.on('close', function() { // set event for close
alert("modal window closed, insert callback here");
});
return modal; // Template plugin is dependent on this return value
};
}
您可以对 tinymce 核心中的其他内容进行类似的覆盖,所以这可能会有所帮助.
you could do similar overrides of other things in the tinymce core, so maybe this can be helpful.
这篇关于Tinymce 4.x 扩展插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!