Show More
@@ -1,93 +1,97 b'' | |||
|
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 | 'base/js/namespace', |
|
7 | 7 | 'base/js/utils', |
|
8 | 8 | 'base/js/page', |
|
9 | 9 | 'base/js/events', |
|
10 | 10 | 'contents', |
|
11 | 11 | 'services/config', |
|
12 | 12 | 'edit/js/editor', |
|
13 | 13 | 'edit/js/menubar', |
|
14 | 14 | 'edit/js/savewidget', |
|
15 | 15 | 'edit/js/notificationarea', |
|
16 | 16 | 'custom/custom', |
|
17 | 17 | ], function( |
|
18 | 18 | $, |
|
19 | 19 | IPython, |
|
20 | 20 | utils, |
|
21 | 21 | page, |
|
22 | 22 | events, |
|
23 | 23 | contents, |
|
24 | 24 | configmod, |
|
25 | 25 | editmod, |
|
26 | 26 | menubar, |
|
27 | 27 | savewidget, |
|
28 | 28 | notificationarea |
|
29 | 29 | ){ |
|
30 | "use strict"; | |
|
30 | 31 | page = new page.Page(); |
|
31 | 32 | |
|
32 | 33 | var base_url = utils.get_body_data('baseUrl'); |
|
33 | 34 | var file_path = utils.get_body_data('filePath'); |
|
34 | contents = new contents.Contents({base_url: base_url}); | |
|
35 | 35 | var config = new configmod.ConfigSection('edit', {base_url: base_url}); |
|
36 | 36 | config.load(); |
|
37 | 37 | var common_config = new configmod.ConfigSection('common', {base_url: base_url}); |
|
38 | 38 | common_config.load(); |
|
39 | contents = new contents.Contents({ | |
|
40 | base_url: base_url, | |
|
41 | common_config: common_config | |
|
42 | }); | |
|
39 | 43 | |
|
40 | 44 | var editor = new editmod.Editor('#texteditor-container', { |
|
41 | 45 | base_url: base_url, |
|
42 | 46 | events: events, |
|
43 | 47 | contents: contents, |
|
44 | 48 | file_path: file_path, |
|
45 | 49 | config: config, |
|
46 | 50 | }); |
|
47 | 51 | |
|
48 | 52 | // Make it available for debugging |
|
49 | 53 | IPython.editor = editor; |
|
50 | 54 | |
|
51 | 55 | var save_widget = new savewidget.SaveWidget('span#save_widget', { |
|
52 | 56 | editor: editor, |
|
53 | 57 | events: events, |
|
54 | 58 | }); |
|
55 | 59 | |
|
56 | 60 | var menus = new menubar.MenuBar('#menubar', { |
|
57 | 61 | base_url: base_url, |
|
58 | 62 | editor: editor, |
|
59 | 63 | events: events, |
|
60 | 64 | save_widget: save_widget, |
|
61 | 65 | }); |
|
62 | 66 | |
|
63 | 67 | var notification_area = new notificationarea.EditorNotificationArea( |
|
64 | 68 | '#notification_area', { |
|
65 | 69 | events: events, |
|
66 | 70 | }); |
|
67 | 71 | editor.notification_area = notification_area; |
|
68 | 72 | notification_area.init_notification_widgets(); |
|
69 | 73 | |
|
70 | 74 | utils.load_extensions_from_config(config); |
|
71 | 75 | utils.load_extensions_from_config(common_config); |
|
72 | 76 | editor.load(); |
|
73 | 77 | page.show(); |
|
74 | 78 | |
|
75 | 79 | window.onbeforeunload = function () { |
|
76 | 80 | if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) { |
|
77 | 81 | return "Unsaved changes will be lost. Close anyway?"; |
|
78 | 82 | } |
|
79 | 83 | }; |
|
80 | 84 | |
|
81 | 85 | // Make sure the codemirror editor is sized appropriatley. |
|
82 | 86 | var _handle_resize = function() { |
|
83 | 87 | var backdrop = $("#texteditor-backdrop"); |
|
84 | 88 | |
|
85 | 89 | // account for padding on the backdrop wrapper |
|
86 | 90 | var padding = backdrop.outerHeight(true) - backdrop.height(); |
|
87 | 91 | $('div.CodeMirror').height($("#site").height() - padding); |
|
88 | 92 | }; |
|
89 | 93 | $(window).resize(_handle_resize); |
|
90 | 94 | |
|
91 | 95 | // On document ready, resize codemirror. |
|
92 | 96 | $(document).ready(_handle_resize); |
|
93 | 97 | }); |
@@ -1,159 +1,160 b'' | |||
|
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 | 'contents', |
|
9 | 9 | 'services/config', |
|
10 | 10 | 'base/js/utils', |
|
11 | 11 | 'base/js/page', |
|
12 | 12 | 'base/js/events', |
|
13 | 13 | 'auth/js/loginwidget', |
|
14 | 14 | 'notebook/js/maintoolbar', |
|
15 | 15 | 'notebook/js/pager', |
|
16 | 16 | 'notebook/js/quickhelp', |
|
17 | 17 | 'notebook/js/menubar', |
|
18 | 18 | 'notebook/js/notificationarea', |
|
19 | 19 | 'notebook/js/savewidget', |
|
20 | 20 | 'notebook/js/actions', |
|
21 | 21 | 'notebook/js/keyboardmanager', |
|
22 | 22 | 'notebook/js/kernelselector', |
|
23 | 23 | 'codemirror/lib/codemirror', |
|
24 | 24 | 'notebook/js/about', |
|
25 | 25 | // only loaded, not used, please keep sure this is loaded last |
|
26 | 26 | 'custom/custom' |
|
27 | 27 | ], function( |
|
28 | 28 | IPython, |
|
29 | 29 | $, |
|
30 | 30 | notebook, |
|
31 | 31 | contents, |
|
32 | 32 | configmod, |
|
33 | 33 | utils, |
|
34 | 34 | page, |
|
35 | 35 | events, |
|
36 | 36 | loginwidget, |
|
37 | 37 | maintoolbar, |
|
38 | 38 | pager, |
|
39 | 39 | quickhelp, |
|
40 | 40 | menubar, |
|
41 | 41 | notificationarea, |
|
42 | 42 | savewidget, |
|
43 | 43 | actions, |
|
44 | 44 | keyboardmanager, |
|
45 | 45 | kernelselector, |
|
46 | 46 | CodeMirror, |
|
47 | 47 | about, |
|
48 | 48 | // please keep sure that even if not used, this is loaded last |
|
49 | 49 | custom |
|
50 | 50 | ) { |
|
51 | 51 | "use strict"; |
|
52 | 52 | |
|
53 | 53 | // compat with old IPython, remove for IPython > 3.0 |
|
54 | 54 | window.CodeMirror = CodeMirror; |
|
55 | 55 | |
|
56 | 56 | var common_options = { |
|
57 | 57 | ws_url : utils.get_body_data("wsUrl"), |
|
58 | 58 | base_url : utils.get_body_data("baseUrl"), |
|
59 | 59 | notebook_path : utils.get_body_data("notebookPath"), |
|
60 | 60 | notebook_name : utils.get_body_data('notebookName') |
|
61 | 61 | }; |
|
62 | 62 | |
|
63 | 63 | var config_section = new configmod.ConfigSection('notebook', common_options); |
|
64 | 64 | config_section.load(); |
|
65 | 65 | var common_config = new configmod.ConfigSection('common', common_options); |
|
66 | 66 | common_config.load(); |
|
67 | 67 | var page = new page.Page(); |
|
68 | 68 | var pager = new pager.Pager('div#pager', { |
|
69 | 69 | events: events}); |
|
70 | 70 | var acts = new actions.init(); |
|
71 | 71 | var keyboard_manager = new keyboardmanager.KeyboardManager({ |
|
72 | 72 | pager: pager, |
|
73 | 73 | events: events, |
|
74 | 74 | actions: acts }); |
|
75 | 75 | var save_widget = new savewidget.SaveWidget('span#save_widget', { |
|
76 | 76 | events: events, |
|
77 | 77 | keyboard_manager: keyboard_manager}); |
|
78 |
var contents = new contents.Contents( |
|
|
79 | events: events, config:config_section}, | |
|
80 | common_options)); | |
|
78 | var contents = new contents.Contents({ | |
|
79 | base_url: common_options.base_url, | |
|
80 | common_config: common_config | |
|
81 | }); | |
|
81 | 82 | var notebook = new notebook.Notebook('div#notebook', $.extend({ |
|
82 | 83 | events: events, |
|
83 | 84 | keyboard_manager: keyboard_manager, |
|
84 | 85 | save_widget: save_widget, |
|
85 | 86 | contents: contents, |
|
86 | 87 | config: config_section}, |
|
87 | 88 | common_options)); |
|
88 | 89 | var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); |
|
89 | 90 | var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { |
|
90 | 91 | notebook: notebook, |
|
91 | 92 | events: events, |
|
92 | 93 | actions: acts}); |
|
93 | 94 | var quick_help = new quickhelp.QuickHelp({ |
|
94 | 95 | keyboard_manager: keyboard_manager, |
|
95 | 96 | events: events, |
|
96 | 97 | notebook: notebook}); |
|
97 | 98 | keyboard_manager.set_notebook(notebook); |
|
98 | 99 | keyboard_manager.set_quickhelp(quick_help); |
|
99 | 100 | var menubar = new menubar.MenuBar('#menubar', $.extend({ |
|
100 | 101 | notebook: notebook, |
|
101 | 102 | contents: contents, |
|
102 | 103 | events: events, |
|
103 | 104 | save_widget: save_widget, |
|
104 | 105 | quick_help: quick_help}, |
|
105 | 106 | common_options)); |
|
106 | 107 | var notification_area = new notificationarea.NotebookNotificationArea( |
|
107 | 108 | '#notification_area', { |
|
108 | 109 | events: events, |
|
109 | 110 | save_widget: save_widget, |
|
110 | 111 | notebook: notebook, |
|
111 | 112 | keyboard_manager: keyboard_manager}); |
|
112 | 113 | notification_area.init_notification_widgets(); |
|
113 | 114 | var kernel_selector = new kernelselector.KernelSelector( |
|
114 | 115 | '#kernel_logo_widget', notebook); |
|
115 | 116 | |
|
116 | 117 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
117 | 118 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
118 | 119 | '<span id="test3" style="font-style: italic;">x</span></pre></div>'); |
|
119 | 120 | var nh = $('#test1').innerHeight(); |
|
120 | 121 | var bh = $('#test2').innerHeight(); |
|
121 | 122 | var ih = $('#test3').innerHeight(); |
|
122 | 123 | if(nh != bh || nh != ih) { |
|
123 | 124 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); |
|
124 | 125 | } |
|
125 | 126 | $('#fonttest').remove(); |
|
126 | 127 | |
|
127 | 128 | page.show(); |
|
128 | 129 | |
|
129 | 130 | var first_load = function () { |
|
130 | 131 | var hash = document.location.hash; |
|
131 | 132 | if (hash) { |
|
132 | 133 | document.location.hash = ''; |
|
133 | 134 | document.location.hash = hash; |
|
134 | 135 | } |
|
135 | 136 | notebook.set_autosave_interval(notebook.minimum_autosave_interval); |
|
136 | 137 | // only do this once |
|
137 | 138 | events.off('notebook_loaded.Notebook', first_load); |
|
138 | 139 | }; |
|
139 | 140 | events.on('notebook_loaded.Notebook', first_load); |
|
140 | 141 | |
|
141 | 142 | IPython.page = page; |
|
142 | 143 | IPython.notebook = notebook; |
|
143 | 144 | IPython.contents = contents; |
|
144 | 145 | IPython.pager = pager; |
|
145 | 146 | IPython.quick_help = quick_help; |
|
146 | 147 | IPython.login_widget = login_widget; |
|
147 | 148 | IPython.menubar = menubar; |
|
148 | 149 | IPython.toolbar = toolbar; |
|
149 | 150 | IPython.notification_area = notification_area; |
|
150 | 151 | IPython.keyboard_manager = keyboard_manager; |
|
151 | 152 | IPython.save_widget = save_widget; |
|
152 | 153 | IPython.tooltip = notebook.tooltip; |
|
153 | 154 | |
|
154 | 155 | events.trigger('app_initialized.NotebookApp'); |
|
155 | 156 | utils.load_extensions_from_config(config_section); |
|
156 | 157 | utils.load_extensions_from_config(common_config); |
|
157 | 158 | notebook.load_notebook(common_options.notebook_path); |
|
158 | 159 | |
|
159 | 160 | }); |
@@ -1,179 +1,180 b'' | |||
|
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 | 'base/js/namespace', |
|
7 | 7 | 'base/js/dialog', |
|
8 | 8 | 'base/js/events', |
|
9 | 9 | 'base/js/page', |
|
10 | 10 | 'base/js/utils', |
|
11 | 11 | 'services/config', |
|
12 | 12 | 'contents', |
|
13 | 13 | 'tree/js/notebooklist', |
|
14 | 14 | 'tree/js/clusterlist', |
|
15 | 15 | 'tree/js/sessionlist', |
|
16 | 16 | 'tree/js/kernellist', |
|
17 | 17 | 'tree/js/terminallist', |
|
18 | 18 | 'tree/js/newnotebook', |
|
19 | 19 | 'auth/js/loginwidget', |
|
20 | 20 | // only loaded, not used: |
|
21 | 21 | 'jqueryui', |
|
22 | 22 | 'bootstrap', |
|
23 | 23 | 'custom/custom', |
|
24 | 24 | ], function( |
|
25 | 25 | $, |
|
26 | 26 | IPython, |
|
27 | 27 | dialog, |
|
28 | 28 | events, |
|
29 | 29 | page, |
|
30 | 30 | utils, |
|
31 | 31 | config, |
|
32 | 32 | contents_service, |
|
33 | 33 | notebooklist, |
|
34 | 34 | clusterlist, |
|
35 | 35 | sesssionlist, |
|
36 | 36 | kernellist, |
|
37 | 37 | terminallist, |
|
38 | 38 | newnotebook, |
|
39 | 39 | loginwidget){ |
|
40 | 40 | "use strict"; |
|
41 | 41 | |
|
42 | 42 | page = new page.Page(); |
|
43 | 43 | |
|
44 | 44 | var common_options = { |
|
45 | 45 | base_url: utils.get_body_data("baseUrl"), |
|
46 | 46 | notebook_path: utils.get_body_data("notebookPath"), |
|
47 | 47 | }; |
|
48 | 48 | var cfg = new config.ConfigSection('tree', common_options); |
|
49 | 49 | cfg.load(); |
|
50 | 50 | common_options.config = cfg; |
|
51 | 51 | var common_config = new config.ConfigSection('common', common_options); |
|
52 | 52 | common_config.load(); |
|
53 | 53 | |
|
54 | 54 | var session_list = new sesssionlist.SesssionList($.extend({ |
|
55 | 55 |
events: events}, |
|
56 | 56 | common_options)); |
|
57 |
var contents = new contents_service.Contents( |
|
|
58 | events: events}, | |
|
59 | common_options)); | |
|
57 | var contents = new contents_service.Contents({ | |
|
58 | base_url: common_options.base_url, | |
|
59 | common_config: common_config | |
|
60 | }); | |
|
60 | 61 | var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ |
|
61 | 62 | contents: contents, |
|
62 | 63 | session_list: session_list}, |
|
63 | 64 | common_options)); |
|
64 | 65 | var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); |
|
65 | 66 | var kernel_list = new kernellist.KernelList('#running_list', $.extend({ |
|
66 | 67 | session_list: session_list}, |
|
67 | 68 | common_options)); |
|
68 | 69 | |
|
69 | 70 | var terminal_list; |
|
70 | 71 | if (utils.get_body_data("terminalsAvailable") === "True") { |
|
71 | 72 | terminal_list = new terminallist.TerminalList('#terminal_list', common_options); |
|
72 | 73 | } |
|
73 | 74 | |
|
74 | 75 | var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); |
|
75 | 76 | |
|
76 | 77 | var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons", |
|
77 | 78 | $.extend( |
|
78 | 79 | {contents: contents}, |
|
79 | 80 | common_options |
|
80 | 81 | ) |
|
81 | 82 | ); |
|
82 | 83 | |
|
83 | 84 | var interval_id=0; |
|
84 | 85 | // auto refresh every xx secondes, no need to be fast, |
|
85 | 86 | // update is done most of the time when page get focus |
|
86 | 87 | IPython.tree_time_refresh = 60; // in sec |
|
87 | 88 | |
|
88 | 89 | // limit refresh on focus at 1/10sec, otherwise this |
|
89 | 90 | // can cause too frequent refresh on switching through windows or tabs. |
|
90 | 91 | IPython.min_delta_refresh = 10; // in sec |
|
91 | 92 | |
|
92 | 93 | var _last_refresh = null; |
|
93 | 94 | |
|
94 | 95 | var _refresh_list = function(){ |
|
95 | 96 | _last_refresh = new Date(); |
|
96 | 97 | session_list.load_sessions(); |
|
97 | 98 | cluster_list.load_list(); |
|
98 | 99 | if (terminal_list) { |
|
99 | 100 | terminal_list.load_terminals(); |
|
100 | 101 | } |
|
101 | } | |
|
102 | }; | |
|
102 | 103 | |
|
103 | 104 | var enable_autorefresh = function(){ |
|
104 | 105 | /** |
|
105 | 106 | *refresh immediately , then start interval |
|
106 | 107 | */ |
|
107 | var now = new Date() | |
|
108 | var now = new Date(); | |
|
108 | 109 | |
|
109 | 110 | if (now - _last_refresh < IPython.min_delta_refresh*1000){ |
|
110 | console.log("Reenabling autorefresh too close to last tree refresh, not refreshing immediately again.") | |
|
111 | console.log("Reenabling autorefresh too close to last tree refresh, not refreshing immediately again."); | |
|
111 | 112 | } else { |
|
112 | 113 | _refresh_list(); |
|
113 | 114 | } |
|
114 | 115 | if (!interval_id){ |
|
115 | 116 | interval_id = setInterval(_refresh_list, |
|
116 | 117 | IPython.tree_time_refresh*1000 |
|
117 | 118 | ); |
|
118 | 119 | } |
|
119 | 120 | }; |
|
120 | 121 | |
|
121 | 122 | var disable_autorefresh = function(){ |
|
122 | 123 | clearInterval(interval_id); |
|
123 | 124 | interval_id = 0; |
|
124 | 125 | }; |
|
125 | 126 | |
|
126 | 127 | // stop autorefresh when page lose focus |
|
127 | 128 | $(window).blur(function() { |
|
128 | 129 | disable_autorefresh(); |
|
129 | 130 | }); |
|
130 | 131 | |
|
131 | 132 | //re-enable when page get focus back |
|
132 | 133 | $(window).focus(function() { |
|
133 | 134 | enable_autorefresh(); |
|
134 | 135 | }); |
|
135 | 136 | |
|
136 | 137 | // finally start it, it will refresh immediately |
|
137 | 138 | enable_autorefresh(); |
|
138 | 139 | |
|
139 | 140 | page.show(); |
|
140 | 141 | |
|
141 | 142 | // For backwards compatability. |
|
142 | 143 | IPython.page = page; |
|
143 | 144 | IPython.notebook_list = notebook_list; |
|
144 | 145 | IPython.cluster_list = cluster_list; |
|
145 | 146 | IPython.session_list = session_list; |
|
146 | 147 | IPython.kernel_list = kernel_list; |
|
147 | 148 | IPython.login_widget = login_widget; |
|
148 | 149 | IPython.new_notebook_widget = new_buttons; |
|
149 | 150 | |
|
150 | 151 | events.trigger('app_initialized.DashboardApp'); |
|
151 | 152 | utils.load_extensions_from_config(cfg); |
|
152 | 153 | utils.load_extensions_from_config(common_config); |
|
153 | 154 | |
|
154 | 155 | // bound the upload method to the on change of the file select list |
|
155 | 156 | $("#alternate_upload").change(function (event){ |
|
156 | 157 | notebook_list.handleFilesUpload(event,'form'); |
|
157 | 158 | }); |
|
158 | 159 | |
|
159 | 160 | // set hash on tab click |
|
160 | 161 | $("#tabs").find("a").click(function(e) { |
|
161 | 162 | // Prevent the document from jumping when the active tab is changed to a |
|
162 | 163 | // tab that has a lot of content. |
|
163 | 164 | e.preventDefault(); |
|
164 | 165 | |
|
165 | 166 | // Set the hash without causing the page to jump. |
|
166 | 167 | // http://stackoverflow.com/a/14690177/2824256 |
|
167 | 168 | var hash = $(this).attr("href"); |
|
168 | 169 | if(window.history.pushState) { |
|
169 | 170 | window.history.pushState(null, null, hash); |
|
170 | 171 | } else { |
|
171 | 172 | window.location.hash = hash; |
|
172 | 173 | } |
|
173 | 174 | }); |
|
174 | 175 | |
|
175 | 176 | // load tab if url hash |
|
176 | 177 | if (window.location.hash) { |
|
177 | 178 | $("#tabs").find("a[href=" + window.location.hash + "]").click(); |
|
178 | 179 | } |
|
179 | 180 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now