8
0
فهرست منبع

Added support for "plugin!" and properly initialized the CKEDITOR module.

fredck 11 سال پیش
والد
کامیت
1eddc343f6
3فایلهای تغییر یافته به همراه75 افزوده شده و 22 حذف شده
  1. 43 22
      ckeditor.js
  2. 3 0
      gruntfile.js
  3. 29 0
      src/plugin.js

+ 43 - 22
ckeditor.js

@@ -7,10 +7,16 @@
 
 
 'use strict';
 'use strict';
 
 
+// This file is required for the development version of CKEditor only. It bootstraps the API.
+
 // Basic Require.js configuration.
 // Basic Require.js configuration.
 requirejs.config( {
 requirejs.config( {
 	// Modules are generally relative to the core project.
 	// Modules are generally relative to the core project.
-	baseUrl: '../node_modules/ckeditor-core/src/'
+	baseUrl: '../node_modules/ckeditor-core/src/',
+	paths: {
+		// The RequireJS "plugin" plugin.
+		plugin: '../src/plugin'
+	}
 } );
 } );
 
 
 ( function( root ) {
 ( function( root ) {
@@ -18,25 +24,40 @@ requirejs.config( {
 		return;
 		return;
 	}
 	}
 
 
-	/**
-	 * The API entry point. It exposes the basic features necessary to integrate and extend CKEditor.
-	 * @class CKEDITOR
-	 * @singleton
-	 */
-	var CKEDITOR = root.CKEDITOR = {};
-
-	/**
-	 * Defines an AMD module.
-	 *
-	 * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
-	 */
-	CKEDITOR.define = CKEDITOR.define || define;
-
-	/**
-	 * Retrieves one or more AMD modules. Note that the CKEditor AMD API doesn't download modules on demand so be sure
-	 * to have their relative scripts available in the page.
-	 *
-	 * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
-	 */
-	CKEDITOR.require = CKEDITOR.require || require;
+	root.CKEDITOR = {
+		/**
+		 * Defines an AMD module.
+		 *
+		 * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
+		 *
+		 * @method
+		 * @member CKEDITOR
+		 */
+		define: define,
+
+		/**
+		 * Retrieves one or more AMD modules.
+		 *
+		 * Note that the CKEditor AMD API does not download modules on demand so be sure to have their relative scripts
+		 * available in the page.
+		 *
+		 * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
+		 *
+		 * @method
+		 * @member CKEDITOR
+		 */
+		require: require,
+
+		// Documented in ckeditor-core/src/ckeditor.js.
+		// This is the development version of this method, which overrides the default one.
+		getPluginPath: function( name ) {
+			return CKEDITOR.basePath + 'node_modules/ckeditor-plugin-' + name + '/src/';
+		}
+	};
+
+	// Load the core CKEDITOR object and extend/override some of its methods with the above.
+	require( [ 'ckeditor', 'tools/utils' ], function( CKEDITOR, utils ) {
+		utils.extend( CKEDITOR, root.CKEDITOR );
+		root.CKEDITOR = CKEDITOR;
+	} );
 } )( window );
 } )( window );

+ 3 - 0
gruntfile.js

@@ -18,6 +18,9 @@ module.exports = function( grunt ) {
 
 
 		jshint: {
 		jshint: {
 			options: {
 			options: {
+				globals: {
+					'CKEDITOR': false
+				},
 				ignores: ignoreFiles
 				ignores: ignoreFiles
 			}
 			}
 		},
 		},

+ 29 - 0
src/plugin.js

@@ -0,0 +1,29 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global define */
+
+'use strict';
+
+// 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' );
+
+			if ( path.length === 2 ) {
+				path.push( path[ 0 ] );
+			}
+
+			path = '../../ckeditor5-plugin-' + path.join( '/' );
+
+			require( [ path ], function( value ) {
+				onload( value );
+			} );
+		}
+	};
+} );