8
0
فهرست منبع

Workaround for the name conflict between the core "plugin" module and the RequireJS "plugin!" module.

fredck 11 سال پیش
والد
کامیت
ba2f8c6057
2فایلهای تغییر یافته به همراه25 افزوده شده و 14 حذف شده
  1. 5 1
      ckeditor.js
  2. 20 13
      src/plugin.js

+ 5 - 1
ckeditor.js

@@ -66,7 +66,11 @@
 			"ckeditor-core": CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/ckeditor',
 
 			// The RequireJS "plugin" plugin.
-			"plugin": CKEDITOR.basePath + 'src/plugin'
+			"plugin": CKEDITOR.basePath + 'src/plugin',
+
+			// Due to name conflict with the above, we have to save a reference to the core "plugin" module.
+			// See src/plugin.js for more details.
+			"plugin-core": CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/plugin'
 		}
 	} );
 

+ 20 - 13
src/plugin.js

@@ -9,21 +9,28 @@
 
 // Plugin for RequireJS to properly load CKEditor plugins through the "plugin!name" scheme:
 // "plugin!name" => "node_modules/ckeditor5-plugin-name/name"
-define( 'plugin', function() {
-	return {
-		load: function( name, require, onload ) {
-			var path = name.split( '/' );
-			path.splice( 1, 0, 'src' );
+//
+// Due to name conflict with the "ckeditor5-core/plugin" module, a workaround was needed. In this case, we extend the
+// core Plugin class with the necessary RequireJS plugin methods. This should have no harm on the use of the Plugin
+// class.
 
-			if ( path.length === 2 ) {
-				path.push( path[ 0 ] );
-			}
+define( 'plugin', [ 'plugin-core' ], function( CorePlugin ) {
+	// Called when a "plugin!" module is to be loaded.
+	// http://requirejs.org/docs/plugins.html#apiload
+	CorePlugin.load = function( name, require, onload ) {
+		var path = name.split( '/' );
+		path.splice( 1, 0, 'src' );
 
-			path = '../../ckeditor5-plugin-' + path.join( '/' );
-
-			require( [ path ], function( value ) {
-				onload( value );
-			} );
+		if ( path.length === 2 ) {
+			path.push( path[ 0 ] );
 		}
+
+		path = '../../ckeditor5-plugin-' + path.join( '/' );
+
+		require( [ path ], function( value ) {
+			onload( value );
+		} );
 	};
+
+	return CorePlugin;
 } );