##// END OF EJS Templates
Fix variable scope.
Fix variable scope.

File last commit:

r19951:dcae386b
r20332:5765b2ce
Show More
maintoolbar.js
164 lines | 5.7 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 'require',
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 './toolbar',
Bussonnier Matthias
return elements instead of append them directly...
r19481 './celltoolbar'
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 ], function(require, IPython, $, toolbar, celltoolbar) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
Matthias BUSSONNIER
add maintoolbar file
r7833
jon
In person review with @ellisonbg
r17210 var MainToolBar = function (selector, options) {
Bussonnier Matthias
fix john coments
r19424 /**
* Constructor
*
* Parameters:
* selector: string
* options: dictionary
* Dictionary of keyword arguments.
* events: $(Events) instance
* notebook: Notebook instance
**/
Matthias Bussonnier
fix rebase after kill of layout manager
r19445 toolbar.ToolBar.apply(this, [selector, options] );
jon
In person review with @ellisonbg
r17210 this.events = options.events;
this.notebook = options.notebook;
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 this._make();
Min RK
disable keyboard events on main toolbar...
r19896 this.notebook.keyboard_manager.register_events(this.element);
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 Object.seal(this);
Matthias BUSSONNIER
add maintoolbar file
r7833 };
Matthias Bussonnier
Use low overhead object heritence in Js (Object.create vs new)...
r18377 MainToolBar.prototype = Object.create(toolbar.ToolBar.prototype);
Matthias BUSSONNIER
add maintoolbar file
r7833
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 MainToolBar.prototype._make = function () {
var grps = [
[
['ipython.save-notebook'],
'save-notbook'
],
[
['ipython.insert-cell-after'],
'insert_above_below'],
[
['ipython.cut-selected-cell',
'ipython.copy-selected-cell',
'ipython.paste-cell-after'
] ,
'cut_copy_paste'],
[
['ipython.move-selected-cell-up',
'ipython.move-selected-cell-down'
],
'move_up_down'],
[ ['ipython.run-select-next',
'ipython.interrupt-kernel',
Bussonnier Matthias
return elements instead of append them directly...
r19481 'ipython.restart-kernel'
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 ],
'run_int'],
['<add_celltype_list>'],
Bussonnier Matthias
return elements instead of append them directly...
r19481 ['<add_celltoolbar_list>']
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 ];
this.construct(grps);
Matthias BUSSONNIER
jslint 1
r8209 };
jon
Fixed cell toolbar dropdown
r16934
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 // add a cell type drop down to the maintoolbar.
Matthias Bussonnier
adresses Min comments x2
r19427 // triggered when the pseudo action `<add_celltype_list>` is
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 // encountered when building a toolbar.
Bussonnier Matthias
make pseudo action in their own dcit....
r19447 MainToolBar.prototype._pseudo_actions.add_celltype_list = function () {
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 var that = this;
var sel = $('<select/>')
.attr('id','cell_type')
.addClass('form-control select-xs')
.append($('<option/>').attr('value','code').text('Code'))
.append($('<option/>').attr('value','markdown').text('Markdown'))
.append($('<option/>').attr('value','raw').text('Raw NBConvert'))
.append($('<option/>').attr('value','heading').text('Heading'));
this.events.on('selected_cell_type_changed.Notebook', function (event, data) {
if (data.cell_type === 'heading') {
sel.val('Markdown');
} else {
sel.val(data.cell_type);
}
});
sel.change(function () {
var cell_type = $(this).val();
switch (cell_type) {
case 'code':
that.notebook.to_code();
break;
case 'markdown':
that.notebook.to_markdown();
break;
case 'raw':
that.notebook.to_raw();
break;
case 'heading':
that.notebook._warn_heading();
that.notebook.to_heading();
Bussonnier Matthias
return elements instead of append them directly...
r19481 sel.val('markdown');
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 break;
default:
console.log("unrecognized cell type:", cell_type);
}
Bussonnier Matthias
Do not leave toolbar element focused....
r19951 that.notebook.focus_cell();
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 });
Bussonnier Matthias
return elements instead of append them directly...
r19481 return sel;
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423
Matthias BUSSONNIER
reorder methods and fix typo
r8212 };
Bussonnier Matthias
make pseudo action in their own dcit....
r19447 MainToolBar.prototype._pseudo_actions.add_celltoolbar_list = function () {
MinRK
bootstrap toolbar
r10889 var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:');
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 var select = $('<select/>')
.attr('id', 'ctb_select')
Jonathan Frederic
Make maintoolbar select dropdowns look nice
r16948 .addClass('form-control select-xs')
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 .append($('<option/>').attr('value', '').text('None'));
Jonathan Frederic
Fixed cell toolbars
r17217 var that = this;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 select.change(function() {
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 var val = $(this).val();
if (val ==='') {
Jonathan Frederic
Fix imports of "modules",...
r17202 celltoolbar.CellToolbar.global_hide();
Jonathan Frederic
Fix all the bugs!
r17203 delete that.notebook.metadata.celltoolbar;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 } else {
Jonathan Frederic
Fix imports of "modules",...
r17202 celltoolbar.CellToolbar.global_show();
Jonathan Frederic
Fixed cell toolbars
r17217 celltoolbar.CellToolbar.activate_preset(val, that.events);
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.metadata.celltoolbar = val;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 }
Bussonnier Matthias
Do not leave toolbar element focused....
r19951 that.notebook.focus_cell();
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 });
// Setup the currently registered presets.
Jonathan Frederic
Fix imports of "modules",...
r17202 var presets = celltoolbar.CellToolbar.list_presets();
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 for (var i=0; i<presets.length; i++) {
var name = presets[i];
select.append($('<option/>').attr('value', name).text(name));
}
// Setup future preset registrations.
Jonathan Frederic
Progress...
r17196 this.events.on('preset_added.CellToolbar', function (event, data) {
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 var name = data.name;
select.append($('<option/>').attr('value', name).text(name));
});
Bussonnier Matthias
add ability to unregister a preset...
r19586 this.events.on('unregistered_preset.CellToolbar', function (event, data) {
if (select.val() === data.name){
select.val('');
celltoolbar.CellToolbar.global_hide();
delete that.notebook.metadata.celltoolbar;
}
select.find("option[value='"+name+"']" ).remove();
});
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 // Update select value when a preset is activated.
Jonathan Frederic
Progress...
r17196 this.events.on('preset_activated.CellToolbar', function (event, data) {
Bussonnier Matthias
add ability to unregister a preset...
r19586 if (select.val() !== data.name){
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 select.val(data.name);
Bussonnier Matthias
add ability to unregister a preset...
r19586 }
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 });
Bussonnier Matthias
return elements instead of append them directly...
r19481
var wrapper = $('<div/>').addClass('btn-group');
wrapper.append(label).append(select);
return wrapper;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 };
Matthias Bussonnier
Add notion of actions to celltoolbar...
r19423 // Backwards compatibility.
Matthias BUSSONNIER
add maintoolbar file
r7833 IPython.MainToolBar = MainToolBar;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'MainToolBar': MainToolBar};
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 });