8
0

ckeditor.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Computes the value of the `basePath` property.
  50. *
  51. * @private
  52. * @method
  53. * @returns {String} A full URL.
  54. */
  55. _getBasePath: getBasePath
  56. };
  57. utilsObject.extend( CKEDITOR, CKEDITOR_CORE );
  58. function getBasePath() {
  59. if ( window.CKEDITOR_BASEPATH ) {
  60. return window.CKEDITOR_BASEPATH;
  61. }
  62. const scripts = document.getElementsByTagName( 'script' );
  63. const basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
  64. let path;
  65. // Find the first script that src matches ckeditor.js.
  66. Array.from( scripts ).some( ( script ) => {
  67. const match = script.src.match( basePathSrcPattern );
  68. if ( match ) {
  69. path = match[ 1 ];
  70. return true;
  71. }
  72. } );
  73. return path;
  74. }
  75. export default CKEDITOR;