##// END OF EJS Templates
Add comment explaining 1.02 factor
Thomas Kluyver -
Show More
@@ -1,52 +1,53
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 'terminal/js/terminado',
9 'terminal/js/terminado',
10 'custom/custom',
10 'custom/custom',
11 ], function(
11 ], function(
12 $,
12 $,
13 termjs,
13 termjs,
14 utils,
14 utils,
15 page,
15 page,
16 terminado
16 terminado
17 ){
17 ){
18 page = new page.Page();
18 page = new page.Page();
19 // Test size: 25x80
19 // Test size: 25x80
20 var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
20 var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
21 // 1.02 here arrived at by trial and error to make the spacing look right
21 var termColWidth = function() { return 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;};
22 var termColWidth = function() { return 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;};
22
23
23 var base_url = utils.get_body_data('baseUrl');
24 var base_url = utils.get_body_data('baseUrl');
24 var ws_path = utils.get_body_data('wsPath');
25 var ws_path = utils.get_body_data('wsPath');
25 var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host
26 var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host
26 + base_url + ws_path;
27 + base_url + ws_path;
27
28
28 var header = $("#header")[0]
29 var header = $("#header")[0]
29 function calculate_size() {
30 function calculate_size() {
30 height = window.innerHeight - header.offsetHeight;
31 height = window.innerHeight - header.offsetHeight;
31 width = window.innerWidth;
32 width = window.innerWidth;
32 var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
33 var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
33 var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
34 var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
34 console.log("resize to :", rows , 'rows by ', cols, 'columns');
35 console.log("resize to :", rows , 'rows by ', cols, 'columns');
35 return {rows: rows, cols: cols};
36 return {rows: rows, cols: cols};
36 }
37 }
37
38
38 page.show_header();
39 page.show_header();
39
40
40 size = calculate_size();
41 size = calculate_size();
41 var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
42 var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);
42
43
43 page.show_site();
44 page.show_site();
44
45
45 window.onresize = function() {
46 window.onresize = function() {
46 var geom = calculate_size();
47 var geom = calculate_size();
47 terminal.term.resize(geom.cols, geom.rows);
48 terminal.term.resize(geom.cols, geom.rows);
48 terminal.socket.send(JSON.stringify(["set_size", geom.rows, geom.cols,
49 terminal.socket.send(JSON.stringify(["set_size", geom.rows, geom.cols,
49 window.innerHeight, window.innerWidth]));
50 window.innerHeight, window.innerWidth]));
50 };
51 };
51
52
52 });
53 });
General Comments 0
You need to be logged in to leave comments. Login now