main.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. requirejs([
  4. 'jquery',
  5. 'base/js/utils',
  6. 'base/js/page',
  7. 'auth/js/loginwidget',
  8. 'services/config',
  9. 'terminal/js/terminado',
  10. ], function(
  11. $,
  12. utils,
  13. page,
  14. loginwidget,
  15. configmod,
  16. terminado
  17. ){
  18. "use strict";
  19. requirejs(['custom/custom'], function() {});
  20. page = new page.Page('div#header', 'div#site');
  21. var common_options = {
  22. base_url : utils.get_body_data("baseUrl"),
  23. };
  24. var config = new configmod.ConfigSection('terminal', common_options);
  25. config.load();
  26. var common_config = new configmod.ConfigSection('common', common_options);
  27. common_config.load();
  28. // This makes the 'logout' button in the top right work.
  29. var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
  30. var base_url = utils.get_body_data('baseUrl').replace(/\/?$/, '/');
  31. var ws_path = utils.get_body_data('wsPath');
  32. var ws_url = utils.get_body_data('wsUrl');
  33. if (!ws_url) {
  34. // trailing 's' in https will become wss for secure web sockets
  35. ws_url = location.protocol.replace('http', 'ws') + "//" + location.host;
  36. }
  37. ws_url = ws_url + base_url + ws_path;
  38. page.show_header();
  39. var terminal = terminado.make_terminal($("#terminado-container")[0], ws_url);
  40. page.show_site();
  41. utils.load_extensions_from_config(config);
  42. utils.load_extensions_from_config(common_config);
  43. window.onresize = function() {
  44. terminal.term.fit();
  45. // send the new size to the server so that it can trigger a resize in the running process.
  46. terminal.socket.send(JSON.stringify(["set_size", terminal.term.rows, terminal.term.cols,
  47. $(window).height(), $(window).width()]));
  48. };
  49. // Expose terminal for fiddling with in the browser
  50. window.terminal = terminal;
  51. });