8
0

ckeditor.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. // This file is shared by the dev and release versions of CKEditor. It bootstraps the API.
  7. import CKEDITOR_CORE from './ckeditor5-core/ckeditor.js';
  8. import utilsObject from './ckeditor5-core/lib/lodash/object.js';
  9. const CKEDITOR = {
  10. /**
  11. * The full URL for the CKEditor installation directory.
  12. *
  13. * It is possible to manually provide the base path by setting a global variable named `CKEDITOR_BASEPATH`. This
  14. * global variable must be set **before** the editor script loading.
  15. *
  16. * console.log( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/'
  17. *
  18. * @readonly
  19. * @property {String}
  20. */
  21. basePath: getBasePath(),
  22. /**
  23. * Whether the app should work in the "debug mode" (aka "verbose mode").
  24. *
  25. * You can use the `CKEDITOR.isDebug` condition in order to wrap code that should be removed in the build version:
  26. *
  27. * if ( CKEDITOR.isDebug ) {
  28. * if ( doSomeSuperUnnecessaryDebugChecks() ) {
  29. * throw new CKEditorError( 'sth-broke: Kaboom!' );
  30. * }
  31. * }
  32. *
  33. * See also {@link #isDev}.
  34. *
  35. * @readonly
  36. */
  37. isDebug: true,
  38. /**
  39. * A flag specifying whether CKEditor is running in development mode (original source code).
  40. *
  41. * This property is not defined in production (compiled, build code).
  42. *
  43. * See also {@link #isDebug}.
  44. *
  45. * @readonly
  46. */
  47. isDev: true,
  48. /**
  49. * Resolves a simplified module name convention to a real path. The returned
  50. * paths are relative to the main `ckeditor.js` file, but they do not start with `./`.
  51. *
  52. * For instance:
  53. *
  54. * * `foo` will be transformed to `ckeditor5-foo/foo.js`,
  55. * * `ckeditor` to `ckeditor.js`,
  56. * * `core/editor` to `ckeditor5-core/editor.js` and
  57. * * `foo/bar/bom` to `ckeditor5-foo/bar/bom.js`.
  58. *
  59. * @param {String} name
  60. * @returns {String} Path to the module.
  61. */
  62. getModulePath( name ) {
  63. //
  64. // Note: This piece of code is duplicated in bender.amd.getModulePath().
  65. //
  66. if ( name != 'ckeditor' ) {
  67. // Resolve shortened feature names to `featureName/featureName`.
  68. if ( name.indexOf( '/' ) < 0 ) {
  69. name = name + '/' + name;
  70. }
  71. // Add the prefix to shortened paths like `core/editor` (will be `ckeditor5-core/editor`).
  72. // Don't add the prefix to the main file and files frok ckeditor5/ module.
  73. if ( !( /^ckeditor5\//.test( name ) ) ) {
  74. name = 'ckeditor5-' + name;
  75. }
  76. }
  77. return name + '.js';
  78. },
  79. /**
  80. * Computes the value of the `basePath` property.
  81. *
  82. * @private
  83. * @method
  84. * @returns {String} A full URL.
  85. */
  86. _getBasePath: getBasePath
  87. };
  88. utilsObject.extend( CKEDITOR, CKEDITOR_CORE );
  89. function getBasePath() {
  90. if ( window.CKEDITOR_BASEPATH ) {
  91. return window.CKEDITOR_BASEPATH;
  92. }
  93. const scripts = document.getElementsByTagName( 'script' );
  94. const basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
  95. let path;
  96. // Find the first script that src matches ckeditor.js.
  97. Array.from( scripts ).some( ( script ) => {
  98. const match = script.src.match( basePathSrcPattern );
  99. if ( match ) {
  100. path = match[ 1 ];
  101. return true;
  102. }
  103. } );
  104. return path;
  105. }
  106. export default CKEDITOR;