ckeditor.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 */
  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. * Whether the app should work in the "debug mode" (aka "verbose mode").
  36. *
  37. * You can use the `CKEDITOR.isDebug` condition in order to wrap code that should be removed in the build version:
  38. *
  39. * if ( CKEDITOR.isDebug ) {
  40. * if ( doSomeSuperUnnecessaryDebugChecks() ) {
  41. * throw new CKEditorError( 'sth-broke: Kaboom!' );
  42. * }
  43. * }
  44. *
  45. * See also {@link #isDev}.
  46. *
  47. * @property
  48. */
  49. isDebug: true,
  50. /**
  51. * Defines an AMD module.
  52. *
  53. * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
  54. *
  55. * @method
  56. * @member CKEDITOR
  57. */
  58. define: function( name, deps ) {
  59. // If this is a named module with dependencies, save this in the dependency list.
  60. if ( Array.isArray( deps ) && name && !this._dependencies[ name ] ) {
  61. this._dependencies[ name ] = deps;
  62. }
  63. return define.apply( this, arguments );
  64. },
  65. /**
  66. * Retrieves one or more AMD modules.
  67. *
  68. * Note that the CKEditor AMD API does not download modules on demand so be sure to have their relative scripts
  69. * available in the page.
  70. *
  71. * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
  72. *
  73. * @method
  74. * @member CKEDITOR
  75. */
  76. require: require
  77. };
  78. requirejs.config( {
  79. // Modules are generally relative to the core project.
  80. baseUrl: CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/',
  81. // These configurations will make no difference in the build version because the following paths will be
  82. // already defined there.
  83. paths: {
  84. // Hide the core "ckeditor" under a different name.
  85. 'ckeditor-core': CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/ckeditor',
  86. // The dev version overrides for the "ckeditor" module. This is empty on release.
  87. 'ckeditor-dev': CKEDITOR.basePath + 'src/ckeditor-dev'
  88. }
  89. } );
  90. // Define a new "ckeditor" module, which overrides the core one with the above and the dev stuff.
  91. define( 'ckeditor', [ 'ckeditor-core', 'ckeditor-dev', 'utils' ], function( core, dev, utils ) {
  92. root.CKEDITOR = utils.extend( {}, core, root.CKEDITOR, ( dev || /* istanbul ignore next */ {} ) );
  93. return root.CKEDITOR;
  94. } );
  95. function getBasePath() {
  96. if ( window.CKEDITOR_BASEPATH ) {
  97. return window.CKEDITOR_BASEPATH;
  98. }
  99. var scripts = document.getElementsByTagName( 'script' );
  100. var basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
  101. var path;
  102. // Find the first script that src matches ckeditor.js.
  103. [].some.call( scripts, function( script ) {
  104. var match = script.src.match( basePathSrcPattern );
  105. if ( match ) {
  106. path = match[ 1 ];
  107. return true;
  108. }
  109. } );
  110. return path;
  111. }
  112. } )( window );