##// END OF EJS Templates
Merge pull request #7457 from minrk/rm-prevent-default...
Thomas Kluyver -
r19920:492fdbd9 merge
parent child Browse files
Show More
@@ -1,464 +1,466 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 define([
4 define([
5 'jquery',
5 'jquery',
6 'base/js/namespace',
6 'base/js/namespace',
7 'base/js/dialog',
7 'base/js/dialog',
8 'base/js/utils',
8 'base/js/utils',
9 'notebook/js/tour',
9 'notebook/js/tour',
10 'bootstrap',
10 'bootstrap',
11 'moment',
11 'moment',
12 ], function($, IPython, dialog, utils, tour, bootstrap, moment) {
12 ], function($, IPython, dialog, utils, tour, bootstrap, moment) {
13 "use strict";
13 "use strict";
14
14
15 var MenuBar = function (selector, options) {
15 var MenuBar = function (selector, options) {
16 /**
16 /**
17 * Constructor
17 * Constructor
18 *
18 *
19 * A MenuBar Class to generate the menubar of IPython notebook
19 * A MenuBar Class to generate the menubar of IPython notebook
20 *
20 *
21 * Parameters:
21 * Parameters:
22 * selector: string
22 * selector: string
23 * options: dictionary
23 * options: dictionary
24 * Dictionary of keyword arguments.
24 * Dictionary of keyword arguments.
25 * notebook: Notebook instance
25 * notebook: Notebook instance
26 * contents: ContentManager instance
26 * contents: ContentManager instance
27 * events: $(Events) instance
27 * events: $(Events) instance
28 * save_widget: SaveWidget instance
28 * save_widget: SaveWidget instance
29 * quick_help: QuickHelp instance
29 * quick_help: QuickHelp instance
30 * base_url : string
30 * base_url : string
31 * notebook_path : string
31 * notebook_path : string
32 * notebook_name : string
32 * notebook_name : string
33 */
33 */
34 options = options || {};
34 options = options || {};
35 this.base_url = options.base_url || utils.get_body_data("baseUrl");
35 this.base_url = options.base_url || utils.get_body_data("baseUrl");
36 this.selector = selector;
36 this.selector = selector;
37 this.notebook = options.notebook;
37 this.notebook = options.notebook;
38 this.contents = options.contents;
38 this.contents = options.contents;
39 this.events = options.events;
39 this.events = options.events;
40 this.save_widget = options.save_widget;
40 this.save_widget = options.save_widget;
41 this.quick_help = options.quick_help;
41 this.quick_help = options.quick_help;
42
42
43 try {
43 try {
44 this.tour = new tour.Tour(this.notebook, this.events);
44 this.tour = new tour.Tour(this.notebook, this.events);
45 } catch (e) {
45 } catch (e) {
46 this.tour = undefined;
46 this.tour = undefined;
47 console.log("Failed to instantiate Notebook Tour", e);
47 console.log("Failed to instantiate Notebook Tour", e);
48 }
48 }
49
49
50 if (this.selector !== undefined) {
50 if (this.selector !== undefined) {
51 this.element = $(selector);
51 this.element = $(selector);
52 this.style();
52 this.style();
53 this.bind_events();
53 this.bind_events();
54 }
54 }
55 };
55 };
56
56
57 // TODO: This has definitively nothing to do with style ...
57 // TODO: This has definitively nothing to do with style ...
58 MenuBar.prototype.style = function () {
58 MenuBar.prototype.style = function () {
59 var that = this;
59 var that = this;
60 this.element.find("li").click(function (event, ui) {
60 this.element.find("li").click(function (event, ui) {
61 // The selected cell loses focus when the menu is entered, so we
61 // The selected cell loses focus when the menu is entered, so we
62 // re-select it upon selection.
62 // re-select it upon selection.
63 var i = that.notebook.get_selected_index();
63 var i = that.notebook.get_selected_index();
64 that.notebook.select(i);
64 that.notebook.select(i);
65 event.preventDefault();
65 event.preventDefault();
66 }
66 }
67 );
67 );
68 };
68 };
69
69
70 MenuBar.prototype._nbconvert = function (format, download) {
70 MenuBar.prototype._nbconvert = function (format, download) {
71 download = download || false;
71 download = download || false;
72 var notebook_path = this.notebook.notebook_path;
72 var notebook_path = this.notebook.notebook_path;
73 var url = utils.url_join_encode(
73 var url = utils.url_join_encode(
74 this.base_url,
74 this.base_url,
75 'nbconvert',
75 'nbconvert',
76 format,
76 format,
77 notebook_path
77 notebook_path
78 ) + "?download=" + download.toString();
78 ) + "?download=" + download.toString();
79
79
80 var w = window.open();
80 var w = window.open();
81 if (this.notebook.dirty) {
81 if (this.notebook.dirty) {
82 this.notebook.save_notebook().then(function() {
82 this.notebook.save_notebook().then(function() {
83 w.location = url;
83 w.location = url;
84 });
84 });
85 } else {
85 } else {
86 w.location = url;
86 w.location = url;
87 }
87 }
88 };
88 };
89
89
90 MenuBar.prototype._size_header = function() {
90 MenuBar.prototype._size_header = function() {
91 /**
91 /**
92 * Update header spacer size.
92 * Update header spacer size.
93 */
93 */
94 this.events.trigger('resize-header.Page');
94 this.events.trigger('resize-header.Page');
95 };
95 };
96
96
97 MenuBar.prototype.bind_events = function () {
97 MenuBar.prototype.bind_events = function () {
98 /**
98 /**
99 * File
99 * File
100 */
100 */
101 var that = this;
101 var that = this;
102
102
103 this.element.find('#open_notebook').click(function () {
103 this.element.find('#open_notebook').click(function () {
104 var parent = utils.url_path_split(that.notebook.notebook_path)[0];
104 var parent = utils.url_path_split(that.notebook.notebook_path)[0];
105 window.open(utils.url_join_encode(that.base_url, 'tree', parent));
105 window.open(utils.url_join_encode(that.base_url, 'tree', parent));
106 // all if(event) are here to let test pass
106 // all if(event) are here to let test pass
107 // as evnet might not be devined when clicking with
107 // as evnet might not be devined when clicking with
108 // casper.js
108 // casper.js
109 if(event)event.preventDefault();
109 if(event)event.preventDefault();
110 });
110 });
111 this.element.find('#copy_notebook').click(function () {
111 this.element.find('#copy_notebook').click(function () {
112 that.notebook.copy_notebook();
112 that.notebook.copy_notebook();
113 return false;
113 return false;
114 });
114 });
115 this.element.find('#download_ipynb').click(function () {
115 this.element.find('#download_ipynb').click(function () {
116 var base_url = that.notebook.base_url;
116 var base_url = that.notebook.base_url;
117 var notebook_path = that.notebook.notebook_path;
117 var notebook_path = that.notebook.notebook_path;
118 if (that.notebook.dirty) {
118 if (that.notebook.dirty) {
119 that.notebook.save_notebook({async : false});
119 that.notebook.save_notebook({async : false});
120 }
120 }
121
121
122 var url = utils.url_join_encode(base_url, 'files', notebook_path);
122 var url = utils.url_join_encode(base_url, 'files', notebook_path);
123 window.open(url + '?download=1');
123 window.open(url + '?download=1');
124 if(event)event.preventDefault();
124 if(event)event.preventDefault();
125 });
125 });
126
126
127 this.element.find('#print_preview').click(function () {
127 this.element.find('#print_preview').click(function () {
128 that._nbconvert('html', false);
128 that._nbconvert('html', false);
129 if(event)event.preventDefault();
129 if(event)event.preventDefault();
130 });
130 });
131
131
132 this.element.find('#download_html').click(function () {
132 this.element.find('#download_html').click(function () {
133 that._nbconvert('html', true);
133 that._nbconvert('html', true);
134 if(event)event.preventDefault();
134 if(event)event.preventDefault();
135 });
135 });
136
136
137 this.element.find('#download_rst').click(function () {
137 this.element.find('#download_rst').click(function () {
138 that._nbconvert('rst', true);
138 that._nbconvert('rst', true);
139 if(event)event.preventDefault();
139 if(event)event.preventDefault();
140 });
140 });
141
141
142 this.element.find('#download_pdf').click(function () {
142 this.element.find('#download_pdf').click(function () {
143 that._nbconvert('pdf', true);
143 that._nbconvert('pdf', true);
144 if(event)event.preventDefault();
144 if(event)event.preventDefault();
145 });
145 });
146
146
147 this.element.find('#download_script').click(function () {
147 this.element.find('#download_script').click(function () {
148 that._nbconvert('script', true);
148 that._nbconvert('script', true);
149 if(event)event.preventDefault();
149 if(event)event.preventDefault();
150 });
150 });
151
151
152 this.element.find('#rename_notebook').click(function () {
152 this.element.find('#rename_notebook').click(function () {
153 that.save_widget.rename_notebook({notebook: that.notebook});
153 that.save_widget.rename_notebook({notebook: that.notebook});
154 if(event)event.preventDefault();
154 if(event)event.preventDefault();
155 });
155 });
156
156
157 this.element.find('#save_checkpoint').click(function () {
157 this.element.find('#save_checkpoint').click(function () {
158 that.notebook.save_checkpoint();
158 that.notebook.save_checkpoint();
159 if(event)event.preventDefault();
159 if(event)event.preventDefault();
160 });
160 });
161
161
162 this.element.find('#restore_checkpoint').click(function () {
162 this.element.find('#restore_checkpoint').click(function () {
163 });
163 });
164
164
165 this.element.find('#trust_notebook').click(function () {
165 this.element.find('#trust_notebook').click(function () {
166 that.notebook.trust_notebook();
166 that.notebook.trust_notebook();
167 if(event)event.preventDefault();
167 if(event)event.preventDefault();
168 });
168 });
169 this.events.on('trust_changed.Notebook', function (event, trusted) {
169 this.events.on('trust_changed.Notebook', function (event, trusted) {
170 if (trusted) {
170 if (trusted) {
171 that.element.find('#trust_notebook')
171 that.element.find('#trust_notebook')
172 .addClass("disabled")
172 .addClass("disabled").off('click')
173 .find("a").text("Trusted Notebook");
173 .find("a").text("Trusted Notebook");
174 } else {
174 } else {
175 that.element.find('#trust_notebook')
175 that.element.find('#trust_notebook')
176 .removeClass("disabled")
176 .removeClass("disabled").on('click', function () {
177 that.notebook.trust_notebook();
178 })
177 .find("a").text("Trust Notebook");
179 .find("a").text("Trust Notebook");
178 }
180 }
179 if(event)event.preventDefault();
181 if(event)event.preventDefault();
180 });
182 });
181
183
182 this.element.find('#kill_and_exit').click(function () {
184 this.element.find('#kill_and_exit').click(function () {
183 var close_window = function () {
185 var close_window = function () {
184 /**
186 /**
185 * allow closing of new tabs in Chromium, impossible in FF
187 * allow closing of new tabs in Chromium, impossible in FF
186 */
188 */
187 window.open('', '_self', '');
189 window.open('', '_self', '');
188 window.close();
190 window.close();
189 };
191 };
190 // finish with close on success or failure
192 // finish with close on success or failure
191 that.notebook.session.delete(close_window, close_window);
193 that.notebook.session.delete(close_window, close_window);
192 if(event)event.preventDefault();
194 if(event)event.preventDefault();
193 });
195 });
194
196
195 // Edit
197 // Edit
196 this.element.find('#cut_cell').click(function () {
198 this.element.find('#cut_cell').click(function () {
197 that.notebook.cut_cell();
199 that.notebook.cut_cell();
198 if(event)event.preventDefault();
200 if(event)event.preventDefault();
199 });
201 });
200 this.element.find('#copy_cell').click(function () {
202 this.element.find('#copy_cell').click(function () {
201 that.notebook.copy_cell();
203 that.notebook.copy_cell();
202 if(event)event.preventDefault();
204 if(event)event.preventDefault();
203 });
205 });
204 this.element.find('#delete_cell').click(function () {
206 this.element.find('#delete_cell').click(function () {
205 that.notebook.delete_cell();
207 that.notebook.delete_cell();
206 if(event)event.preventDefault();
208 if(event)event.preventDefault();
207 });
209 });
208 this.element.find('#undelete_cell').click(function () {
210 this.element.find('#undelete_cell').click(function () {
209 that.notebook.undelete_cell();
211 that.notebook.undelete_cell();
210 if(event)event.preventDefault();
212 if(event)event.preventDefault();
211 });
213 });
212 this.element.find('#split_cell').click(function () {
214 this.element.find('#split_cell').click(function () {
213 that.notebook.split_cell();
215 that.notebook.split_cell();
214 if(event)event.preventDefault();
216 if(event)event.preventDefault();
215 });
217 });
216 this.element.find('#merge_cell_above').click(function () {
218 this.element.find('#merge_cell_above').click(function () {
217 that.notebook.merge_cell_above();
219 that.notebook.merge_cell_above();
218 if(event)event.preventDefault();
220 if(event)event.preventDefault();
219 });
221 });
220 this.element.find('#merge_cell_below').click(function () {
222 this.element.find('#merge_cell_below').click(function () {
221 that.notebook.merge_cell_below();
223 that.notebook.merge_cell_below();
222 if(event)event.preventDefault();
224 if(event)event.preventDefault();
223 });
225 });
224 this.element.find('#move_cell_up').click(function () {
226 this.element.find('#move_cell_up').click(function () {
225 that.notebook.move_cell_up();
227 that.notebook.move_cell_up();
226 if(event)event.preventDefault();
228 if(event)event.preventDefault();
227 });
229 });
228 this.element.find('#move_cell_down').click(function () {
230 this.element.find('#move_cell_down').click(function () {
229 that.notebook.move_cell_down();
231 that.notebook.move_cell_down();
230 if(event)event.preventDefault();
232 if(event)event.preventDefault();
231 });
233 });
232 this.element.find('#edit_nb_metadata').click(function () {
234 this.element.find('#edit_nb_metadata').click(function () {
233 that.notebook.edit_metadata({
235 that.notebook.edit_metadata({
234 notebook: that.notebook,
236 notebook: that.notebook,
235 keyboard_manager: that.notebook.keyboard_manager});
237 keyboard_manager: that.notebook.keyboard_manager});
236 if(event)event.preventDefault();
238 if(event)event.preventDefault();
237 });
239 });
238
240
239 // View
241 // View
240 this.element.find('#toggle_header').click(function () {
242 this.element.find('#toggle_header').click(function () {
241 $('div#header-container').toggle();
243 $('div#header-container').toggle();
242 that._size_header();
244 that._size_header();
243 if(event)event.preventDefault();
245 if(event)event.preventDefault();
244 });
246 });
245 this.element.find('#toggle_toolbar').click(function () {
247 this.element.find('#toggle_toolbar').click(function () {
246 $('div#maintoolbar').toggle();
248 $('div#maintoolbar').toggle();
247 that._size_header();
249 that._size_header();
248 if(event)event.preventDefault();
250 if(event)event.preventDefault();
249 });
251 });
250 // Insert
252 // Insert
251 this.element.find('#insert_cell_above').click(function () {
253 this.element.find('#insert_cell_above').click(function () {
252 that.notebook.insert_cell_above('code');
254 that.notebook.insert_cell_above('code');
253 that.notebook.select_prev();
255 that.notebook.select_prev();
254 if(event)event.preventDefault();
256 if(event)event.preventDefault();
255 });
257 });
256 this.element.find('#insert_cell_below').click(function () {
258 this.element.find('#insert_cell_below').click(function () {
257 that.notebook.insert_cell_below('code');
259 that.notebook.insert_cell_below('code');
258 that.notebook.select_next();
260 that.notebook.select_next();
259 if(event)event.preventDefault();
261 if(event)event.preventDefault();
260 });
262 });
261 // Cell
263 // Cell
262 this.element.find('#run_cell').click(function () {
264 this.element.find('#run_cell').click(function () {
263 that.notebook.execute_cell();
265 that.notebook.execute_cell();
264 if(event)event.preventDefault();
266 if(event)event.preventDefault();
265 });
267 });
266 this.element.find('#run_cell_select_below').click(function () {
268 this.element.find('#run_cell_select_below').click(function () {
267 that.notebook.execute_cell_and_select_below();
269 that.notebook.execute_cell_and_select_below();
268 if(event)event.preventDefault();
270 if(event)event.preventDefault();
269 });
271 });
270 this.element.find('#run_cell_insert_below').click(function () {
272 this.element.find('#run_cell_insert_below').click(function () {
271 that.notebook.execute_cell_and_insert_below();
273 that.notebook.execute_cell_and_insert_below();
272 if(event)event.preventDefault();
274 if(event)event.preventDefault();
273 });
275 });
274 this.element.find('#run_all_cells').click(function () {
276 this.element.find('#run_all_cells').click(function () {
275 that.notebook.execute_all_cells();
277 that.notebook.execute_all_cells();
276 if(event)event.preventDefault();
278 if(event)event.preventDefault();
277 });
279 });
278 this.element.find('#run_all_cells_above').click(function () {
280 this.element.find('#run_all_cells_above').click(function () {
279 that.notebook.execute_cells_above();
281 that.notebook.execute_cells_above();
280 if(event)event.preventDefault();
282 if(event)event.preventDefault();
281 });
283 });
282 this.element.find('#run_all_cells_below').click(function () {
284 this.element.find('#run_all_cells_below').click(function () {
283 that.notebook.execute_cells_below();
285 that.notebook.execute_cells_below();
284 if(event)event.preventDefault();
286 if(event)event.preventDefault();
285 });
287 });
286 this.element.find('#to_code').click(function () {
288 this.element.find('#to_code').click(function () {
287 that.notebook.to_code();
289 that.notebook.to_code();
288 if(event)event.preventDefault();
290 if(event)event.preventDefault();
289 });
291 });
290 this.element.find('#to_markdown').click(function () {
292 this.element.find('#to_markdown').click(function () {
291 that.notebook.to_markdown();
293 that.notebook.to_markdown();
292 if(event)event.preventDefault();
294 if(event)event.preventDefault();
293 });
295 });
294 this.element.find('#to_raw').click(function () {
296 this.element.find('#to_raw').click(function () {
295 that.notebook.to_raw();
297 that.notebook.to_raw();
296 if(event)event.preventDefault();
298 if(event)event.preventDefault();
297 });
299 });
298
300
299 this.element.find('#toggle_current_output').click(function () {
301 this.element.find('#toggle_current_output').click(function () {
300 that.notebook.toggle_output();
302 that.notebook.toggle_output();
301 if(event)event.preventDefault();
303 if(event)event.preventDefault();
302 });
304 });
303 this.element.find('#toggle_current_output_scroll').click(function () {
305 this.element.find('#toggle_current_output_scroll').click(function () {
304 that.notebook.toggle_output_scroll();
306 that.notebook.toggle_output_scroll();
305 if(event)event.preventDefault();
307 if(event)event.preventDefault();
306 });
308 });
307 this.element.find('#clear_current_output').click(function () {
309 this.element.find('#clear_current_output').click(function () {
308 that.notebook.clear_output();
310 that.notebook.clear_output();
309 if(event)event.preventDefault();
311 if(event)event.preventDefault();
310 });
312 });
311
313
312 this.element.find('#toggle_all_output').click(function () {
314 this.element.find('#toggle_all_output').click(function () {
313 that.notebook.toggle_all_output();
315 that.notebook.toggle_all_output();
314 if(event)event.preventDefault();
316 if(event)event.preventDefault();
315 });
317 });
316 this.element.find('#toggle_all_output_scroll').click(function () {
318 this.element.find('#toggle_all_output_scroll').click(function () {
317 that.notebook.toggle_all_output_scroll();
319 that.notebook.toggle_all_output_scroll();
318 if(event)event.preventDefault();
320 if(event)event.preventDefault();
319 });
321 });
320 this.element.find('#clear_all_output').click(function () {
322 this.element.find('#clear_all_output').click(function () {
321 that.notebook.clear_all_output();
323 that.notebook.clear_all_output();
322 if(event)event.preventDefault();
324 if(event)event.preventDefault();
323 });
325 });
324
326
325 // Kernel
327 // Kernel
326 this.element.find('#int_kernel').click(function () {
328 this.element.find('#int_kernel').click(function () {
327 that.notebook.kernel.interrupt();
329 that.notebook.kernel.interrupt();
328 if(event)event.preventDefault();
330 if(event)event.preventDefault();
329 });
331 });
330 this.element.find('#restart_kernel').click(function () {
332 this.element.find('#restart_kernel').click(function () {
331 that.notebook.restart_kernel();
333 that.notebook.restart_kernel();
332 if(event)event.preventDefault();
334 if(event)event.preventDefault();
333 });
335 });
334 this.element.find('#reconnect_kernel').click(function () {
336 this.element.find('#reconnect_kernel').click(function () {
335 that.notebook.kernel.reconnect();
337 that.notebook.kernel.reconnect();
336 if(event)event.preventDefault();
338 if(event)event.preventDefault();
337 });
339 });
338 // Help
340 // Help
339 if (this.tour) {
341 if (this.tour) {
340 this.element.find('#notebook_tour').click(function () {
342 this.element.find('#notebook_tour').click(function () {
341 that.tour.start();
343 that.tour.start();
342 if(event)event.preventDefault();
344 if(event)event.preventDefault();
343 });
345 });
344 } else {
346 } else {
345 this.element.find('#notebook_tour').addClass("disabled");
347 this.element.find('#notebook_tour').addClass("disabled");
346 }
348 }
347 this.element.find('#keyboard_shortcuts').click(function () {
349 this.element.find('#keyboard_shortcuts').click(function () {
348 that.quick_help.show_keyboard_shortcuts();
350 that.quick_help.show_keyboard_shortcuts();
349 if(event)event.preventDefault();
351 if(event)event.preventDefault();
350 });
352 });
351
353
352 this.update_restore_checkpoint(null);
354 this.update_restore_checkpoint(null);
353
355
354 this.events.on('checkpoints_listed.Notebook', function (event, data) {
356 this.events.on('checkpoints_listed.Notebook', function (event, data) {
355 that.update_restore_checkpoint(that.notebook.checkpoints);
357 that.update_restore_checkpoint(that.notebook.checkpoints);
356 if(event)event.preventDefault();
358 if(event)event.preventDefault();
357 });
359 });
358
360
359 this.events.on('checkpoint_created.Notebook', function (event, data) {
361 this.events.on('checkpoint_created.Notebook', function (event, data) {
360 that.update_restore_checkpoint(that.notebook.checkpoints);
362 that.update_restore_checkpoint(that.notebook.checkpoints);
361 if(event)event.preventDefault();
363 if(event)event.preventDefault();
362 });
364 });
363
365
364 this.events.on('notebook_loaded.Notebook', function() {
366 this.events.on('notebook_loaded.Notebook', function() {
365 var langinfo = that.notebook.metadata.language_info || {};
367 var langinfo = that.notebook.metadata.language_info || {};
366 that.update_nbconvert_script(langinfo);
368 that.update_nbconvert_script(langinfo);
367 if(event)event.preventDefault();
369 if(event)event.preventDefault();
368 });
370 });
369
371
370 this.events.on('kernel_ready.Kernel', function(event, data) {
372 this.events.on('kernel_ready.Kernel', function(event, data) {
371 var langinfo = data.kernel.info_reply.language_info || {};
373 var langinfo = data.kernel.info_reply.language_info || {};
372 that.update_nbconvert_script(langinfo);
374 that.update_nbconvert_script(langinfo);
373 that.add_kernel_help_links(data.kernel.info_reply.help_links || []);
375 that.add_kernel_help_links(data.kernel.info_reply.help_links || []);
374 if(event)event.preventDefault();
376 if(event)event.preventDefault();
375 });
377 });
376 };
378 };
377
379
378 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
380 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
379 var ul = this.element.find("#restore_checkpoint").find("ul");
381 var ul = this.element.find("#restore_checkpoint").find("ul");
380 ul.empty();
382 ul.empty();
381 if (!checkpoints || checkpoints.length === 0) {
383 if (!checkpoints || checkpoints.length === 0) {
382 ul.append(
384 ul.append(
383 $("<li/>")
385 $("<li/>")
384 .addClass("disabled")
386 .addClass("disabled")
385 .append(
387 .append(
386 $("<a/>")
388 $("<a/>")
387 .text("No checkpoints")
389 .text("No checkpoints")
388 )
390 )
389 );
391 );
390 return;
392 return;
391 }
393 }
392
394
393 var that = this;
395 var that = this;
394 checkpoints.map(function (checkpoint) {
396 checkpoints.map(function (checkpoint) {
395 var d = new Date(checkpoint.last_modified);
397 var d = new Date(checkpoint.last_modified);
396 ul.append(
398 ul.append(
397 $("<li/>").append(
399 $("<li/>").append(
398 $("<a/>")
400 $("<a/>")
399 .attr("href", "#")
401 .attr("href", "#")
400 .text(moment(d).format("LLLL"))
402 .text(moment(d).format("LLLL"))
401 .click(function () {
403 .click(function () {
402 that.notebook.restore_checkpoint_dialog(checkpoint);
404 that.notebook.restore_checkpoint_dialog(checkpoint);
403 if(event)event.preventDefault();
405 if(event)event.preventDefault();
404 })
406 })
405 )
407 )
406 );
408 );
407 });
409 });
408 };
410 };
409
411
410 MenuBar.prototype.update_nbconvert_script = function(langinfo) {
412 MenuBar.prototype.update_nbconvert_script = function(langinfo) {
411 /**
413 /**
412 * Set the 'Download as foo' menu option for the relevant language.
414 * Set the 'Download as foo' menu option for the relevant language.
413 */
415 */
414 var el = this.element.find('#download_script');
416 var el = this.element.find('#download_script');
415
417
416 // Set menu entry text to e.g. "Python (.py)"
418 // Set menu entry text to e.g. "Python (.py)"
417 var langname = (langinfo.name || 'Script');
419 var langname = (langinfo.name || 'Script');
418 langname = langname.charAt(0).toUpperCase()+langname.substr(1); // Capitalise
420 langname = langname.charAt(0).toUpperCase()+langname.substr(1); // Capitalise
419 el.find('a').text(langname + ' ('+(langinfo.file_extension || 'txt')+')');
421 el.find('a').text(langname + ' ('+(langinfo.file_extension || 'txt')+')');
420 };
422 };
421
423
422 MenuBar.prototype.add_kernel_help_links = function(help_links) {
424 MenuBar.prototype.add_kernel_help_links = function(help_links) {
423 /** add links from kernel_info to the help menu */
425 /** add links from kernel_info to the help menu */
424 var divider = $("#kernel-help-links");
426 var divider = $("#kernel-help-links");
425 if (divider.length === 0) {
427 if (divider.length === 0) {
426 // insert kernel help section above about link
428 // insert kernel help section above about link
427 var about = $("#notebook_about").parent();
429 var about = $("#notebook_about").parent();
428 divider = $("<li>")
430 divider = $("<li>")
429 .attr('id', "kernel-help-links")
431 .attr('id', "kernel-help-links")
430 .addClass('divider');
432 .addClass('divider');
431 about.prev().before(divider);
433 about.prev().before(divider);
432 }
434 }
433 // remove previous entries
435 // remove previous entries
434 while (!divider.next().hasClass('divider')) {
436 while (!divider.next().hasClass('divider')) {
435 divider.next().remove();
437 divider.next().remove();
436 }
438 }
437 if (help_links.length === 0) {
439 if (help_links.length === 0) {
438 // no help links, remove the divider
440 // no help links, remove the divider
439 divider.remove();
441 divider.remove();
440 return;
442 return;
441 }
443 }
442 var cursor = divider;
444 var cursor = divider;
443 help_links.map(function (link) {
445 help_links.map(function (link) {
444 cursor.after($("<li>")
446 cursor.after($("<li>")
445 .append($("<a>")
447 .append($("<a>")
446 .attr('target', '_blank')
448 .attr('target', '_blank')
447 .attr('title', 'Opens in a new window')
449 .attr('title', 'Opens in a new window')
448 .attr('href', link.url)
450 .attr('href', link.url)
449 .text(link.text)
451 .text(link.text)
450 .append($("<i>")
452 .append($("<i>")
451 .addClass("fa fa-external-link menu-icon pull-right")
453 .addClass("fa fa-external-link menu-icon pull-right")
452 )
454 )
453 )
455 )
454 );
456 );
455 cursor = cursor.next();
457 cursor = cursor.next();
456 });
458 });
457
459
458 };
460 };
459
461
460 // Backwards compatability.
462 // Backwards compatability.
461 IPython.MenuBar = MenuBar;
463 IPython.MenuBar = MenuBar;
462
464
463 return {'MenuBar': MenuBar};
465 return {'MenuBar': MenuBar};
464 });
466 });
General Comments 0
You need to be logged in to leave comments. Login now