ckeditor.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global requirejs, define, require, window, document */
  6. 'use strict';
  7. // This file is shared by the dev and release versions of CKEditor. It bootstraps the API.
  8. ( function( root ) {
  9. var CKEDITOR = root.CKEDITOR = {
  10. /**
  11. * Computes the value of the `basePath` property.
  12. *
  13. * @private
  14. * @method
  15. * @returns {String} A full URL.
  16. */
  17. _getBasePath: getBasePath,
  18. /**
  19. * The list of dependencies of **named** AMD modules created with `CKEDITOR.define`. This is mainly used to
  20. * trace the dependency tree of plugins.
  21. */
  22. _dependencies: {},
  23. /**
  24. * The full URL for the CKEditor installation directory.
  25. *
  26. * It is possible to manually provide the base path by setting a global variable named `CKEDITOR_BASEPATH`. This
  27. * global variable must be set **before** the editor script loading.
  28. *
  29. * console.log( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/'
  30. *
  31. * @property {String}
  32. */
  33. basePath: getBasePath(),
  34. /**
  35. * Defines an AMD module.
  36. *
  37. * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
  38. *
  39. * @method
  40. * @member CKEDITOR
  41. */
  42. define: function( name, deps ) {
  43. // If this is a named module with dependencies, save this in the dependency list.
  44. if ( Array.isArray( deps ) && name && !this._dependencies[ name ] ) {
  45. this._dependencies[ name ] = deps;
  46. }
  47. return define.apply( this, arguments );
  48. },
  49. /**
  50. * Retrieves one or more AMD modules.
  51. *
  52. * Note that the CKEditor AMD API does not download modules on demand so be sure to have their relative scripts
  53. * available in the page.
  54. *
  55. * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
  56. *
  57. * @method
  58. * @member CKEDITOR
  59. */
  60. require: require
  61. };
  62. requirejs.config( {
  63. // Modules are generally relative to the core project.
  64. baseUrl: CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/',
  65. // These configurations will make no difference in the build version because the following paths will be
  66. // already defined there.
  67. paths: {
  68. // Hide the core "ckeditor" under a different name.
  69. 'ckeditor-core': CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/ckeditor',
  70. // The dev version overrides for the "ckeditor" module. This is empty on release.
  71. 'ckeditor-dev': CKEDITOR.basePath + 'src/ckeditor-dev'
  72. }
  73. } );
  74. // Define a new "ckeditor" module, which overrides the core one with the above and the dev stuff.
  75. define( 'ckeditor', [ 'ckeditor-core', 'ckeditor-dev', 'utils' ], function( core, dev, utils ) {
  76. root.CKEDITOR = utils.extend( {}, core, root.CKEDITOR, ( dev || /* istanbul ignore next */ {} ) );
  77. return root.CKEDITOR;
  78. } );
  79. function getBasePath() {
  80. if ( window.CKEDITOR_BASEPATH ) {
  81. return window.CKEDITOR_BASEPATH;
  82. }
  83. var scripts = document.getElementsByTagName( 'script' );
  84. var basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
  85. var path;
  86. // Find the first script that src matches ckeditor.js.
  87. [].some.call( scripts, function( script ) {
  88. var match = script.src.match( basePathSrcPattern );
  89. if ( match ) {
  90. path = match[ 1 ];
  91. return true;
  92. }
  93. } );
  94. return path;
  95. }
  96. } )( window );