Image dialog — extend onOk, instead of total overwrite

情到浓时终转凉″ 提交于 2019-11-29 14:43:05

Small improvement of maximkou's solution:

var oldImplementation = definition.onOk;
definition.onOk = function( e ) {
    oldImplementation.apply( this, [].slice.call( arguments ) );
    console.log( e );
};

This solution is ok and AFAIK it's the cleanest one.

Update: I've found a better solution - there's dialog#ok event about which I've just learnt :). So you don't need to change dialog's definition - you can bind your event listener like this:

editor.on('dialogShow', function ( evt ) {
    if ( evt.data.getName() == 'image' ) {
        var listener = evt.data.on( 'ok', function() {
            console.log( 'ok!' );
        } );

        // We need to remove that listener, to avoid duplicating it on
        // next dialogShow.
        evt.data.on( 'hide', function() {
            listener.removeListener();
        } );
    }
} );
var oldImplementation = definition.onOk;
definition.onOk = function(e)
{
    oldImplementation(e);
    console.log( e );
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!