【问题标题】:Tinymce 4.x extend pluginTinymce 4.x 扩展插件
【发布时间】:2013-07-24 11:20:12
【问题描述】:

我正在寻找一些关于如何扩展现有 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 tinymce-4


    【解决方案1】:

    我设法为模态窗口执行此操作(我需要打开/关闭回调)也许你可以在它的基础上检测打开的窗口类型:

    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 核心中对其他内容进行类似的覆盖,所以也许这会有所帮助。

    【讨论】:

    • 对我来说足够可扩展:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多