我正在寻找一些有关如何扩展现有的tinymce(4.x)插件的示例,例如“链接”插件。
链接插件打开一个对话框窗口...我想做的是在对话框打开时添加一个事件并修改正文(插入一些带有单击事件的额外 HTML)。
做得好似乎是有问题的......我想避免一些“顶部”代码,例如$('#mce_13').click(...);
而是使用类似的东西
editor.on('DialogOpen', function(e) {
// if link dialog then
$(e.body).append('<div>My HTML</div>');
});
但是没有这样的事件onDialogOpen
...是否有实现此目标的最佳实践?
我设法对模态窗口执行此操作(我需要打开/关闭的回调)也许您可以在此基础上构建来检测打开的窗口类型:
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核心中的其他内容进行类似的覆盖,所以这可能会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)