Show More
@@ -1,136 +1,137 | |||
|
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 | 'jquery', |
|
7 | 7 | 'notebook/js/notebook', |
|
8 | 8 | 'base/js/utils', |
|
9 | 9 | 'base/js/page', |
|
10 | 10 | 'notebook/js/layoutmanager', |
|
11 | 11 | 'base/js/events', |
|
12 | 12 | 'auth/js/loginwidget', |
|
13 | 13 | 'notebook/js/maintoolbar', |
|
14 | 14 | 'notebook/js/pager', |
|
15 | 15 | 'notebook/js/quickhelp', |
|
16 | 16 | 'notebook/js/menubar', |
|
17 | 17 | 'notebook/js/notificationarea', |
|
18 | 18 | 'notebook/js/savewidget', |
|
19 | 19 | 'notebook/js/keyboardmanager', |
|
20 | 20 | 'notebook/js/config', |
|
21 | // only loaded, not used: | |
|
21 | 22 | 'custom/custom', |
|
22 | 23 | ], function( |
|
23 | 24 | IPython, |
|
24 | 25 | $, |
|
25 | 26 | notebook, |
|
26 | 27 | utils, |
|
27 | 28 | page, |
|
28 | 29 | layoutmanager, |
|
29 | 30 | events, |
|
30 | 31 | loginwidget, |
|
31 | 32 | maintoolbar, |
|
32 | 33 | pager, |
|
33 | 34 | quickhelp, |
|
34 | 35 | menubar, |
|
35 | 36 | notificationarea, |
|
36 | 37 | savewidget, |
|
37 | 38 | keyboardmanager, |
|
38 | 39 | config |
|
39 | 40 | ) { |
|
40 | 41 | "use strict"; |
|
41 | 42 | |
|
42 | 43 | $('#ipython-main-app').addClass('border-box-sizing'); |
|
43 | 44 | $('div#notebook_panel').addClass('border-box-sizing'); |
|
44 | 45 | |
|
45 | 46 | var common_options = { |
|
46 | 47 | base_url : utils.get_body_data("baseUrl"), |
|
47 | 48 | notebook_path : utils.get_body_data("notebookPath"), |
|
48 | 49 | notebook_name : utils.get_body_data('notebookName') |
|
49 | 50 | }; |
|
50 | 51 | |
|
51 | 52 | var user_config = $.extend({}, config.default_config); |
|
52 | 53 | var page = new page.Page(); |
|
53 | 54 | var layout_manager = new layoutmanager.LayoutManager(); |
|
54 | 55 | var pager = new pager.Pager('div#pager', 'div#pager_splitter', { |
|
55 | 56 | layout_manager: layout_manager, |
|
56 | 57 | events: events}); |
|
57 | 58 | var keyboard_manager = new keyboardmanager.KeyboardManager({ |
|
58 | 59 | pager: pager, |
|
59 | 60 | events: events}); |
|
60 | 61 | var save_widget = new savewidget.SaveWidget('span#save_widget', { |
|
61 | 62 | events: events, |
|
62 | 63 | keyboard_manager: keyboard_manager}); |
|
63 | 64 | var notebook = new notebook.Notebook('div#notebook', $.extend({ |
|
64 | 65 | events: events, |
|
65 | 66 | keyboard_manager: keyboard_manager, |
|
66 | 67 | save_widget: save_widget, |
|
67 | 68 | config: user_config}, |
|
68 | 69 | common_options)); |
|
69 | 70 | var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); |
|
70 | 71 | var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { |
|
71 | 72 | notebook: notebook, |
|
72 | 73 | events: events}); |
|
73 | 74 | var quick_help = new quickhelp.QuickHelp({ |
|
74 | 75 | keyboard_manager: keyboard_manager, |
|
75 | 76 | events: events, |
|
76 | 77 | notebook: notebook}); |
|
77 | 78 | var menubar = new menubar.MenuBar('#menubar', $.extend({ |
|
78 | 79 | notebook: notebook, |
|
79 | 80 | layout_manager: layout_manager, |
|
80 | 81 | events: events, |
|
81 | 82 | save_widget: save_widget, |
|
82 | 83 | quick_help: quick_help}, |
|
83 | 84 | common_options)); |
|
84 | 85 | var notification_area = new notificationarea.NotificationArea( |
|
85 | 86 | '#notification_area', { |
|
86 | 87 | events: events, |
|
87 | 88 | save_widget: save_widget, |
|
88 | 89 | notebook: notebook, |
|
89 | 90 | keyboard_manager: keyboard_manager}); |
|
90 | 91 | notification_area.init_notification_widgets(); |
|
91 | 92 | |
|
92 | 93 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
93 | 94 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
94 | 95 | '<span id="test3" style="font-style: italic;">x</span></pre></div>'); |
|
95 | 96 | var nh = $('#test1').innerHeight(); |
|
96 | 97 | var bh = $('#test2').innerHeight(); |
|
97 | 98 | var ih = $('#test3').innerHeight(); |
|
98 | 99 | if(nh != bh || nh != ih) { |
|
99 | 100 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); |
|
100 | 101 | } |
|
101 | 102 | $('#fonttest').remove(); |
|
102 | 103 | |
|
103 | 104 | page.show(); |
|
104 | 105 | |
|
105 | 106 | layout_manager.do_resize(); |
|
106 | 107 | var first_load = function () { |
|
107 | 108 | layout_manager.do_resize(); |
|
108 | 109 | var hash = document.location.hash; |
|
109 | 110 | if (hash) { |
|
110 | 111 | document.location.hash = ''; |
|
111 | 112 | document.location.hash = hash; |
|
112 | 113 | } |
|
113 | 114 | notebook.set_autosave_interval(notebook.minimum_autosave_interval); |
|
114 | 115 | // only do this once |
|
115 | 116 | events.off('notebook_loaded.Notebook', first_load); |
|
116 | 117 | }; |
|
117 | 118 | events.on('notebook_loaded.Notebook', first_load); |
|
118 | 119 | |
|
119 | 120 | IPython.page = page; |
|
120 | 121 | IPython.layout_manager = layout_manager; |
|
121 | 122 | IPython.notebook = notebook; |
|
122 | 123 | IPython.pager = pager; |
|
123 | 124 | IPython.quick_help = quick_help; |
|
124 | 125 | IPython.login_widget = login_widget; |
|
125 | 126 | IPython.menubar = menubar; |
|
126 | 127 | IPython.toolbar = toolbar; |
|
127 | 128 | IPython.notification_area = notification_area; |
|
128 | 129 | IPython.keyboard_manager = keyboard_manager; |
|
129 | 130 | IPython.save_widget = save_widget; |
|
130 | 131 | IPython.config = user_config; |
|
131 | 132 | IPython.tooltip = notebook.tooltip; |
|
132 | 133 | |
|
133 | 134 | events.trigger('app_initialized.NotebookApp'); |
|
134 | 135 | notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); |
|
135 | 136 | |
|
136 | 137 | }); |
@@ -1,120 +1,121 | |||
|
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 | 'jquery', |
|
7 | 7 | 'base/js/events', |
|
8 | 8 | 'base/js/page', |
|
9 | 9 | 'base/js/utils', |
|
10 | 10 | 'tree/js/notebooklist', |
|
11 | 11 | 'tree/js/clusterlist', |
|
12 | 12 | 'tree/js/sessionlist', |
|
13 | 13 | 'tree/js/kernellist', |
|
14 | 14 | 'auth/js/loginwidget', |
|
15 | // only loaded, not used: | |
|
15 | 16 | 'jqueryui', |
|
16 | 17 | 'bootstrap', |
|
17 | 18 | 'custom/custom', |
|
18 | 19 | ], function( |
|
19 | 20 | IPython, |
|
20 | 21 | $, |
|
21 | 22 | events, |
|
22 | 23 | page, |
|
23 | 24 | utils, |
|
24 | 25 | notebooklist, |
|
25 | 26 | clusterlist, |
|
26 | 27 | sesssionlist, |
|
27 | 28 | kernellist, |
|
28 | 29 | loginwidget){ |
|
29 | 30 | |
|
30 | 31 | page = new page.Page(); |
|
31 | 32 | |
|
32 | 33 | var common_options = { |
|
33 | 34 | base_url: utils.get_body_data("baseUrl"), |
|
34 | 35 | notebook_path: utils.get_body_data("notebookPath"), |
|
35 | 36 | }; |
|
36 | 37 | session_list = new sesssionlist.SesssionList($.extend({ |
|
37 | 38 | events: events}, |
|
38 | 39 | common_options)); |
|
39 | 40 | notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ |
|
40 | 41 | session_list: session_list}, |
|
41 | 42 | common_options)); |
|
42 | 43 | cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); |
|
43 | 44 | kernel_list = new kernellist.KernelList('#running_list', $.extend({ |
|
44 | 45 | session_list: session_list}, |
|
45 | 46 | common_options)); |
|
46 | 47 | login_widget = new loginwidget.LoginWidget('#login_widget', common_options); |
|
47 | 48 | |
|
48 | 49 | $('#new_notebook').button().click(function (e) { |
|
49 | 50 | notebook_list.new_notebook(); |
|
50 | 51 | }); |
|
51 | 52 | |
|
52 | 53 | var interval_id=0; |
|
53 | 54 | // auto refresh every xx secondes, no need to be fast, |
|
54 | 55 | // update is done at least when page get focus |
|
55 | 56 | var time_refresh = 60; // in sec |
|
56 | 57 | |
|
57 | 58 | var enable_autorefresh = function(){ |
|
58 | 59 | //refresh immediately , then start interval |
|
59 | 60 | if($('.upload_button').length === 0) |
|
60 | 61 | { |
|
61 | 62 | session_list.load_sessions(); |
|
62 | 63 | cluster_list.load_list(); |
|
63 | 64 | } |
|
64 | 65 | if (!interval_id){ |
|
65 | 66 | interval_id = setInterval(function(){ |
|
66 | 67 | if($('.upload_button').length === 0) |
|
67 | 68 | { |
|
68 | 69 | session_list.load_sessions(); |
|
69 | 70 | cluster_list.load_list(); |
|
70 | 71 | } |
|
71 | 72 | }, time_refresh*1000); |
|
72 | 73 | } |
|
73 | 74 | }; |
|
74 | 75 | |
|
75 | 76 | var disable_autorefresh = function(){ |
|
76 | 77 | clearInterval(interval_id); |
|
77 | 78 | interval_id = 0; |
|
78 | 79 | }; |
|
79 | 80 | |
|
80 | 81 | // stop autorefresh when page lose focus |
|
81 | 82 | $(window).blur(function() { |
|
82 | 83 | disable_autorefresh(); |
|
83 | 84 | }); |
|
84 | 85 | |
|
85 | 86 | //re-enable when page get focus back |
|
86 | 87 | $(window).focus(function() { |
|
87 | 88 | enable_autorefresh(); |
|
88 | 89 | }); |
|
89 | 90 | |
|
90 | 91 | // finally start it, it will refresh immediately |
|
91 | 92 | enable_autorefresh(); |
|
92 | 93 | |
|
93 | 94 | page.show(); |
|
94 | 95 | |
|
95 | 96 | // For backwards compatability. |
|
96 | 97 | IPython.page = page; |
|
97 | 98 | IPython.notebook_list = notebook_list; |
|
98 | 99 | IPython.cluster_list = cluster_list; |
|
99 | 100 | IPython.session_list = session_list; |
|
100 | 101 | IPython.kernel_list = kernel_list; |
|
101 | 102 | IPython.login_widget = login_widget; |
|
102 | 103 | |
|
103 | 104 | events.trigger('app_initialized.DashboardApp'); |
|
104 | 105 | |
|
105 | 106 | // bound the upload method to the on change of the file select list |
|
106 | 107 | $("#alternate_upload").change(function (event){ |
|
107 | 108 | notebook_list.handleFilesUpload(event,'form'); |
|
108 | 109 | }); |
|
109 | 110 | |
|
110 | 111 | // set hash on tab click |
|
111 | 112 | $("#tabs").find("a").click(function() { |
|
112 | 113 | window.location.hash = $(this).attr("href"); |
|
113 | 114 | }); |
|
114 | 115 | |
|
115 | 116 | // load tab if url hash |
|
116 | 117 | if (window.location.hash) { |
|
117 | 118 | $("#tabs").find("a[href=" + window.location.hash + "]").click(); |
|
118 | 119 | } |
|
119 | 120 | |
|
120 | 121 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now