Explorar el Código

Call user-defined onInit method.

Maciej Gołaszewski hace 7 años
padre
commit
2413414b69

+ 8 - 0
packages/ckeditor5-ckfinder/src/ckfindercommand.js

@@ -65,8 +65,16 @@ export default class CKFinderCommand extends Command {
 
 		options.chooseFiles = true;
 
+		// Cache the user-defined onInit method
+		const originalOnInit = options.onInit;
+
 		// The onInit method allows to extend CKFinder's behavior. It is used to attach event listeners to file choosing related events.
 		options.onInit = finder => {
+			// Call original options.onInit if it was defined by user.
+			if ( originalOnInit ) {
+				originalOnInit();
+			}
+
 			finder.on( 'files:choose', evt => {
 				const files = evt.data.files.toArray();
 

+ 10 - 0
packages/ckeditor5-ckfinder/tests/ckfindercommand.js

@@ -197,6 +197,16 @@ describe( 'CKFinderCommand', () => {
 			expect( openerMethodOptions ).to.have.property( 'connectorPath', connectorPath );
 		} );
 
+		it( 'should call user defined config.onInit() function', () => {
+			const spy = sinon.spy();
+
+			editor.config.set( 'ckfinder.options.onInit', spy );
+
+			command.execute();
+
+			sinon.assert.calledOnce( spy );
+		} );
+
 		it( 'should insert multiple chosen images as image widget', () => {
 			const url1 = 'foo/bar1.jpg';
 			const url2 = 'foo/bar2.jpg';