main.js
92 lines
| 2.5 KiB
| application/javascript
|
JavascriptLexer
|
r19010 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
require([ | ||||
|
r20063 | 'jquery', | ||
|
r19013 | 'base/js/namespace', | ||
|
r19010 | 'base/js/utils', | ||
'base/js/page', | ||||
|
r19012 | 'base/js/events', | ||
|
r19011 | 'contents', | ||
|
r19082 | 'services/config', | ||
|
r19074 | 'edit/js/editor', | ||
'edit/js/menubar', | ||||
|
r19316 | 'edit/js/savewidget', | ||
|
r19074 | 'edit/js/notificationarea', | ||
|
r19010 | 'custom/custom', | ||
], function( | ||||
|
r20063 | $, | ||
|
r19013 | IPython, | ||
|
r19010 | utils, | ||
page, | ||||
|
r19012 | events, | ||
|
r19011 | contents, | ||
|
r19082 | configmod, | ||
|
r19304 | editmod, | ||
|
r19017 | menubar, | ||
|
r19316 | savewidget, | ||
|
r19017 | notificationarea | ||
|
r19010 | ){ | ||
page = new page.Page(); | ||||
var base_url = utils.get_body_data('baseUrl'); | ||||
|
r19011 | var file_path = utils.get_body_data('filePath'); | ||
|
r19013 | contents = new contents.Contents({base_url: base_url}); | ||
|
r19304 | var config = new configmod.ConfigSection('edit', {base_url: base_url}); | ||
|
r19082 | config.load(); | ||
|
r19635 | var common_config = new configmod.ConfigSection('common', {base_url: base_url}); | ||
|
r19633 | common_config.load(); | ||
|
r19013 | |||
|
r19304 | var editor = new editmod.Editor('#texteditor-container', { | ||
|
r19013 | base_url: base_url, | ||
events: events, | ||||
contents: contents, | ||||
file_path: file_path, | ||||
|
r19303 | config: config, | ||
|
r19011 | }); | ||
|
r19013 | |||
// Make it available for debugging | ||||
IPython.editor = editor; | ||||
|
r19317 | var save_widget = new savewidget.SaveWidget('span#save_widget', { | ||
|
r19013 | editor: editor, | ||
|
r19303 | events: events, | ||
|
r19013 | }); | ||
|
r19017 | |||
|
r19317 | var menus = new menubar.MenuBar('#menubar', { | ||
base_url: base_url, | ||||
|
r19316 | editor: editor, | ||
events: events, | ||||
|
r19317 | save_widget: save_widget, | ||
|
r19316 | }); | ||
|
r19017 | var notification_area = new notificationarea.EditorNotificationArea( | ||
'#notification_area', { | ||||
events: events, | ||||
}); | ||||
notification_area.init_notification_widgets(); | ||||
|
r19013 | |||
|
r19633 | utils.load_extensions_from_config(config); | ||
utils.load_extensions_from_config(common_config); | ||||
|
r19013 | editor.load(); | ||
page.show(); | ||||
|
r19304 | |||
window.onbeforeunload = function () { | ||||
|
r19337 | if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) { | ||
|
r19304 | return "Unsaved changes will be lost. Close anyway?"; | ||
} | ||||
}; | ||||
|
r20063 | // Make sure the codemirror editor is sized appropriatley. | ||
var _handle_resize = function() { | ||||
|
r20167 | var backdrop = $("#texteditor-backdrop"); | ||
|
r20070 | |||
|
r20167 | // account for padding on the backdrop wrapper | ||
var padding = backdrop.outerHeight(true) - backdrop.height(); | ||||
$('div.CodeMirror').height($("#site").height() - padding); | ||||
|
r20063 | }; | ||
|
r20107 | $(window).resize(_handle_resize); | ||
|
r20063 | |||
// On document ready, resize codemirror. | ||||
|
r20086 | $(document).ready(_handle_resize); | ||
|
r19010 | }); | ||