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