ckeditor.js 3.2 KB

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