##// END OF EJS Templates
adresses Min comments x2
r19427:ad73ac4a
Show More
maintoolbar.js
152 lines | 5.2 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',
'./celltoolbar',
], 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
Add notion of actions to celltoolbar...
r19423 toolbar.ToolBar.apply(this, [selector, undefined ,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();
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 // thought, this might not be the best way as dict might not keep the right order.
// Might want to put the group name as second to make it optional
//
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',
'ipython.restart-kernel',
],
'run_int'],
['<add_celltype_list>'],
['<add_celltoolbar_list>'],
];
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.
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 MainToolBar.prototype.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();
sel.val('markdown')
break;
default:
console.log("unrecognized cell type:", cell_type);
}
});
this.element.append(sel);
Matthias BUSSONNIER
reorder methods and fix typo
r8212 };
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 MainToolBar.prototype.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'));
this.element.append(label).append(select);
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 }
});
// 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));
});
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) {
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 if (select.val() !== data.name)
select.val(data.name);
});
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 });