##// END OF EJS Templates
Be a little more clear about sizing logic.
Jonathan Frederic -
Show More
@@ -1,90 +1,97 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 require([
4 require([
5 'jquery',
5 'jquery',
6 'base/js/namespace',
6 'base/js/namespace',
7 'base/js/utils',
7 'base/js/utils',
8 'base/js/page',
8 'base/js/page',
9 'base/js/events',
9 'base/js/events',
10 'contents',
10 'contents',
11 'services/config',
11 'services/config',
12 'edit/js/editor',
12 'edit/js/editor',
13 'edit/js/menubar',
13 'edit/js/menubar',
14 'edit/js/savewidget',
14 'edit/js/savewidget',
15 'edit/js/notificationarea',
15 'edit/js/notificationarea',
16 'custom/custom',
16 'custom/custom',
17 ], function(
17 ], function(
18 $,
18 $,
19 IPython,
19 IPython,
20 utils,
20 utils,
21 page,
21 page,
22 events,
22 events,
23 contents,
23 contents,
24 configmod,
24 configmod,
25 editmod,
25 editmod,
26 menubar,
26 menubar,
27 savewidget,
27 savewidget,
28 notificationarea
28 notificationarea
29 ){
29 ){
30 page = new page.Page();
30 page = new page.Page();
31
31
32 var base_url = utils.get_body_data('baseUrl');
32 var base_url = utils.get_body_data('baseUrl');
33 var file_path = utils.get_body_data('filePath');
33 var file_path = utils.get_body_data('filePath');
34 contents = new contents.Contents({base_url: base_url});
34 contents = new contents.Contents({base_url: base_url});
35 var config = new configmod.ConfigSection('edit', {base_url: base_url});
35 var config = new configmod.ConfigSection('edit', {base_url: base_url});
36 config.load();
36 config.load();
37 var common_config = new configmod.ConfigSection('common', {base_url: base_url});
37 var common_config = new configmod.ConfigSection('common', {base_url: base_url});
38 common_config.load();
38 common_config.load();
39
39
40 var editor = new editmod.Editor('#texteditor-container', {
40 var editor = new editmod.Editor('#texteditor-container', {
41 base_url: base_url,
41 base_url: base_url,
42 events: events,
42 events: events,
43 contents: contents,
43 contents: contents,
44 file_path: file_path,
44 file_path: file_path,
45 config: config,
45 config: config,
46 });
46 });
47
47
48 // Make it available for debugging
48 // Make it available for debugging
49 IPython.editor = editor;
49 IPython.editor = editor;
50
50
51 var save_widget = new savewidget.SaveWidget('span#save_widget', {
51 var save_widget = new savewidget.SaveWidget('span#save_widget', {
52 editor: editor,
52 editor: editor,
53 events: events,
53 events: events,
54 });
54 });
55
55
56 var menus = new menubar.MenuBar('#menubar', {
56 var menus = new menubar.MenuBar('#menubar', {
57 base_url: base_url,
57 base_url: base_url,
58 editor: editor,
58 editor: editor,
59 events: events,
59 events: events,
60 save_widget: save_widget,
60 save_widget: save_widget,
61 });
61 });
62
62
63 var notification_area = new notificationarea.EditorNotificationArea(
63 var notification_area = new notificationarea.EditorNotificationArea(
64 '#notification_area', {
64 '#notification_area', {
65 events: events,
65 events: events,
66 });
66 });
67 notification_area.init_notification_widgets();
67 notification_area.init_notification_widgets();
68
68
69 utils.load_extensions_from_config(config);
69 utils.load_extensions_from_config(config);
70 utils.load_extensions_from_config(common_config);
70 utils.load_extensions_from_config(common_config);
71 editor.load();
71 editor.load();
72 page.show();
72 page.show();
73
73
74 window.onbeforeunload = function () {
74 window.onbeforeunload = function () {
75 if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) {
75 if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) {
76 return "Unsaved changes will be lost. Close anyway?";
76 return "Unsaved changes will be lost. Close anyway?";
77 }
77 }
78 };
78 };
79
79
80 // Make sure the codemirror editor is sized appropriatley.
80 // Make sure the codemirror editor is sized appropriatley.
81 var _handle_resize = function() {
81 var _handle_resize = function() {
82 var header = $('#header');
82 var header = $('#header');
83 var padding = header.outerHeight(true) - header.innerHeight();
83
84 $('div.CodeMirror').height(window.innerHeight - header.height() - 2*padding);
84 // The header doesn't have a margin or padding above it. Calculate
85 // the lower margin&padding by subtracting the innerHeight from the
86 // outerHeight.
87 var header_margin_bottom = header.outerHeight(true) - header.innerHeight();
88
89 // When scaling CodeMirror, subtract the header lower margin from the
90 // height twice. Once for top padding and once for bottom padding.
91 $('div.CodeMirror').height(window.innerHeight - header.height() - 2*header_margin_bottom);
85 };
92 };
86 window.onresize = _handle_resize;
93 window.onresize = _handle_resize;
87
94
88 // On document ready, resize codemirror.
95 // On document ready, resize codemirror.
89 $(_handle_resize);
96 $(_handle_resize);
90 });
97 });
General Comments 0
You need to be logged in to leave comments. Login now