extensions.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* jshint node: false, browser: true, globalstrict: true, varstmt: false */
  6. /* globals bender, requirejs */
  7. 'use strict';
  8. ( function() {
  9. // This seems to be the only way to force Require.JS to load modules starting with '/' from a different path.
  10. var load = requirejs.load;
  11. requirejs.load = function( context, moduleId, url ) {
  12. var basePath = bender.getCKEditorModuleBasePath().replace( /\/$/, '' );
  13. if ( moduleId[ 0 ] == '/' ) {
  14. url = basePath + url;
  15. } else if ( moduleId.startsWith( 'ckeditor5' ) || moduleId.startsWith( 'tests' ) || moduleId.startsWith( 'theme' ) ) {
  16. url = basePath + '/' + url;
  17. }
  18. return load( context, moduleId, url );
  19. };
  20. // Reported: https://github.com/benderjs/benderjs/issues/248
  21. // Ugh... make some paths cleanup, because we need to combine these fragments and we don't want to
  22. // duplicate '/'. BTW. if you want to touch this make sure you haven't broken Bender jobs which
  23. // have different bender.basePaths (no trailing '/', unnecessary 'tests/' fragment).
  24. bender.getCKEditorModuleBasePath = function() {
  25. var appBasePath = bender.basePath;
  26. var ckeditorBasePath = bender.config.applications.ckeditor.basePath;
  27. var modulebasePath;
  28. modulebasePath = appBasePath
  29. .split( '/' )
  30. .filter( nonEmpty )
  31. // When running a job we need to drop the last parth of the base path, which is "tests".
  32. .slice( 0, -1 )
  33. .concat(
  34. ckeditorBasePath.split( '/' ).filter( nonEmpty )
  35. )
  36. .join( '/' );
  37. return '/' + modulebasePath;
  38. };
  39. function nonEmpty( str ) {
  40. return !!str.length;
  41. }
  42. } )();