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