我正在寻找一些关于如何扩展现有的tinymce(4.x)插件的例子,例如"链接"插件.
链接插件打开一个对话框窗口......我想要做的是在打开对话框时添加一个事件并修改正文(用点击事件插入一些额外的HTML).
这样做似乎很有问题...我想避免一些"在顶部"代码$('#mce_13').click(...);
,而不是使用类似的东西
editor.on('DialogOpen', function(e) {
// if link dialog then
$(e.body).append('<div>My HTML</div>');
});
Run Code Online (Sandbox Code Playgroud)
然而,没有像onDialogOpen
...... 这样的事件是否有最佳实践来实现这一目标?
我设法为模态窗口做这个(我需要回调打开/关闭)也许你可以在它上构建它以检测打开什么类型的窗口:
tinymce.init({
//... code and setup here
setup: function(editor) {
editor.on('init',function(e) {
setModalEvents(editor);
});
},
//... and more here perhaps
});
Run Code Online (Sandbox Code Playgroud)
然后是函数本身:
// 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
};
}
Run Code Online (Sandbox Code Playgroud)
你可以在tinymce核心中做其他事情的类似覆盖,所以这可能会有所帮助.
归档时间: |
|
查看次数: |
2752 次 |
最近记录: |