Tinymce 4.x extend plugin

北城以北 提交于 2019-12-06 05:09:25

问题


I'm looking for some examples on how to extend a existing tinymce (4.x) plugin, e.g. the "link" plugin.

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).

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>');
});

However there are no such events like onDialogOpen... is there a best practice to achieve this?


回答1:


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
});

and then the function itself:

// 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
    };
}

you could do similar overrides of other things in the tinymce core, so maybe this can be helpful.



来源:https://stackoverflow.com/questions/17832495/tinymce-4-x-extend-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!