##// END OF EJS Templates
Fix instantiating config in editor and terminal
Thomas Kluyver -
Show More
@@ -1,78 +1,78
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 require([
5 5 'base/js/namespace',
6 6 'base/js/utils',
7 7 'base/js/page',
8 8 'base/js/events',
9 9 'contents',
10 10 'services/config',
11 11 'edit/js/editor',
12 12 'edit/js/menubar',
13 13 'edit/js/savewidget',
14 14 'edit/js/notificationarea',
15 15 'custom/custom',
16 16 ], function(
17 17 IPython,
18 18 utils,
19 19 page,
20 20 events,
21 21 contents,
22 22 configmod,
23 23 editmod,
24 24 menubar,
25 25 savewidget,
26 26 notificationarea
27 27 ){
28 28 page = new page.Page();
29 29
30 30 var base_url = utils.get_body_data('baseUrl');
31 31 var file_path = utils.get_body_data('filePath');
32 32 contents = new contents.Contents({base_url: base_url});
33 33 var config = new configmod.ConfigSection('edit', {base_url: base_url});
34 34 config.load();
35 var common_config = new configmod.ConfigSection('common', common_options);
35 var common_config = new configmod.ConfigSection('common', {base_url: base_url});
36 36 common_config.load();
37 37
38 38 var editor = new editmod.Editor('#texteditor-container', {
39 39 base_url: base_url,
40 40 events: events,
41 41 contents: contents,
42 42 file_path: file_path,
43 43 config: config,
44 44 });
45 45
46 46 // Make it available for debugging
47 47 IPython.editor = editor;
48 48
49 49 var save_widget = new savewidget.SaveWidget('span#save_widget', {
50 50 editor: editor,
51 51 events: events,
52 52 });
53 53
54 54 var menus = new menubar.MenuBar('#menubar', {
55 55 base_url: base_url,
56 56 editor: editor,
57 57 events: events,
58 58 save_widget: save_widget,
59 59 });
60 60
61 61 var notification_area = new notificationarea.EditorNotificationArea(
62 62 '#notification_area', {
63 63 events: events,
64 64 });
65 65 notification_area.init_notification_widgets();
66 66
67 67 utils.load_extensions_from_config(config);
68 68 utils.load_extensions_from_config(common_config);
69 69 editor.load();
70 70 page.show();
71 71
72 72 window.onbeforeunload = function () {
73 73 if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) {
74 74 return "Unsaved changes will be lost. Close anyway?";
75 75 }
76 76 };
77 77
78 78 });
@@ -1,61 +1,62
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 require([
5 5 'jquery',
6 6 'termjs',
7 7 'base/js/utils',
8 8 'base/js/page',
9 9 'services/config',
10 10 'terminal/js/terminado',
11 11 'custom/custom',
12 12 ], function(
13 13 $,
14 14 termjs,
15 15 utils,
16 16 page,
17 17 configmod,
18 18 terminado
19 19 ){
20 20 page = new page.Page();
21 21
22 var common_config = new configmod.ConfigSection('common', common_options);
22 var common_config = new configmod.ConfigSection('common',
23 {base_url: utils.get_body_data('baseUrl')});
23 24 common_config.load();
24 25
25 26 // Test size: 25x80
26 27 var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
27 28 // 1.02 here arrived at by trial and error to make the spacing look right
28 29 var termColWidth = function() { return 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;};
29 30
30 31 var base_url = utils.get_body_data('baseUrl');
31 32 var ws_path = utils.get_body_data('wsPath');
32 33 var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host
33 34 + base_url + ws_path;
34 35
35 36 var header = $("#header")[0]
36 37 function calculate_size() {
37 38 height = window.innerHeight - header.offsetHeight;
38 39 width = window.innerWidth;
39 40 var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
40 41 var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
41 42 console.log("resize to :", rows , 'rows by ', cols, 'columns');
42 43 return {rows: rows, cols: cols};
43 44 }
44 45
45 46 page.show_header();
46 47
47 48 size = calculate_size();
48 49 var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
49 50
50 51 page.show_site();
51 52
52 53 utils.load_extensions_from_config(common_config);
53 54
54 55 window.onresize = function() {
55 56 var geom = calculate_size();
56 57 terminal.term.resize(geom.cols, geom.rows);
57 58 terminal.socket.send(JSON.stringify(["set_size", geom.rows, geom.cols,
58 59 window.innerHeight, window.innerWidth]));
59 60 };
60 61
61 62 });
General Comments 0
You need to be logged in to leave comments. Login now