main.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. requirejs([
  4. 'jquery',
  5. 'contents',
  6. 'base/js/namespace',
  7. 'base/js/utils',
  8. 'base/js/page',
  9. 'base/js/events',
  10. 'services/config',
  11. 'edit/js/editor',
  12. 'edit/js/menubar',
  13. 'edit/js/savewidget',
  14. 'edit/js/notificationarea',
  15. 'bidi/bidi',
  16. ], function(
  17. $,
  18. contents_service,
  19. IPython,
  20. utils,
  21. page,
  22. events,
  23. configmod,
  24. editmod,
  25. menubar,
  26. savewidget,
  27. notificationarea,
  28. bidi
  29. ){
  30. "use strict";
  31. try {
  32. requirejs(['custom/custom'], function() {});
  33. bidi.loadLocale();
  34. } catch(err) {
  35. console.log("Error loading custom.js from edition service. Continuing and logging");
  36. console.warn(err);
  37. }
  38. page = new page.Page('div#header', 'div#site');
  39. var base_url = utils.get_body_data('baseUrl');
  40. var file_path = utils.get_body_data('filePath');
  41. var config = new configmod.ConfigSection('edit', {base_url: base_url});
  42. config.load();
  43. var common_config = new configmod.ConfigSection('common', {base_url: base_url});
  44. common_config.load();
  45. var contents = new contents_service.Contents({
  46. base_url: base_url,
  47. common_config: common_config
  48. });
  49. var editor = new editmod.Editor('#texteditor-container', {
  50. base_url: base_url,
  51. events: events,
  52. contents: contents,
  53. file_path: file_path,
  54. config: config,
  55. });
  56. // Make it available for debugging
  57. IPython.editor = editor;
  58. var save_widget = new savewidget.SaveWidget('span#save_widget', {
  59. editor: editor,
  60. events: events,
  61. });
  62. var menus = new menubar.MenuBar('#menubar', {
  63. base_url: base_url,
  64. editor: editor,
  65. events: events,
  66. save_widget: save_widget,
  67. });
  68. var notification_area = new notificationarea.EditorNotificationArea(
  69. '#notification_area', {
  70. events: events,
  71. });
  72. editor.notification_area = notification_area;
  73. notification_area.init_notification_widgets();
  74. utils.load_extensions_from_config(config);
  75. utils.load_extensions_from_config(common_config);
  76. editor.load();
  77. page.show();
  78. window.onbeforeunload = function () {
  79. if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) {
  80. return "Unsaved changes will be lost. Close anyway?";
  81. }
  82. };
  83. // Make sure the codemirror editor is sized appropriatley.
  84. var _handle_resize = function() {
  85. var backdrop = $("#texteditor-backdrop");
  86. // account for padding on the backdrop wrapper
  87. var padding = backdrop.outerHeight(true) - backdrop.height();
  88. $('div.CodeMirror').height($("#site").height() - padding);
  89. };
  90. $(window).resize(_handle_resize);
  91. // On document ready, resize codemirror.
  92. $(document).ready(_handle_resize);
  93. });