ckeditor.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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, location */
  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 full URL for the CKEditor installation directory.
  20. *
  21. * It is possible to manually provide the base path by setting a global variable named `CKEDITOR_BASEPATH`. This
  22. * global variable must be set **before** the editor script loading.
  23. *
  24. * console.log( CKEDITOR.basePath ); // e.g. 'http://www.example.com/ckeditor/'
  25. *
  26. * @property {String}
  27. */
  28. basePath: getBasePath(),
  29. /**
  30. * Defines an AMD module.
  31. *
  32. * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
  33. *
  34. * @method
  35. * @member CKEDITOR
  36. */
  37. define: define,
  38. /**
  39. * Retrieves one or more AMD modules.
  40. *
  41. * Note that the CKEditor AMD API does not download modules on demand so be sure to have their relative scripts
  42. * available in the page.
  43. *
  44. * See https://github.com/ckeditor/ckeditor5-design/wiki/AMD for more details about our AMD API.
  45. *
  46. * @method
  47. * @member CKEDITOR
  48. */
  49. require: require
  50. };
  51. requirejs.config( {
  52. // Modules are generally relative to the core project.
  53. baseUrl: CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/',
  54. // These configurations will make no difference in the build version because the following paths will be
  55. // already defined there.
  56. paths: {
  57. // Hide the core "ckeditor" under a different name.
  58. 'ckeditor-core': CKEDITOR.basePath + 'node_modules/ckeditor5-core/src/ckeditor',
  59. // The dev version overrides for the "ckeditor" module. This is empty on release.
  60. 'ckeditor-dev': CKEDITOR.basePath + 'src/ckeditor-dev'
  61. }
  62. } );
  63. // Define a new "ckeditor" module, which overrides the core one with the above and the dev stuff.
  64. define( 'ckeditor', [ 'ckeditor-core', 'ckeditor-dev', 'utils' ], function( core, dev, utils ) {
  65. utils.extend( core, root.CKEDITOR, ( dev || {} ) );
  66. root.CKEDITOR = core;
  67. return core;
  68. } );
  69. function getBasePath() {
  70. if ( window.CKEDITOR_BASEPATH ) {
  71. return window.CKEDITOR_BASEPATH;
  72. }
  73. var scripts = document.getElementsByTagName( 'script' );
  74. var basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;
  75. var path;
  76. // Find the first script that src matches ckeditor.js.
  77. [].some.call( scripts, function( script ) {
  78. var match = script.src.match( basePathSrcPattern );
  79. if ( match ) {
  80. path = match[ 1 ];
  81. return true;
  82. }
  83. } );
  84. if ( path.indexOf( ':/' ) == -1 && path.slice( 0, 2 ) != '//' ) {
  85. if ( path.indexOf( '/' ) === 0 ) {
  86. path = location.href.match( /^.*?:\/\/[^\/]*/ )[ 0 ] + path;
  87. } else {
  88. path = location.href.match( /^[^\?]*\/(?:)/ )[ 0 ] + path;
  89. }
  90. }
  91. return path;
  92. }
  93. } )( window );