Przeglądaj źródła

Extracted all things from CKEDITOR object to avoid circ deps.

Piotrek Koszuliński 10 lat temu
rodzic
commit
eb4747200b

+ 1 - 116
ckeditor.js

@@ -5,121 +5,6 @@
 
 'use strict';
 
-// This file is shared by the dev and release versions of CKEditor. It bootstraps the API.
-
-import CKEDITOR_CORE from './ckeditor5-core/ckeditor.js';
-import utilsObject from './ckeditor5-core/lib/lodash/object.js';
-
-const CKEDITOR = {
-	/**
-	 * The full URL for the CKEditor installation directory.
-	 *
-	 * It is possible to manually provide the base path by setting a global variable named `CKEDITOR_BASEPATH`. This
-	 * global variable must be set **before** the editor script loading.
-	 *
-	 *		console.log( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/'
-	 *
-	 * @readonly
-	 * @property {String}
-	 */
-	basePath: getBasePath(),
-
-	/**
-	 * Whether the app should work in the "debug mode" (aka "verbose mode").
-	 *
-	 * You can use the `CKEDITOR.isDebug` condition in order to wrap code that should be removed in the build version:
-	 *
-	 *		if ( CKEDITOR.isDebug ) {
-	 *			if ( doSomeSuperUnnecessaryDebugChecks() ) {
-	 *				throw new CKEditorError( 'sth-broke: Kaboom!' );
-	 *			}
-	 *		}
-	 *
-	 * See also {@link #isDev}.
-	 *
-	 * @readonly
-	 */
-	isDebug: true,
-
-	/**
-	 * A flag specifying whether CKEditor is running in development mode (original source code).
-	 *
-	 * This property is not defined in production (compiled, build code).
-	 *
-	 * See also {@link #isDebug}.
-	 *
-	 * @readonly
-	 */
-	isDev: true,
-
-	/**
-	 * Resolves a simplified module name convention to a real path. The returned
-	 * paths are relative to the main `ckeditor.js` file, but they do not start with `./`.
-	 *
-	 * For instance:
-	 *
-	 * * `foo` will be transformed to `ckeditor5-foo/foo.js`,
-	 * * `ckeditor` to `ckeditor.js`,
-	 * * `core/editor` to `ckeditor5-core/editor.js` and
-	 * * `foo/bar/bom` to `ckeditor5-foo/bar/bom.js`.
-	 *
-	 * @param {String} name
-	 * @returns {String} Path to the module.
-	 */
-	getModulePath( name ) {
-		//
-		// Note: This piece of code is duplicated in bender.amd.getModulePath().
-		//
-
-		if ( name != 'ckeditor' ) {
-			// Resolve shortened feature names to `featureName/featureName`.
-			if ( name.indexOf( '/' ) < 0 ) {
-				name = name + '/' + name;
-			}
-
-			// Add the prefix to shortened paths like `core/editor` (will be `ckeditor5-core/editor`).
-			// Don't add the prefix to the main file and files frok ckeditor5/ module.
-			if ( !( /^ckeditor5\//.test( name ) ) ) {
-				name = 'ckeditor5-' + name;
-			}
-		}
-
-		return name + '.js';
-	},
-
-	/**
-	 * Computes the value of the `basePath` property.
-	 *
-	 * @private
-	 * @method
-	 * @returns {String} A full URL.
-	 */
-	_getBasePath: getBasePath
-};
-
-utilsObject.extend( CKEDITOR, CKEDITOR_CORE );
-
-function getBasePath() {
-	if ( window.CKEDITOR_BASEPATH ) {
-		return window.CKEDITOR_BASEPATH;
-	}
-
-	const scripts = document.getElementsByTagName( 'script' );
-	const basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
-	let path;
-
-	// Find the first script that src matches ckeditor.js.
-	Array.from( scripts ).some( ( script ) => {
-		const match = script.src.match( basePathSrcPattern );
-
-		if ( match ) {
-			path = match[ 1 ];
-
-			return true;
-		}
-	} );
-
-	return path;
-}
+import CKEDITOR from './ckeditor5-core/ckeditor.js';
 
 export default CKEDITOR;

+ 1 - 1
dev/bender/plugins/ckeditor5/static/amd.js

@@ -18,7 +18,7 @@
 		 * generating a base path for that file, taking into account whether a Bender job is being run
 		 * or a simple test.
 		 *
-		 * The name should be given in a simplified features naming convention. See {@link CKEDITOR#getModulePath}
+		 * The name should be given in a simplified features naming convention. See {@link ckeditor5/path#getModulePath}
 		 * for more details.
 		 *
 		 * @param {String} name The name of the module.

+ 90 - 0
src/path.js

@@ -0,0 +1,90 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const path = {
+	/**
+	 * The full URL for the CKEditor installation directory.
+	 *
+	 * It is possible to manually provide the base path by setting a global variable named `CKEDITOR_BASEPATH`. This
+	 * global variable must be set **before** the editor script loading.
+	 *
+	 *		console.log( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/'
+	 *
+	 * @readonly
+	 * @property {String}
+	 */
+	basePath: getBasePath(),
+
+	/**
+	 * Resolves a simplified module name convention to a real path. The returned
+	 * paths are relative to the main `ckeditor.js` file, but they do not start with `./`.
+	 *
+	 * For instance:
+	 *
+	 * * `foo` will be transformed to `ckeditor5-foo/foo.js`,
+	 * * `ckeditor` to `ckeditor.js`,
+	 * * `core/editor` to `ckeditor5-core/editor.js` and
+	 * * `foo/bar/bom` to `ckeditor5-foo/bar/bom.js`.
+	 *
+	 * @param {String} name
+	 * @returns {String} Path to the module.
+	 */
+	getModulePath( name ) {
+		//
+		// Note: This piece of code is duplicated in bender.amd.getModulePath().
+		//
+
+		if ( name != 'ckeditor' ) {
+			// Resolve shortened feature names to `featureName/featureName`.
+			if ( name.indexOf( '/' ) < 0 ) {
+				name = name + '/' + name;
+			}
+
+			// Add the prefix to shortened paths like `core/editor` (will be `ckeditor5-core/editor`).
+			// Don't add the prefix to the main file and files frok ckeditor5/ module.
+			if ( !( /^ckeditor5\//.test( name ) ) ) {
+				name = 'ckeditor5-' + name;
+			}
+		}
+
+		return name + '.js';
+	},
+
+	/**
+	 * Computes the value of the `basePath` property.
+	 *
+	 * @private
+	 * @method
+	 * @returns {String} A full URL.
+	 */
+	_getBasePath: getBasePath
+};
+
+function getBasePath() {
+	if ( window.CKEDITOR_BASEPATH ) {
+		return window.CKEDITOR_BASEPATH;
+	}
+
+	const scripts = document.getElementsByTagName( 'script' );
+	const basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
+	let path;
+
+	// Find the first script that src matches ckeditor.js.
+	Array.from( scripts ).some( ( script ) => {
+		const match = script.src.match( basePathSrcPattern );
+
+		if ( match ) {
+			path = match[ 1 ];
+
+			return true;
+		}
+	} );
+
+	return path;
+}
+
+export default path;

+ 19 - 0
tests/ckeditor.js

@@ -0,0 +1,19 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const modules = bender.amd.require( 'ckeditor' );
+let CKEDITOR;
+
+before( () => {
+	CKEDITOR = modules.ckeditor;
+} );
+
+describe( 'CKEDITOR', () => {
+	it( 'is an object', () => {
+		expect( CKEDITOR ).to.be.an( 'object' );
+	} );
+} );

+ 0 - 51
tests/ckeditor/ckeditor.js

@@ -1,51 +0,0 @@
-/**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-const modules = bender.amd.require( 'ckeditor' );
-let CKEDITOR;
-
-before( () => {
-	CKEDITOR = modules.ckeditor;
-} );
-
-describe( 'isDebug', () => {
-	it( 'is a boolean', () => {
-		expect( CKEDITOR.isDebug ).to.be.a( 'boolean' );
-	} );
-} );
-
-describe( 'getModulePath()', () => {
-	it( 'generates path for the main file', () => {
-		const path = CKEDITOR.getModulePath( 'ckeditor' );
-
-		expect( path ).to.equal( 'ckeditor.js' );
-	} );
-
-	it( 'generates path for modules within ckeditor5 package', () => {
-		const path = CKEDITOR.getModulePath( 'ckeditor5/foo' );
-
-		expect( path ).to.equal( 'ckeditor5/foo.js' );
-	} );
-
-	it( 'generates path for modules within the core package', () => {
-		const path = CKEDITOR.getModulePath( 'core/ui/controller' );
-
-		expect( path ).to.equal( 'ckeditor5-core/ui/controller.js' );
-	} );
-
-	it( 'generates path for modules within some package', () => {
-		const path = CKEDITOR.getModulePath( 'some/ba' );
-
-		expect( path ).to.equal( 'ckeditor5-some/ba.js' );
-	} );
-
-	it( 'generates path from simplified feature name', () => {
-		const path = CKEDITOR.getModulePath( 'foo' );
-
-		expect( path ).to.equal( 'ckeditor5-foo/foo.js' );
-	} );
-} );

+ 5 - 5
tests/ckeditor/load.js → tests/load.js

@@ -5,11 +5,11 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'ckeditor', 'ckeditor5/load' );
-let CKEDITOR, load;
+const modules = bender.amd.require( 'ckeditor5/path', 'ckeditor5/load' );
+let load, path;
 
 before( () => {
-	CKEDITOR = modules.ckeditor;
+	path = modules[ 'ckeditor5/path' ];
 	load = modules[ 'ckeditor5/load' ];
 } );
 
@@ -17,12 +17,12 @@ describe( 'load()', () => {
 	it( 'loads ckeditor.js', () => {
 		return load( 'ckeditor.js' )
 			.then( ( CKEDITORModule ) => {
-				expect( CKEDITORModule.default ).to.equal( CKEDITOR );
+				expect( CKEDITORModule.default ).to.have.property( 'create' );
 			} );
 	} );
 
 	it( 'loads core/editor', () => {
-		return load( CKEDITOR.getModulePath( 'core/editor' ) )
+		return load( path.getModulePath( 'core/editor' ) )
 			.then( ( EditorModule ) => {
 				expect( EditorModule.default ).to.be.a( 'function' );
 			} );

+ 9 - 8
tests/ckeditor/basepath.js → tests/path/basepath.js

@@ -5,7 +5,12 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'ckeditor' );
+const modules = bender.amd.require( 'ckeditor5/path' );
+let path;
+
+before( () => {
+	path = modules[ 'ckeditor5/path' ];
+} );
 
 beforeEach( () => {
 	// Ensure that no CKEDITOR_BASEPATH global is available.
@@ -24,22 +29,18 @@ describe( 'basePath', () => {
 	testGetBasePathFromTag( '../ckeditor/foo/ckeditor.JS', /\/ckeditor\/foo\/$/ );
 
 	it( 'should work with the CKEDITOR_BASEPATH global', () => {
-		const CKEDITOR = modules.ckeditor;
-
 		window.CKEDITOR_BASEPATH = 'http://foo.com/ckeditor/';
-		expect( CKEDITOR._getBasePath() ).to.equal( 'http://foo.com/ckeditor/' );
+		expect( path._getBasePath() ).to.equal( 'http://foo.com/ckeditor/' );
 	} );
 
 	function testGetBasePathFromTag( url, expectedBasePath ) {
 		it( 'should work with script tags - ' + url, () => {
-			const CKEDITOR = modules.ckeditor;
-
 			addScript( url );
 
 			if ( typeof expectedBasePath == 'string' ) {
-				expect( CKEDITOR._getBasePath() ).to.equal( expectedBasePath );
+				expect( path._getBasePath() ).to.equal( expectedBasePath );
 			} else {
-				expect( CKEDITOR._getBasePath() ).to.match( expectedBasePath );
+				expect( path._getBasePath() ).to.match( expectedBasePath );
 			}
 		} );
 	}

+ 45 - 0
tests/path/getmodulepath.js

@@ -0,0 +1,45 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const modules = bender.amd.require( 'ckeditor5/path' );
+let path;
+
+before( () => {
+	path = modules[ 'ckeditor5/path' ];
+} );
+
+describe( 'getModulePath()', () => {
+	it( 'generates path for the main file', () => {
+		const p = path.getModulePath( 'ckeditor' );
+
+		expect( p ).to.equal( 'ckeditor.js' );
+	} );
+
+	it( 'generates path for modules within ckeditor5 package', () => {
+		const p = path.getModulePath( 'ckeditor5/foo' );
+
+		expect( p ).to.equal( 'ckeditor5/foo.js' );
+	} );
+
+	it( 'generates path for modules within the core package', () => {
+		const p = path.getModulePath( 'core/ui/controller' );
+
+		expect( p ).to.equal( 'ckeditor5-core/ui/controller.js' );
+	} );
+
+	it( 'generates path for modules within some package', () => {
+		const p = path.getModulePath( 'some/ba' );
+
+		expect( p ).to.equal( 'ckeditor5-some/ba.js' );
+	} );
+
+	it( 'generates path from simplified feature name', () => {
+		const p = path.getModulePath( 'foo' );
+
+		expect( p ).to.equal( 'ckeditor5-foo/foo.js' );
+	} );
+} );