##// END OF EJS Templates
Update celltoolbar.js...
Update celltoolbar.js I want to write an extension with multiple select bar. They are supposed to be displayed inline, not in block mode. The better way is to use span instead of div.

File last commit:

r17216:08b8fbc9
r17265:950b016a
Show More
menubar.js
351 lines | 12.4 KiB | application/javascript | JavascriptLexer
MinRK
support pdf export in the notebook UI
r16266 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Brian Granger
Implemented menu based UI using Wijmo.
r5857
Jonathan Frederic
Almost done!...
r17198 define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Almost done!...
r17198 'base/js/utils',
'notebook/js/tour',
Jonathan Frederic
Fix all the tests
r17216 'components/bootstrap/js/bootstrap.min',
Jonathan Frederic
Fix imports of "modules",...
r17202 ], function(IPython, $, utils, tour) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
MinRK
save before download-as...
r13076
jon
In person review with @ellisonbg
r17210 var MenuBar = function (selector, options) {
jon
Added some nice comments,...
r17211 // Constructor
//
// A MenuBar Class to generate the menubar of IPython notebook
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// notebook: Notebook instance
// layout_manager: LayoutManager instance
// events: $(Events) instance
// save_widget: SaveWidget instance
// quick_help: QuickHelp instance
// base_url : string
// notebook_path : string
// notebook_name : string
MinRK
review pass on multidir js
r13103 options = options || {};
Jonathan Frederic
Almost done!...
r17198 this.base_url = options.base_url || utils.get_body_data("baseUrl");
Brian Granger
Implemented menu based UI using Wijmo.
r5857 this.selector = selector;
jon
In person review with @ellisonbg
r17210 this.notebook = options.notebook;
this.layout_manager = options.layout_manager;
this.events = options.events;
this.save_widget = options.save_widget;
this.quick_help = options.quick_help;
Jonathan Frederic
Almost done!...
r17198
try {
jon
In person review with @ellisonbg
r17210 this.tour = new tour.Tour(this.notebook, this.events);
Jonathan Frederic
Almost done!...
r17198 } catch (e) {
this.tour = undefined;
console.log("Failed to instantiate Notebook Tour", e);
}
Brian Granger
Implemented menu based UI using Wijmo.
r5857 if (this.selector !== undefined) {
this.element = $(selector);
this.style();
this.bind_events();
}
};
MenuBar.prototype.style = function () {
Jonathan Frederic
MWE,...
r17200 var that = this;
Brian Granger
Major refactoring of notebook....
r6193 this.element.addClass('border-box-sizing');
MinRK
bootstrap menubar
r10888 this.element.find("li").click(function (event, ui) {
Brian Granger
Fixing minor typo in menubar.js.
r5908 // The selected cell loses focus when the menu is entered, so we
Brian Granger
Cell splitting and merging is done!
r5898 // re-select it upon selection.
Jonathan Frederic
MWE,...
r17200 var i = that.notebook.get_selected_index();
that.notebook.select(i);
Brian Granger
Cell splitting and merging is done!
r5898 }
MinRK
bootstrap menubar
r10888 );
Brian Granger
Implemented menu based UI using Wijmo.
r5857 };
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829 MenuBar.prototype._nbconvert = function (format, download) {
download = download || false;
Jonathan Frederic
Almost done!...
r17198 var notebook_path = this.notebook.notebook_path;
var notebook_name = this.notebook.notebook_name;
if (this.notebook.dirty) {
this.notebook.save_notebook({async : false});
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829 }
MinRK
various unicode fixes...
r15234 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829 'nbconvert',
format,
MinRK
fix notebook_path in menu bar
r15239 notebook_path,
notebook_name
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829 ) + "?download=" + download.toString();
Thomas Kluyver
Download as always starts downloads in new window/tab...
r13838 window.open(url);
MinRK
various unicode fixes...
r15234 };
Brian Granger
Implemented menu based UI using Wijmo.
r5857
MenuBar.prototype.bind_events = function () {
// File
Matthias BUSSONNIER
fix baseUrl
r9699 var that = this;
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 this.element.find('#new_notebook').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.new_notebook();
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 });
this.element.find('#open_notebook').click(function () {
MinRK
make sure to encode URL components for API requests...
r13693 window.open(utils.url_join_encode(
Jonathan Frederic
Almost done!...
r17198 that.notebook.base_url,
MinRK
review pass on multidir js
r13103 'tree',
Jonathan Frederic
Almost done!...
r17198 that.notebook.notebook_path
MinRK
review pass on multidir js
r13103 ));
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 });
this.element.find('#copy_notebook').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.copy_notebook();
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 return false;
});
this.element.find('#download_ipynb').click(function () {
Jonathan Frederic
Almost done!...
r17198 var base_url = that.notebook.base_url;
var notebook_path = that.notebook.notebook_path;
var notebook_name = that.notebook.notebook_name;
if (that.notebook.dirty) {
that.notebook.save_notebook({async : false});
MinRK
save before download-as...
r13076 }
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
various unicode fixes...
r15234 base_url,
Brian E. Granger
Handle notebook downloads through the /files URL.
r13114 'files',
MinRK
various unicode fixes...
r15234 notebook_path,
MinRK
fix notebook_path in menu bar
r15239 notebook_name
MinRK
save before download-as...
r13076 );
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 window.location.assign(url);
});
MinRK
disable download-as-pt...
r13108
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829 this.element.find('#print_preview').click(function () {
that._nbconvert('html', false);
});
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 this.element.find('#download_py').click(function () {
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829 that._nbconvert('python', true);
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 });
Thomas Kluyver
Add menu entries for getting converted views of a notebook
r13829
this.element.find('#download_html').click(function () {
that._nbconvert('html', true);
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 });
Thomas Kluyver
Add option to download as reST
r13831
this.element.find('#download_rst').click(function () {
that._nbconvert('rst', true);
});
MinRK
support pdf export in the notebook UI
r16266 this.element.find('#download_pdf').click(function () {
that._nbconvert('pdf', true);
});
Brian Granger
Improved notebook renaming....
r5859 this.element.find('#rename_notebook').click(function () {
Jonathan Frederic
Fix some dialog keyboard_manager problems
r17213 that.save_widget.rename_notebook({notebook: that.notebook});
Brian Granger
Improved notebook renaming....
r5859 });
MinRK
expose notebook checkpoints in html/js...
r10501 this.element.find('#save_checkpoint').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.save_checkpoint();
MinRK
expose notebook checkpoints in html/js...
r10501 });
MinRK
add Revert to the menu bar
r10503 this.element.find('#restore_checkpoint').click(function () {
});
MinRK
Add Trust Notebook to File menu
r15655 this.element.find('#trust_notebook').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.trust_notebook();
MinRK
Add Trust Notebook to File menu
r15655 });
Jonathan Frederic
Almost done!...
r17198 this.events.on('trust_changed.Notebook', function (event, trusted) {
MinRK
disable trust notebook menu item on trusted notebooks
r15657 if (trusted) {
that.element.find('#trust_notebook')
.addClass("disabled")
.find("a").text("Trusted Notebook");
} else {
that.element.find('#trust_notebook')
.removeClass("disabled")
.find("a").text("Trust Notebook");
}
});
Matthias BUSSONNIER
add 'Close and halt' in notebook filemenu
r6850 this.element.find('#kill_and_exit').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.session.delete();
Paul Ivanov
make close-and-halt work on new tabs in Chrome...
r13338 setTimeout(function(){
// allow closing of new tabs in Chromium, impossible in FF
window.open('', '_self', '');
window.close();
}, 500);
Matthias BUSSONNIER
add 'Close and halt' in notebook filemenu
r6850 });
Brian Granger
Implemented menu based UI using Wijmo.
r5857 // Edit
Brian Granger
Added cell level cut/copy/paste.
r5879 this.element.find('#cut_cell').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.cut_cell();
Brian Granger
Added cell level cut/copy/paste.
r5879 });
this.element.find('#copy_cell').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.copy_cell();
Brian Granger
Added cell level cut/copy/paste.
r5879 });
Brian Granger
Implemented menu based UI using Wijmo.
r5857 this.element.find('#delete_cell').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.delete_cell();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
MinRK
add menu item for undo delete cell...
r9551 this.element.find('#undelete_cell').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.undelete_cell();
MinRK
add menu item for undo delete cell...
r9551 });
Brian Granger
Basic code cell splitting implemented.
r5896 this.element.find('#split_cell').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.split_cell();
Brian Granger
Basic code cell splitting implemented.
r5896 });
this.element.find('#merge_cell_above').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.merge_cell_above();
Brian Granger
Basic code cell splitting implemented.
r5896 });
this.element.find('#merge_cell_below').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.merge_cell_below();
Brian Granger
Basic code cell splitting implemented.
r5896 });
Brian Granger
Implemented menu based UI using Wijmo.
r5857 this.element.find('#move_cell_up').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.move_cell_up();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
this.element.find('#move_cell_down').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.move_cell_down();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
MinRK
add Edit Notebook Metadata to Edit menu
r12913 this.element.find('#edit_nb_metadata').click(function () {
Jonathan Frederic
More review changes
r17214 that.notebook.edit_metadata({
notebook: that.notebook,
keyboard_manager: that.notebook.keyboard_manager});
MinRK
add Edit Notebook Metadata to Edit menu
r12913 });
Brian Granger
Further work on the toolbar UI....
r5994 // View
this.element.find('#toggle_header').click(function () {
$('div#header').toggle();
Jonathan Frederic
Almost done!...
r17198 that.layout_manager.do_resize();
Brian Granger
Further work on the toolbar UI....
r5994 });
this.element.find('#toggle_toolbar').click(function () {
MinRK
tweak header styling...
r10906 $('div#maintoolbar').toggle();
Jonathan Frederic
Almost done!...
r17198 that.layout_manager.do_resize();
Brian Granger
Further work on the toolbar UI....
r5994 });
Brian Granger
Implemented menu based UI using Wijmo.
r5857 // Insert
this.element.find('#insert_cell_above').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.insert_cell_above('code');
that.notebook.select_prev();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
this.element.find('#insert_cell_below').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.insert_cell_below('code');
that.notebook.select_next();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
// Cell
this.element.find('#run_cell').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.execute_cell();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
Brian E. Granger
Renaming execute methods.
r14085 this.element.find('#run_cell_select_below').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.execute_cell_and_select_below();
Brian E. Granger
Renaming execute methods.
r14085 });
this.element.find('#run_cell_insert_below').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.execute_cell_and_insert_below();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
this.element.find('#run_all_cells').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.execute_all_cells();
Paul Ivanov
javascript is no place to start adding title tags
r13159 });
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 this.element.find('#run_all_cells_above').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.execute_cells_above();
Paul Ivanov
javascript is no place to start adding title tags
r13159 });
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 this.element.find('#run_all_cells_below').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.execute_cells_below();
Paul Ivanov
javascript is no place to start adding title tags
r13159 });
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 this.element.find('#to_code').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_code();
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_markdown').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_markdown();
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_raw').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_raw();
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_heading1').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_heading(undefined, 1);
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_heading2').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_heading(undefined, 2);
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_heading3').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_heading(undefined, 3);
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_heading4').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_heading(undefined, 4);
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_heading5').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_heading(undefined, 5);
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#to_heading6').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.to_heading(undefined, 6);
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
Brian E. Granger
Simplified Cell menu items related to output.
r14871
this.element.find('#toggle_current_output').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.toggle_output();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
Brian E. Granger
Simplified Cell menu items related to output.
r14871 this.element.find('#toggle_current_output_scroll').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.toggle_output_scroll();
Brian Granger
A first go at RST cell support in the notebook.
r6017 });
Brian E. Granger
Cleaning up output management in code and menus.
r14867 this.element.find('#clear_current_output').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.clear_output();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
Brian E. Granger
Simplified Cell menu items related to output.
r14871
this.element.find('#toggle_all_output').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.toggle_all_output();
MinRK
third attempt at scrolled long output...
r7362 });
Brian E. Granger
Simplified Cell menu items related to output.
r14871 this.element.find('#toggle_all_output_scroll').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.toggle_all_output_scroll();
MinRK
third attempt at scrolled long output...
r7362 });
Brian Granger
Implemented menu based UI using Wijmo.
r5857 this.element.find('#clear_all_output').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.clear_all_output();
Brian Granger
Implemented menu based UI using Wijmo.
r5857 });
Brian E. Granger
Simplified Cell menu items related to output.
r14871
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 // Kernel
this.element.find('#int_kernel').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.session.interrupt_kernel();
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
this.element.find('#restart_kernel').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.restart_kernel();
Brian E. Granger
Adding back Kernel menu and Cell Type submenu.
r14869 });
Brian Granger
Cleaning up menu code....
r5858 // Help
Jonathan Frederic
Almost done!...
r17198 if (this.tour) {
MinRK
allow notebook tour instantiation to fail...
r16672 this.element.find('#notebook_tour').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.tour.start();
MinRK
allow notebook tour instantiation to fail...
r16672 });
} else {
this.element.find('#notebook_tour').addClass("disabled");
}
Brian Granger
Cleaning up menu code....
r5858 this.element.find('#keyboard_shortcuts').click(function () {
Jonathan Frederic
Almost done!...
r17198 that.quick_help.show_keyboard_shortcuts();
Brian Granger
Cleaning up menu code....
r5858 });
MinRK
add Revert to the menu bar
r10503
this.update_restore_checkpoint(null);
Jonathan Frederic
Almost done!...
r17198 this.events.on('checkpoints_listed.Notebook', function (event, data) {
that.update_restore_checkpoint(that.notebook.checkpoints);
MinRK
add Revert to the menu bar
r10503 });
Jonathan Frederic
Almost done!...
r17198 this.events.on('checkpoint_created.Notebook', function (event, data) {
that.update_restore_checkpoint(that.notebook.checkpoints);
MinRK
add Revert to the menu bar
r10503 });
Brian Granger
Implemented menu based UI using Wijmo.
r5857 };
MinRK
restore checkpoints in a sub-list...
r10520 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
MinRK
add 'No Checkpoints' to Revert menu...
r11117 var ul = this.element.find("#restore_checkpoint").find("ul");
ul.empty();
MinRK
review pass on multidir js
r13103 if (!checkpoints || checkpoints.length === 0) {
MinRK
add 'No Checkpoints' to Revert menu...
r11117 ul.append(
$("<li/>")
.addClass("disabled")
.append(
$("<a/>")
.text("No checkpoints")
)
);
return;
MinRK
review pass on multidir js
r13103 }
MinRK
remove debug statement...
r11164
Jonathan Frederic
Almost done!...
r17198 var that = this;
MinRK
minor checkpoint cleanup...
r12050 checkpoints.map(function (checkpoint) {
MinRK
restore checkpoints in a sub-list...
r10520 var d = new Date(checkpoint.last_modified);
MinRK
add 'No Checkpoints' to Revert menu...
r11117 ul.append(
$("<li/>").append(
$("<a/>")
.attr("href", "#")
.text(d.format("mmm dd HH:MM:ss"))
.click(function () {
Jonathan Frederic
Almost done!...
r17198 that.notebook.restore_checkpoint_dialog(checkpoint);
MinRK
add 'No Checkpoints' to Revert menu...
r11117 })
)
);
MinRK
minor checkpoint cleanup...
r12050 });
MinRK
restore checkpoints in a sub-list...
r10520 };
Brian Granger
Implemented menu based UI using Wijmo.
r5857
Jonathan Frederic
Almost done!...
r17198 // Backwards compatability.
Brian Granger
Implemented menu based UI using Wijmo.
r5857 IPython.MenuBar = MenuBar;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'MenuBar': MenuBar};
Jonathan Frederic
Almost done!...
r17198 });