dev-setup.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (function() {
  2. self.loadDevEditor = function() {
  3. return (getQueryStringValue('editor') === 'dev');
  4. }
  5. function getQueryStringValue (key) {
  6. return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
  7. }
  8. function resolveCorePath(core) {
  9. if (loadDevEditor()) {
  10. return core.srcPath;
  11. } else {
  12. return '/monaco-editor/' + core.path;
  13. }
  14. }
  15. function resolvePluginPath(plugin) {
  16. if (plugin.srcPath && getQueryStringValue(plugin.name) === 'dev') {
  17. return plugin.srcPath;
  18. } else {
  19. return '/monaco-editor/' + plugin.path;
  20. }
  21. }
  22. self.RESOLVED_CORE_PATH = resolveCorePath(METADATA.CORE);
  23. var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
  24. return {
  25. name: plugin.name,
  26. contrib: plugin.contrib,
  27. modulePrefix: plugin.modulePrefix,
  28. path: resolvePluginPath(plugin)
  29. };
  30. });
  31. self.METADATA = null;
  32. self.loadEditor = function(callback, PATH_PREFIX) {
  33. PATH_PREFIX = PATH_PREFIX || '';
  34. var pathsConfig = {};
  35. RESOLVED_PLUGINS.forEach(function(plugin) {
  36. pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
  37. });
  38. pathsConfig['vs'] = PATH_PREFIX + RESOLVED_CORE_PATH;
  39. var loaderInfo = document.createElement('div');
  40. loaderInfo.style.position = 'fixed';
  41. loaderInfo.style.top = 0;
  42. loaderInfo.style.right = 0;
  43. loaderInfo.innerHTML = 'LOADER PATH CONFIGURATION: ' + '<br/><pre>' + JSON.stringify(pathsConfig, null, '\t') + '</pre>';
  44. document.body.appendChild(loaderInfo);
  45. require.config({
  46. paths: pathsConfig
  47. });
  48. require(['vs/editor/editor.main'], function() {
  49. // At this point we've loaded the monaco-editor-core
  50. require(RESOLVED_PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
  51. // At this point we've loaded all the plugins
  52. callback();
  53. // require(['./index'], function() {});
  54. });
  55. });
  56. }
  57. })();