extensions.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. ( () => {
  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. }
  16. return load( context, moduleId, url );
  17. };
  18. // Reported: https://github.com/benderjs/benderjs/issues/248
  19. // Ugh... make some paths cleanup, because we need to combine these fragments and we don't want to
  20. // duplicate '/'. BTW. if you want to touch this make sure you haven't broken Bender jobs which
  21. // have different bender.basePaths (no trailing '/', unnecessary 'tests/' fragment).
  22. bender.getCKEditorModuleBasePath = function() {
  23. var appBasePath = bender.basePath;
  24. var ckeditorBasePath = bender.config.applications.ckeditor.basePath;
  25. var modulebasePath;
  26. modulebasePath = appBasePath
  27. .split( '/' )
  28. .filter( nonEmpty )
  29. // When running a job we need to drop the last parth of the base path, which is "tests".
  30. .slice( 0, -1 )
  31. .concat(
  32. ckeditorBasePath.split( '/' ).filter( nonEmpty )
  33. )
  34. .join( '/' );
  35. return '/' + modulebasePath;
  36. };
  37. function nonEmpty( str ) {
  38. return !!str.length;
  39. }
  40. } )();