Browse Source

Simplified media config.

Aleksander Nowodzinski 7 years ago
parent
commit
65eb5d45b1

+ 5 - 19
packages/ckeditor5-media-embed/src/mediaembedediting.js

@@ -48,10 +48,6 @@ export default class MediaEmbedEditing extends Plugin {
 				},
 
 				{
-					url: /^(https:\/\/)?(www\.)?instagram\.com\/p\/(\w+)/
-				},
-
-				{
 					url: [
 						/^(https:\/\/)?(www\.)?open\.spotify\.com\/(artist\/\w+)/,
 						/^(https:\/\/)?(www\.)?open\.spotify\.com\/(album\/\w+)/,
@@ -101,21 +97,11 @@ export default class MediaEmbedEditing extends Plugin {
 						'</div>'
 				},
 
-				{
-					url: /^(https:\/\/)?(www\.)?twitter\.com/
-				},
-
-				{
-					url: /^(https:\/\/)?(www\.)?google\.com\/maps/
-				},
-
-				{
-					url: /^(https:\/\/)?(www\.)?flickr\.com/
-				},
-
-				{
-					url: /^(https:\/\/)?(www\.)?facebook\.com/
-				}
+				/^(https:\/\/)?(www\.)?instagram\.com\/p\/(\w+)/,
+				/^(https:\/\/)?(www\.)?twitter\.com/,
+				/^(https:\/\/)?(www\.)?google\.com\/maps/,
+				/^(https:\/\/)?(www\.)?flickr\.com/,
+				/^(https:\/\/)?(www\.)?facebook\.com/
 			]
 		} );
 

+ 10 - 1
packages/ckeditor5-media-embed/src/mediaregistry.js

@@ -82,7 +82,16 @@ export class MediaRegistry {
 
 		url = url.trim();
 
-		for ( let { url: pattern, html: contentRenderer } of this.providerDefinitions ) {
+		for ( const definition of this.providerDefinitions ) {
+			let pattern, contentRenderer;
+
+			if ( definition instanceof RegExp ) {
+				pattern = definition;
+			} else {
+				pattern = definition.url;
+				contentRenderer = definition.html;
+			}
+
 			if ( !Array.isArray( pattern ) ) {
 				pattern = [ pattern ];
 			}

+ 1 - 3
packages/ckeditor5-media-embed/tests/mediaembedediting.js

@@ -13,9 +13,7 @@ import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml'
 describe( 'MediaEmbedEditing', () => {
 	let editor, model, doc, view;
 	const mediaDefinitions = [
-		{
-			url: /^https:\/\/generic/
-		},
+		/^https:\/\/generic/,
 		{
 			url: /(.*)/,
 			html: id => `<iframe src="${ id }"></iframe>`