Image dialog — extend onOk, instead of total overwrite

前端 未结 2 1843
轮回少年
轮回少年 2020-12-21 03:43

I have found out that I can hook into onOk with this:

editor.on(\'dialogShow\', function (ev)
{
    var name = ev.data.getName();
    var defini         


        
相关标签:
2条回答
  • 2020-12-21 04:13
    var oldImplementation = definition.onOk;
    definition.onOk = function(e)
    {
        oldImplementation(e);
        console.log( e );
    };
    
    0 讨论(0)
  • 2020-12-21 04:17

    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();
            } );
        }
    } );
    
    0 讨论(0)
提交回复
热议问题