Show More
@@ -1,351 +1,350 | |||||
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 | define([ |
|
4 | define([ | |
5 | 'base/js/namespace', |
|
5 | 'base/js/namespace', | |
6 | 'jquery', |
|
6 | 'jquery', | |
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'notebook/js/tour', |
|
8 | 'notebook/js/tour', | |
9 | 'bootstrap', |
|
9 | 'bootstrap', | |
10 | ], function(IPython, $, utils, tour) { |
|
10 | ], function(IPython, $, utils, tour) { | |
11 | "use strict"; |
|
11 | "use strict"; | |
12 |
|
12 | |||
13 | var MenuBar = function (selector, options) { |
|
13 | var MenuBar = function (selector, options) { | |
14 | // Constructor |
|
14 | // Constructor | |
15 | // |
|
15 | // | |
16 | // A MenuBar Class to generate the menubar of IPython notebook |
|
16 | // A MenuBar Class to generate the menubar of IPython notebook | |
17 | // |
|
17 | // | |
18 | // Parameters: |
|
18 | // Parameters: | |
19 | // selector: string |
|
19 | // selector: string | |
20 | // options: dictionary |
|
20 | // options: dictionary | |
21 | // Dictionary of keyword arguments. |
|
21 | // Dictionary of keyword arguments. | |
22 | // notebook: Notebook instance |
|
22 | // notebook: Notebook instance | |
23 | // layout_manager: LayoutManager instance |
|
23 | // layout_manager: LayoutManager instance | |
24 | // events: $(Events) instance |
|
24 | // events: $(Events) instance | |
25 | // save_widget: SaveWidget instance |
|
25 | // save_widget: SaveWidget instance | |
26 | // quick_help: QuickHelp instance |
|
26 | // quick_help: QuickHelp instance | |
27 | // base_url : string |
|
27 | // base_url : string | |
28 | // notebook_path : string |
|
28 | // notebook_path : string | |
29 | // notebook_name : string |
|
29 | // notebook_name : string | |
30 | options = options || {}; |
|
30 | options = options || {}; | |
31 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); |
|
31 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | |
32 | this.selector = selector; |
|
32 | this.selector = selector; | |
33 | this.notebook = options.notebook; |
|
33 | this.notebook = options.notebook; | |
34 | this.layout_manager = options.layout_manager; |
|
34 | this.layout_manager = options.layout_manager; | |
35 | this.events = options.events; |
|
35 | this.events = options.events; | |
36 | this.save_widget = options.save_widget; |
|
36 | this.save_widget = options.save_widget; | |
37 | this.quick_help = options.quick_help; |
|
37 | this.quick_help = options.quick_help; | |
38 |
|
38 | |||
39 | try { |
|
39 | try { | |
40 | this.tour = new tour.Tour(this.notebook, this.events); |
|
40 | this.tour = new tour.Tour(this.notebook, this.events); | |
41 | } catch (e) { |
|
41 | } catch (e) { | |
42 | this.tour = undefined; |
|
42 | this.tour = undefined; | |
43 | console.log("Failed to instantiate Notebook Tour", e); |
|
43 | console.log("Failed to instantiate Notebook Tour", e); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | if (this.selector !== undefined) { |
|
46 | if (this.selector !== undefined) { | |
47 | this.element = $(selector); |
|
47 | this.element = $(selector); | |
48 | this.style(); |
|
48 | this.style(); | |
49 | this.bind_events(); |
|
49 | this.bind_events(); | |
50 | } |
|
50 | } | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | MenuBar.prototype.style = function () { |
|
53 | MenuBar.prototype.style = function () { | |
54 | var that = this; |
|
54 | var that = this; | |
55 | this.element.addClass('border-box-sizing'); |
|
|||
56 | this.element.find("li").click(function (event, ui) { |
|
55 | this.element.find("li").click(function (event, ui) { | |
57 | // The selected cell loses focus when the menu is entered, so we |
|
56 | // The selected cell loses focus when the menu is entered, so we | |
58 | // re-select it upon selection. |
|
57 | // re-select it upon selection. | |
59 | var i = that.notebook.get_selected_index(); |
|
58 | var i = that.notebook.get_selected_index(); | |
60 | that.notebook.select(i); |
|
59 | that.notebook.select(i); | |
61 | } |
|
60 | } | |
62 | ); |
|
61 | ); | |
63 | }; |
|
62 | }; | |
64 |
|
63 | |||
65 | MenuBar.prototype._nbconvert = function (format, download) { |
|
64 | MenuBar.prototype._nbconvert = function (format, download) { | |
66 | download = download || false; |
|
65 | download = download || false; | |
67 | var notebook_path = this.notebook.notebook_path; |
|
66 | var notebook_path = this.notebook.notebook_path; | |
68 | var notebook_name = this.notebook.notebook_name; |
|
67 | var notebook_name = this.notebook.notebook_name; | |
69 | if (this.notebook.dirty) { |
|
68 | if (this.notebook.dirty) { | |
70 | this.notebook.save_notebook({async : false}); |
|
69 | this.notebook.save_notebook({async : false}); | |
71 | } |
|
70 | } | |
72 | var url = utils.url_join_encode( |
|
71 | var url = utils.url_join_encode( | |
73 | this.base_url, |
|
72 | this.base_url, | |
74 | 'nbconvert', |
|
73 | 'nbconvert', | |
75 | format, |
|
74 | format, | |
76 | notebook_path, |
|
75 | notebook_path, | |
77 | notebook_name |
|
76 | notebook_name | |
78 | ) + "?download=" + download.toString(); |
|
77 | ) + "?download=" + download.toString(); | |
79 |
|
78 | |||
80 | window.open(url); |
|
79 | window.open(url); | |
81 | }; |
|
80 | }; | |
82 |
|
81 | |||
83 | MenuBar.prototype.bind_events = function () { |
|
82 | MenuBar.prototype.bind_events = function () { | |
84 | // File |
|
83 | // File | |
85 | var that = this; |
|
84 | var that = this; | |
86 | this.element.find('#new_notebook').click(function () { |
|
85 | this.element.find('#new_notebook').click(function () { | |
87 | that.notebook.new_notebook(); |
|
86 | that.notebook.new_notebook(); | |
88 | }); |
|
87 | }); | |
89 | this.element.find('#open_notebook').click(function () { |
|
88 | this.element.find('#open_notebook').click(function () { | |
90 | window.open(utils.url_join_encode( |
|
89 | window.open(utils.url_join_encode( | |
91 | that.notebook.base_url, |
|
90 | that.notebook.base_url, | |
92 | 'tree', |
|
91 | 'tree', | |
93 | that.notebook.notebook_path |
|
92 | that.notebook.notebook_path | |
94 | )); |
|
93 | )); | |
95 | }); |
|
94 | }); | |
96 | this.element.find('#copy_notebook').click(function () { |
|
95 | this.element.find('#copy_notebook').click(function () { | |
97 | that.notebook.copy_notebook(); |
|
96 | that.notebook.copy_notebook(); | |
98 | return false; |
|
97 | return false; | |
99 | }); |
|
98 | }); | |
100 | this.element.find('#download_ipynb').click(function () { |
|
99 | this.element.find('#download_ipynb').click(function () { | |
101 | var base_url = that.notebook.base_url; |
|
100 | var base_url = that.notebook.base_url; | |
102 | var notebook_path = that.notebook.notebook_path; |
|
101 | var notebook_path = that.notebook.notebook_path; | |
103 | var notebook_name = that.notebook.notebook_name; |
|
102 | var notebook_name = that.notebook.notebook_name; | |
104 | if (that.notebook.dirty) { |
|
103 | if (that.notebook.dirty) { | |
105 | that.notebook.save_notebook({async : false}); |
|
104 | that.notebook.save_notebook({async : false}); | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | var url = utils.url_join_encode( |
|
107 | var url = utils.url_join_encode( | |
109 | base_url, |
|
108 | base_url, | |
110 | 'files', |
|
109 | 'files', | |
111 | notebook_path, |
|
110 | notebook_path, | |
112 | notebook_name |
|
111 | notebook_name | |
113 | ); |
|
112 | ); | |
114 | window.location.assign(url); |
|
113 | window.location.assign(url); | |
115 | }); |
|
114 | }); | |
116 |
|
115 | |||
117 | this.element.find('#print_preview').click(function () { |
|
116 | this.element.find('#print_preview').click(function () { | |
118 | that._nbconvert('html', false); |
|
117 | that._nbconvert('html', false); | |
119 | }); |
|
118 | }); | |
120 |
|
119 | |||
121 | this.element.find('#download_py').click(function () { |
|
120 | this.element.find('#download_py').click(function () { | |
122 | that._nbconvert('python', true); |
|
121 | that._nbconvert('python', true); | |
123 | }); |
|
122 | }); | |
124 |
|
123 | |||
125 | this.element.find('#download_html').click(function () { |
|
124 | this.element.find('#download_html').click(function () { | |
126 | that._nbconvert('html', true); |
|
125 | that._nbconvert('html', true); | |
127 | }); |
|
126 | }); | |
128 |
|
127 | |||
129 | this.element.find('#download_rst').click(function () { |
|
128 | this.element.find('#download_rst').click(function () { | |
130 | that._nbconvert('rst', true); |
|
129 | that._nbconvert('rst', true); | |
131 | }); |
|
130 | }); | |
132 |
|
131 | |||
133 | this.element.find('#download_pdf').click(function () { |
|
132 | this.element.find('#download_pdf').click(function () { | |
134 | that._nbconvert('pdf', true); |
|
133 | that._nbconvert('pdf', true); | |
135 | }); |
|
134 | }); | |
136 |
|
135 | |||
137 | this.element.find('#rename_notebook').click(function () { |
|
136 | this.element.find('#rename_notebook').click(function () { | |
138 | that.save_widget.rename_notebook({notebook: that.notebook}); |
|
137 | that.save_widget.rename_notebook({notebook: that.notebook}); | |
139 | }); |
|
138 | }); | |
140 | this.element.find('#save_checkpoint').click(function () { |
|
139 | this.element.find('#save_checkpoint').click(function () { | |
141 | that.notebook.save_checkpoint(); |
|
140 | that.notebook.save_checkpoint(); | |
142 | }); |
|
141 | }); | |
143 | this.element.find('#restore_checkpoint').click(function () { |
|
142 | this.element.find('#restore_checkpoint').click(function () { | |
144 | }); |
|
143 | }); | |
145 | this.element.find('#trust_notebook').click(function () { |
|
144 | this.element.find('#trust_notebook').click(function () { | |
146 | that.notebook.trust_notebook(); |
|
145 | that.notebook.trust_notebook(); | |
147 | }); |
|
146 | }); | |
148 | this.events.on('trust_changed.Notebook', function (event, trusted) { |
|
147 | this.events.on('trust_changed.Notebook', function (event, trusted) { | |
149 | if (trusted) { |
|
148 | if (trusted) { | |
150 | that.element.find('#trust_notebook') |
|
149 | that.element.find('#trust_notebook') | |
151 | .addClass("disabled") |
|
150 | .addClass("disabled") | |
152 | .find("a").text("Trusted Notebook"); |
|
151 | .find("a").text("Trusted Notebook"); | |
153 | } else { |
|
152 | } else { | |
154 | that.element.find('#trust_notebook') |
|
153 | that.element.find('#trust_notebook') | |
155 | .removeClass("disabled") |
|
154 | .removeClass("disabled") | |
156 | .find("a").text("Trust Notebook"); |
|
155 | .find("a").text("Trust Notebook"); | |
157 | } |
|
156 | } | |
158 | }); |
|
157 | }); | |
159 | this.element.find('#kill_and_exit').click(function () { |
|
158 | this.element.find('#kill_and_exit').click(function () { | |
160 | that.notebook.session.delete(); |
|
159 | that.notebook.session.delete(); | |
161 | setTimeout(function(){ |
|
160 | setTimeout(function(){ | |
162 | // allow closing of new tabs in Chromium, impossible in FF |
|
161 | // allow closing of new tabs in Chromium, impossible in FF | |
163 | window.open('', '_self', ''); |
|
162 | window.open('', '_self', ''); | |
164 | window.close(); |
|
163 | window.close(); | |
165 | }, 500); |
|
164 | }, 500); | |
166 | }); |
|
165 | }); | |
167 | // Edit |
|
166 | // Edit | |
168 | this.element.find('#cut_cell').click(function () { |
|
167 | this.element.find('#cut_cell').click(function () { | |
169 | that.notebook.cut_cell(); |
|
168 | that.notebook.cut_cell(); | |
170 | }); |
|
169 | }); | |
171 | this.element.find('#copy_cell').click(function () { |
|
170 | this.element.find('#copy_cell').click(function () { | |
172 | that.notebook.copy_cell(); |
|
171 | that.notebook.copy_cell(); | |
173 | }); |
|
172 | }); | |
174 | this.element.find('#delete_cell').click(function () { |
|
173 | this.element.find('#delete_cell').click(function () { | |
175 | that.notebook.delete_cell(); |
|
174 | that.notebook.delete_cell(); | |
176 | }); |
|
175 | }); | |
177 | this.element.find('#undelete_cell').click(function () { |
|
176 | this.element.find('#undelete_cell').click(function () { | |
178 | that.notebook.undelete_cell(); |
|
177 | that.notebook.undelete_cell(); | |
179 | }); |
|
178 | }); | |
180 | this.element.find('#split_cell').click(function () { |
|
179 | this.element.find('#split_cell').click(function () { | |
181 | that.notebook.split_cell(); |
|
180 | that.notebook.split_cell(); | |
182 | }); |
|
181 | }); | |
183 | this.element.find('#merge_cell_above').click(function () { |
|
182 | this.element.find('#merge_cell_above').click(function () { | |
184 | that.notebook.merge_cell_above(); |
|
183 | that.notebook.merge_cell_above(); | |
185 | }); |
|
184 | }); | |
186 | this.element.find('#merge_cell_below').click(function () { |
|
185 | this.element.find('#merge_cell_below').click(function () { | |
187 | that.notebook.merge_cell_below(); |
|
186 | that.notebook.merge_cell_below(); | |
188 | }); |
|
187 | }); | |
189 | this.element.find('#move_cell_up').click(function () { |
|
188 | this.element.find('#move_cell_up').click(function () { | |
190 | that.notebook.move_cell_up(); |
|
189 | that.notebook.move_cell_up(); | |
191 | }); |
|
190 | }); | |
192 | this.element.find('#move_cell_down').click(function () { |
|
191 | this.element.find('#move_cell_down').click(function () { | |
193 | that.notebook.move_cell_down(); |
|
192 | that.notebook.move_cell_down(); | |
194 | }); |
|
193 | }); | |
195 | this.element.find('#edit_nb_metadata').click(function () { |
|
194 | this.element.find('#edit_nb_metadata').click(function () { | |
196 | that.notebook.edit_metadata({ |
|
195 | that.notebook.edit_metadata({ | |
197 | notebook: that.notebook, |
|
196 | notebook: that.notebook, | |
198 | keyboard_manager: that.notebook.keyboard_manager}); |
|
197 | keyboard_manager: that.notebook.keyboard_manager}); | |
199 | }); |
|
198 | }); | |
200 |
|
199 | |||
201 | // View |
|
200 | // View | |
202 | this.element.find('#toggle_header').click(function () { |
|
201 | this.element.find('#toggle_header').click(function () { | |
203 | $('div#header').toggle(); |
|
202 | $('div#header').toggle(); | |
204 | that.layout_manager.do_resize(); |
|
203 | that.layout_manager.do_resize(); | |
205 | }); |
|
204 | }); | |
206 | this.element.find('#toggle_toolbar').click(function () { |
|
205 | this.element.find('#toggle_toolbar').click(function () { | |
207 | $('div#maintoolbar').toggle(); |
|
206 | $('div#maintoolbar').toggle(); | |
208 | that.layout_manager.do_resize(); |
|
207 | that.layout_manager.do_resize(); | |
209 | }); |
|
208 | }); | |
210 | // Insert |
|
209 | // Insert | |
211 | this.element.find('#insert_cell_above').click(function () { |
|
210 | this.element.find('#insert_cell_above').click(function () { | |
212 | that.notebook.insert_cell_above('code'); |
|
211 | that.notebook.insert_cell_above('code'); | |
213 | that.notebook.select_prev(); |
|
212 | that.notebook.select_prev(); | |
214 | }); |
|
213 | }); | |
215 | this.element.find('#insert_cell_below').click(function () { |
|
214 | this.element.find('#insert_cell_below').click(function () { | |
216 | that.notebook.insert_cell_below('code'); |
|
215 | that.notebook.insert_cell_below('code'); | |
217 | that.notebook.select_next(); |
|
216 | that.notebook.select_next(); | |
218 | }); |
|
217 | }); | |
219 | // Cell |
|
218 | // Cell | |
220 | this.element.find('#run_cell').click(function () { |
|
219 | this.element.find('#run_cell').click(function () { | |
221 | that.notebook.execute_cell(); |
|
220 | that.notebook.execute_cell(); | |
222 | }); |
|
221 | }); | |
223 | this.element.find('#run_cell_select_below').click(function () { |
|
222 | this.element.find('#run_cell_select_below').click(function () { | |
224 | that.notebook.execute_cell_and_select_below(); |
|
223 | that.notebook.execute_cell_and_select_below(); | |
225 | }); |
|
224 | }); | |
226 | this.element.find('#run_cell_insert_below').click(function () { |
|
225 | this.element.find('#run_cell_insert_below').click(function () { | |
227 | that.notebook.execute_cell_and_insert_below(); |
|
226 | that.notebook.execute_cell_and_insert_below(); | |
228 | }); |
|
227 | }); | |
229 | this.element.find('#run_all_cells').click(function () { |
|
228 | this.element.find('#run_all_cells').click(function () { | |
230 | that.notebook.execute_all_cells(); |
|
229 | that.notebook.execute_all_cells(); | |
231 | }); |
|
230 | }); | |
232 | this.element.find('#run_all_cells_above').click(function () { |
|
231 | this.element.find('#run_all_cells_above').click(function () { | |
233 | that.notebook.execute_cells_above(); |
|
232 | that.notebook.execute_cells_above(); | |
234 | }); |
|
233 | }); | |
235 | this.element.find('#run_all_cells_below').click(function () { |
|
234 | this.element.find('#run_all_cells_below').click(function () { | |
236 | that.notebook.execute_cells_below(); |
|
235 | that.notebook.execute_cells_below(); | |
237 | }); |
|
236 | }); | |
238 | this.element.find('#to_code').click(function () { |
|
237 | this.element.find('#to_code').click(function () { | |
239 | that.notebook.to_code(); |
|
238 | that.notebook.to_code(); | |
240 | }); |
|
239 | }); | |
241 | this.element.find('#to_markdown').click(function () { |
|
240 | this.element.find('#to_markdown').click(function () { | |
242 | that.notebook.to_markdown(); |
|
241 | that.notebook.to_markdown(); | |
243 | }); |
|
242 | }); | |
244 | this.element.find('#to_raw').click(function () { |
|
243 | this.element.find('#to_raw').click(function () { | |
245 | that.notebook.to_raw(); |
|
244 | that.notebook.to_raw(); | |
246 | }); |
|
245 | }); | |
247 | this.element.find('#to_heading1').click(function () { |
|
246 | this.element.find('#to_heading1').click(function () { | |
248 | that.notebook.to_heading(undefined, 1); |
|
247 | that.notebook.to_heading(undefined, 1); | |
249 | }); |
|
248 | }); | |
250 | this.element.find('#to_heading2').click(function () { |
|
249 | this.element.find('#to_heading2').click(function () { | |
251 | that.notebook.to_heading(undefined, 2); |
|
250 | that.notebook.to_heading(undefined, 2); | |
252 | }); |
|
251 | }); | |
253 | this.element.find('#to_heading3').click(function () { |
|
252 | this.element.find('#to_heading3').click(function () { | |
254 | that.notebook.to_heading(undefined, 3); |
|
253 | that.notebook.to_heading(undefined, 3); | |
255 | }); |
|
254 | }); | |
256 | this.element.find('#to_heading4').click(function () { |
|
255 | this.element.find('#to_heading4').click(function () { | |
257 | that.notebook.to_heading(undefined, 4); |
|
256 | that.notebook.to_heading(undefined, 4); | |
258 | }); |
|
257 | }); | |
259 | this.element.find('#to_heading5').click(function () { |
|
258 | this.element.find('#to_heading5').click(function () { | |
260 | that.notebook.to_heading(undefined, 5); |
|
259 | that.notebook.to_heading(undefined, 5); | |
261 | }); |
|
260 | }); | |
262 | this.element.find('#to_heading6').click(function () { |
|
261 | this.element.find('#to_heading6').click(function () { | |
263 | that.notebook.to_heading(undefined, 6); |
|
262 | that.notebook.to_heading(undefined, 6); | |
264 | }); |
|
263 | }); | |
265 |
|
264 | |||
266 | this.element.find('#toggle_current_output').click(function () { |
|
265 | this.element.find('#toggle_current_output').click(function () { | |
267 | that.notebook.toggle_output(); |
|
266 | that.notebook.toggle_output(); | |
268 | }); |
|
267 | }); | |
269 | this.element.find('#toggle_current_output_scroll').click(function () { |
|
268 | this.element.find('#toggle_current_output_scroll').click(function () { | |
270 | that.notebook.toggle_output_scroll(); |
|
269 | that.notebook.toggle_output_scroll(); | |
271 | }); |
|
270 | }); | |
272 | this.element.find('#clear_current_output').click(function () { |
|
271 | this.element.find('#clear_current_output').click(function () { | |
273 | that.notebook.clear_output(); |
|
272 | that.notebook.clear_output(); | |
274 | }); |
|
273 | }); | |
275 |
|
274 | |||
276 | this.element.find('#toggle_all_output').click(function () { |
|
275 | this.element.find('#toggle_all_output').click(function () { | |
277 | that.notebook.toggle_all_output(); |
|
276 | that.notebook.toggle_all_output(); | |
278 | }); |
|
277 | }); | |
279 | this.element.find('#toggle_all_output_scroll').click(function () { |
|
278 | this.element.find('#toggle_all_output_scroll').click(function () { | |
280 | that.notebook.toggle_all_output_scroll(); |
|
279 | that.notebook.toggle_all_output_scroll(); | |
281 | }); |
|
280 | }); | |
282 | this.element.find('#clear_all_output').click(function () { |
|
281 | this.element.find('#clear_all_output').click(function () { | |
283 | that.notebook.clear_all_output(); |
|
282 | that.notebook.clear_all_output(); | |
284 | }); |
|
283 | }); | |
285 |
|
284 | |||
286 | // Kernel |
|
285 | // Kernel | |
287 | this.element.find('#int_kernel').click(function () { |
|
286 | this.element.find('#int_kernel').click(function () { | |
288 | that.notebook.session.interrupt_kernel(); |
|
287 | that.notebook.session.interrupt_kernel(); | |
289 | }); |
|
288 | }); | |
290 | this.element.find('#restart_kernel').click(function () { |
|
289 | this.element.find('#restart_kernel').click(function () { | |
291 | that.notebook.restart_kernel(); |
|
290 | that.notebook.restart_kernel(); | |
292 | }); |
|
291 | }); | |
293 | // Help |
|
292 | // Help | |
294 | if (this.tour) { |
|
293 | if (this.tour) { | |
295 | this.element.find('#notebook_tour').click(function () { |
|
294 | this.element.find('#notebook_tour').click(function () { | |
296 | that.tour.start(); |
|
295 | that.tour.start(); | |
297 | }); |
|
296 | }); | |
298 | } else { |
|
297 | } else { | |
299 | this.element.find('#notebook_tour').addClass("disabled"); |
|
298 | this.element.find('#notebook_tour').addClass("disabled"); | |
300 | } |
|
299 | } | |
301 | this.element.find('#keyboard_shortcuts').click(function () { |
|
300 | this.element.find('#keyboard_shortcuts').click(function () { | |
302 | that.quick_help.show_keyboard_shortcuts(); |
|
301 | that.quick_help.show_keyboard_shortcuts(); | |
303 | }); |
|
302 | }); | |
304 |
|
303 | |||
305 | this.update_restore_checkpoint(null); |
|
304 | this.update_restore_checkpoint(null); | |
306 |
|
305 | |||
307 | this.events.on('checkpoints_listed.Notebook', function (event, data) { |
|
306 | this.events.on('checkpoints_listed.Notebook', function (event, data) { | |
308 | that.update_restore_checkpoint(that.notebook.checkpoints); |
|
307 | that.update_restore_checkpoint(that.notebook.checkpoints); | |
309 | }); |
|
308 | }); | |
310 |
|
309 | |||
311 | this.events.on('checkpoint_created.Notebook', function (event, data) { |
|
310 | this.events.on('checkpoint_created.Notebook', function (event, data) { | |
312 | that.update_restore_checkpoint(that.notebook.checkpoints); |
|
311 | that.update_restore_checkpoint(that.notebook.checkpoints); | |
313 | }); |
|
312 | }); | |
314 | }; |
|
313 | }; | |
315 |
|
314 | |||
316 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { |
|
315 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { | |
317 | var ul = this.element.find("#restore_checkpoint").find("ul"); |
|
316 | var ul = this.element.find("#restore_checkpoint").find("ul"); | |
318 | ul.empty(); |
|
317 | ul.empty(); | |
319 | if (!checkpoints || checkpoints.length === 0) { |
|
318 | if (!checkpoints || checkpoints.length === 0) { | |
320 | ul.append( |
|
319 | ul.append( | |
321 | $("<li/>") |
|
320 | $("<li/>") | |
322 | .addClass("disabled") |
|
321 | .addClass("disabled") | |
323 | .append( |
|
322 | .append( | |
324 | $("<a/>") |
|
323 | $("<a/>") | |
325 | .text("No checkpoints") |
|
324 | .text("No checkpoints") | |
326 | ) |
|
325 | ) | |
327 | ); |
|
326 | ); | |
328 | return; |
|
327 | return; | |
329 | } |
|
328 | } | |
330 |
|
329 | |||
331 | var that = this; |
|
330 | var that = this; | |
332 | checkpoints.map(function (checkpoint) { |
|
331 | checkpoints.map(function (checkpoint) { | |
333 | var d = new Date(checkpoint.last_modified); |
|
332 | var d = new Date(checkpoint.last_modified); | |
334 | ul.append( |
|
333 | ul.append( | |
335 | $("<li/>").append( |
|
334 | $("<li/>").append( | |
336 | $("<a/>") |
|
335 | $("<a/>") | |
337 | .attr("href", "#") |
|
336 | .attr("href", "#") | |
338 | .text(d.format("mmm dd HH:MM:ss")) |
|
337 | .text(d.format("mmm dd HH:MM:ss")) | |
339 | .click(function () { |
|
338 | .click(function () { | |
340 | that.notebook.restore_checkpoint_dialog(checkpoint); |
|
339 | that.notebook.restore_checkpoint_dialog(checkpoint); | |
341 | }) |
|
340 | }) | |
342 | ) |
|
341 | ) | |
343 | ); |
|
342 | ); | |
344 | }); |
|
343 | }); | |
345 | }; |
|
344 | }; | |
346 |
|
345 | |||
347 | // Backwards compatability. |
|
346 | // Backwards compatability. | |
348 | IPython.MenuBar = MenuBar; |
|
347 | IPython.MenuBar = MenuBar; | |
349 |
|
348 | |||
350 | return {'MenuBar': MenuBar}; |
|
349 | return {'MenuBar': MenuBar}; | |
351 | }); |
|
350 | }); |
@@ -1,54 +1,55 | |||||
1 | #menubar { |
|
1 | #menubar { | |
2 | margin-top: 0px; |
|
2 | margin-top: 0px; | |
3 | margin-bottom: -19px; |
|
3 | margin-bottom: -19px; | |
4 | position: relative; |
|
4 | position: relative; | |
|
5 | .border-box-sizing(); | |||
5 |
|
6 | |||
6 | .navbar { |
|
7 | .navbar { | |
7 | border-top: 1px; |
|
8 | border-top: 1px; | |
8 | border-radius: 0px 0px @border-radius-base @border-radius-base; |
|
9 | border-radius: 0px 0px @border-radius-base @border-radius-base; | |
9 | } |
|
10 | } | |
10 |
|
11 | |||
11 |
|
12 | |||
12 | li.dropdown { |
|
13 | li.dropdown { | |
13 | line-height: 12px; |
|
14 | line-height: 12px; | |
14 |
|
15 | |||
15 | a { |
|
16 | a { | |
16 | padding-top: 6px; |
|
17 | padding-top: 6px; | |
17 | padding-bottom: 5px; |
|
18 | padding-bottom: 5px; | |
18 | } |
|
19 | } | |
19 | } |
|
20 | } | |
20 |
|
21 | |||
21 | ul.navbar-right { |
|
22 | ul.navbar-right { | |
22 | padding-top: 2px; |
|
23 | padding-top: 2px; | |
23 | } |
|
24 | } | |
24 | } |
|
25 | } | |
25 |
|
26 | |||
26 | .nav-wrapper { |
|
27 | .nav-wrapper { | |
27 | border-bottom: 1px solid @navbar-default-border; |
|
28 | border-bottom: 1px solid @navbar-default-border; | |
28 | } |
|
29 | } | |
29 |
|
30 | |||
30 | i.menu-icon { |
|
31 | i.menu-icon { | |
31 | // add padding to account for float-right |
|
32 | // add padding to account for float-right | |
32 | padding-top: 4px; |
|
33 | padding-top: 4px; | |
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 | ul#help_menu li a{ |
|
36 | ul#help_menu li a{ | |
36 | overflow: hidden; |
|
37 | overflow: hidden; | |
37 | padding-right: 2.2em; |
|
38 | padding-right: 2.2em; | |
38 | i { |
|
39 | i { | |
39 | margin-right: -1.2em; |
|
40 | margin-right: -1.2em; | |
40 | } |
|
41 | } | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | #menus { |
|
44 | #menus { | |
44 | min-height: 30px; |
|
45 | min-height: 30px; | |
45 | } |
|
46 | } | |
46 |
|
47 | |||
47 | // Make sub menus work in BS3. |
|
48 | // Make sub menus work in BS3. | |
48 | // Credit: http://www.bootply.com/86684 |
|
49 | // Credit: http://www.bootply.com/86684 | |
49 | .dropdown-submenu{position:relative;} |
|
50 | .dropdown-submenu{position:relative;} | |
50 | .dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} |
|
51 | .dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} | |
51 | .dropdown-submenu:hover>.dropdown-menu{display:block;} |
|
52 | .dropdown-submenu:hover>.dropdown-menu{display:block;} | |
52 | .dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#cccccc;margin-top:5px;margin-right:-10px;} |
|
53 | .dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#cccccc;margin-top:5px;margin-right:-10px;} | |
53 | .dropdown-submenu:hover>a:after{border-left-color:#ffffff;} |
|
54 | .dropdown-submenu:hover>a:after{border-left-color:#ffffff;} | |
54 | .dropdown-submenu.pull-left{float:none;}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px;} |
|
55 | .dropdown-submenu.pull-left{float:none;}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px;} |
General Comments 0
You need to be logged in to leave comments.
Login now