瀏覽代碼

Merge branch 'master' into t/9

Piotrek Koszuliński 7 年之前
父節點
當前提交
2094576b7d

+ 7 - 0
packages/ckeditor5-ckfinder/lang/contexts.json

@@ -0,0 +1,7 @@
+{
+	"Insert image or file": "Toolbar button tooltip for inserting an image or file via a CKFinder file browser.",
+	"Could not obtain resized image URL.": "Error message displayed when inserting a resized version of an image failed.",
+	"Selecting resized image failed": "Title of a notification displayed when inserting a resized version of an image failed.",
+	"Could not insert image at the current position.": "Error message displayed when an image cannot be inserted at the current position.",
+	"Inserting image failed": "Title of a notification displayed when an image cannot be inserted at the current position."
+}

+ 10 - 6
packages/ckeditor5-ckfinder/src/ckfindercommand.js

@@ -34,9 +34,7 @@ export default class CKFinderCommand extends Command {
 		this.stopListening( this.editor.model.document, 'change' );
 
 		// Lower this command listener priority to be sure that refresh() will be called after link & image refresh.
-		this.listenTo( this.editor.model.document, 'change', () => {
-			this.refresh();
-		}, { priority: 'low' } );
+		this.listenTo( this.editor.model.document, 'change', () => this.refresh(), { priority: 'low' } );
 	}
 
 	/**
@@ -46,7 +44,8 @@ export default class CKFinderCommand extends Command {
 		const imageCommand = this.editor.commands.get( 'imageUpload' );
 		const linkCommand = this.editor.commands.get( 'link' );
 
-		this.isEnabled = ( !imageCommand || !linkCommand ) ? false : ( imageCommand.isEnabled || linkCommand.isEnabled );
+		// The CKFinder command is enabled when one of image or link command is enabled.
+		this.isEnabled = imageCommand && linkCommand && ( imageCommand.isEnabled || linkCommand.isEnabled );
 	}
 
 	/**
@@ -68,6 +67,11 @@ export default class CKFinderCommand extends Command {
 		// Cache the user-defined onInit method
 		const originalOnInit = options.onInit;
 
+		// Pass the lang code to the CKFinder if not defined by user.
+		if ( !options.language ) {
+			options.language = editor.locale.language;
+		}
+
 		// 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.
@@ -106,7 +110,7 @@ export default class CKFinderCommand extends Command {
 					const notification = editor.plugins.get( Notification );
 					const t = editor.locale.t;
 
-					notification.showWarning( t( 'Could not obtain resized image URL. Try different image or folder.' ), {
+					notification.showWarning( t( 'Could not obtain resized image URL.' ), {
 						title: t( 'Selecting resized image failed' ),
 						namespace: 'ckfinder'
 					} );
@@ -130,7 +134,7 @@ function insertImages( editor, urls ) {
 		const notification = editor.plugins.get( Notification );
 		const t = editor.locale.t;
 
-		notification.showWarning( t( 'Could not insert image at current selection.' ), {
+		notification.showWarning( t( 'Could not insert image at the current position.' ), {
 			title: t( 'Inserting image failed' ),
 			namespace: 'ckfinder'
 		} );

+ 1 - 1
packages/ckeditor5-ckfinder/src/ckfinderui.js

@@ -39,7 +39,7 @@ export default class CKFinderUI extends Plugin {
 			const button = new ButtonView( locale );
 
 			button.set( {
-				label: t( 'CKFinder' ),
+				label: t( 'Insert image or file' ),
 				icon: ckfinderIcon,
 				tooltip: true
 			} );

+ 59 - 7
packages/ckeditor5-ckfinder/tests/ckfindercommand.js

@@ -34,9 +34,6 @@ describe( 'CKFinderCommand', () => {
 
 				command = new CKFinderCommand( editor );
 
-				const schema = model.schema;
-				schema.extend( 'image' );
-
 				setModelData( model, '<paragraph>f[o]o</paragraph>' );
 			} );
 	} );
@@ -134,7 +131,7 @@ describe( 'CKFinderCommand', () => {
 			expect( finderMock ).to.have.property( 'file:choose:resizedImage' );
 		} );
 
-		it( 'should use "CKFinder.modal" as default CKFinder opener method', () => {
+		it( 'should use CKFinder.modal() as default CKFinder opener method', () => {
 			const spy = sinon.spy( window.CKFinder, 'modal' );
 
 			command.execute();
@@ -142,7 +139,7 @@ describe( 'CKFinderCommand', () => {
 			sinon.assert.calledOnce( spy );
 		} );
 
-		it( 'should use "CKFinder.modal" as default CKFinder opener method', () => {
+		it( 'should use CKFinder.popup() when ckfinder.openerMethod is set to it', () => {
 			const spy = sinon.spy( window.CKFinder, 'popup' );
 
 			editor.config.set( 'ckfinder.openerMethod', 'popup' );
@@ -207,6 +204,61 @@ describe( 'CKFinderCommand', () => {
 			sinon.assert.calledOnce( spy );
 		} );
 
+		it( 'should pass editor default language to the CKFinder instance', () => {
+			const spy = sinon.spy( window.CKFinder, 'modal' );
+			command.execute();
+
+			const openerMethodOptions = spy.args[ 0 ][ 0 ];
+
+			expect( openerMethodOptions ).to.have.property( 'language', 'en' );
+		} );
+
+		it( 'should pass editor language set by configuration to the CKFinder instance', () => {
+			const finderMock = {
+				on: ( eventName, callback ) => {
+					finderMock[ eventName ] = callback;
+				}
+			};
+
+			return VirtualTestEditor
+				.create( {
+					plugins: [ Paragraph, ImageEditing, ImageUploadEditing, LinkEditing, Notification ],
+					language: 'pl'
+				} )
+				.then( newEditor => {
+					editor = newEditor;
+
+					window.CKFinder = {
+						modal: config => {
+							config.onInit( finderMock );
+						}
+					};
+
+					command = new CKFinderCommand( editor );
+
+					setModelData( editor.model, '<paragraph>f[o]o</paragraph>' );
+					const spy = sinon.spy( window.CKFinder, 'modal' );
+
+					command.execute();
+
+					const openerMethodOptions = spy.args[ 0 ][ 0 ];
+
+					expect( openerMethodOptions ).to.have.property( 'language', 'pl' );
+				} );
+		} );
+
+		it( 'should not pass editor language if it is set in ckfinder.options', () => {
+			const spy = sinon.spy( window.CKFinder, 'modal' );
+
+			editor.config.set( 'ckfinder.options.language', 'pl' );
+
+			command.execute();
+
+			const openerMethodOptions = spy.args[ 0 ][ 0 ];
+
+			expect( openerMethodOptions ).to.have.property( 'language', 'pl' );
+		} );
+
 		it( 'should insert multiple chosen images as image widget', () => {
 			const url1 = 'foo/bar1.jpg';
 			const url2 = 'foo/bar2.jpg';
@@ -266,7 +318,7 @@ describe( 'CKFinderCommand', () => {
 			const notification = editor.plugins.get( Notification );
 
 			notification.on( 'show:warning', ( evt, data ) => {
-				expect( data.message ).to.equal( 'Could not obtain resized image URL. Try different image or folder.' );
+				expect( data.message ).to.equal( 'Could not obtain resized image URL.' );
 				expect( data.title ).to.equal( 'Selecting resized image failed' );
 				evt.stop();
 
@@ -299,7 +351,7 @@ describe( 'CKFinderCommand', () => {
 			const notification = editor.plugins.get( Notification );
 
 			notification.on( 'show:warning', ( evt, data ) => {
-				expect( data.message ).to.equal( 'Could not insert image at current selection.' );
+				expect( data.message ).to.equal( 'Could not insert image at the current position.' );
 				expect( data.title ).to.equal( 'Inserting image failed' );
 				evt.stop();
 

+ 1 - 1
packages/ckeditor5-ckfinder/tests/ckfinderui.js

@@ -56,7 +56,7 @@ describe( 'CKFinderUI', () => {
 		} );
 
 		it( 'should set a #label of the #buttonView', () => {
-			expect( button.label ).to.equal( 'CKFinder' );
+			expect( button.label ).to.equal( 'Insert image or file' );
 		} );
 
 		it( 'should set an #icon of the #buttonView', () => {