ckeditor.js 2.9 KB

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