Image dialog - continue onOk, not full rewrite

I found out that I can connect to onOk with this:

 editor.on('dialogShow', function (ev) { var name = ev.data.getName(); var definition = ev.data.definition; if (name == 'image') { definition.onOk = function(e) { console.log( e ); }; } }); 

Surprisingly, if only now the default behavior is not canceled, as a result of which the image will not be added to the contents of CK.

Checking the source of CK , I do not want to disrupt the functionality of 74 lines by default.

My goal is simply to launch the image via a callback after adding it.

Copy / paste, change the only way to keep functionality, or is there another way?

+4
source share
2 answers

A slight improvement to 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 is the cleanest .

Update : I found a better solution - there is a dialog#ok event that I just learned about :). Therefore, you do not need to change the definition of the dialog - you can link the event listener as follows:

 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(); } ); } } ); 
+6
source
 var oldImplementation = definition.onOk; definition.onOk = function(e) { oldImplementation(e); console.log( e ); }; 
+2
source

Source: https://habr.com/ru/post/1484449/


All Articles