##// END OF EJS Templates
minor fixes in dashboard tests...
minor fixes in dashboard tests events and regular expressions weren't quite right, which could cause occasional test failures.

File last commit:

r17414:d2e61f9b
r17716:da60ef6a
Show More
maintoolbar.js
230 lines | 8.5 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([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 'notebook/js/toolbar',
Jonathan Frederic
Progress...
r17196 'notebook/js/celltoolbar',
Jonathan Frederic
Fix all the bugs!
r17203 ], function(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) {
jon
Added some nice comments,...
r17211 // Constructor
//
// Parameters:
// selector: string
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// notebook: Notebook instance
Jonathan Frederic
Fix all the bugs!
r17203 toolbar.ToolBar.apply(this, arguments);
jon
In person review with @ellisonbg
r17210 this.events = options.events;
this.notebook = options.notebook;
Matthias BUSSONNIER
check for selector only in parent classes
r8213 this.construct();
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 this.add_celltype_list();
this.add_celltoolbar_list();
Matthias BUSSONNIER
check for selector only in parent classes
r8213 this.bind_events();
Matthias BUSSONNIER
add maintoolbar file
r7833 };
Jonathan Frederic
Fix all the bugs!
r17203 MainToolBar.prototype = new toolbar.ToolBar();
Matthias BUSSONNIER
add maintoolbar file
r7833
Matthias BUSSONNIER
space around :
r8210 MainToolBar.prototype.construct = function () {
Jonathan Frederic
Fix all the bugs!
r17203 var that = this;
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'save_b',
MinRK
Save and Checkpoint
r10513 label : 'Save and Checkpoint',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-save',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.save_checkpoint();
Matthias BUSSONNIER
jslint 1
r8209 }
}
Matthias BUSSONNIER
add maintoolbar file
r7833 ]);
Susan Tan
Fixed #2923 Move Save Away from Cut in toolbar
r13731
this.add_buttons_group([
{
id : 'insert_below_b',
label : 'Insert Cell Below',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-plus',
Susan Tan
Fixed #2923 Move Save Away from Cut in toolbar
r13731 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.insert_cell_below('code');
that.notebook.select_next();
that.notebook.focus_cell();
Susan Tan
Fixed #2923 Move Save Away from Cut in toolbar
r13731 }
}
],'insert_above_below');
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'cut_b',
label : 'Cut Cell',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-cut',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.cut_cell();
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'copy_b',
label : 'Copy Cell',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-copy',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.copy_cell();
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'paste_b',
Matthias BUSSONNIER
past below by default
r8770 label : 'Paste Cell Below',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-paste',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.paste_cell_below();
Matthias BUSSONNIER
jslint 1
r8209 }
}
Matthias BUSSONNIER
add maintoolbar file
r7833 ],'cut_copy_paste');
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'move_up_b',
label : 'Move Cell Up',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-arrow-up',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.move_cell_up();
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'move_down_b',
label : 'Move Cell Down',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-arrow-down',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.move_cell_down();
Matthias BUSSONNIER
jslint 1
r8209 }
}
Matthias BUSSONNIER
add maintoolbar file
r7833 ],'move_up_down');
jon
Added function to create Bootstrap specific drop down.
r16931
Matthias BUSSONNIER
add maintoolbar file
r7833
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'run_b',
label : 'Run Cell',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-play',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
MinRK
make execute button in menu bar match shift-enter...
r15179 // emulate default shift-enter behavior
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.execute_cell_and_select_below();
MinRK
make execute button in menu bar match shift-enter...
r15179 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'interrupt_b',
label : 'Interrupt',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-stop',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.session.interrupt_kernel();
Matthias BUSSONNIER
jslint 1
r8209 }
Brian E. Granger
Add kernel restart button to toolbar.
r14866 },
{
id : 'repeat_b',
label : 'Restart Kernel',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-repeat',
Brian E. Granger
Add kernel restart button to toolbar.
r14866 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.restart_kernel();
Brian E. Granger
Add kernel restart button to toolbar.
r14866 }
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 ],'run_int');
Matthias BUSSONNIER
jslint 1
r8209 };
jon
Fixed cell toolbar dropdown
r16934
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 MainToolBar.prototype.add_celltype_list = function () {
this.element
Matthias BUSSONNIER
reorder methods and fix typo
r8212 .append($('<select/>')
.attr('id','cell_type')
Jonathan Frederic
Make maintoolbar select dropdowns look nice
r16948 .addClass('form-control select-xs')
MinRK
bootstrap toolbar
r10889 // .addClass('ui-widget-content')
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 .append($('<option/>').attr('value','code').text('Code'))
.append($('<option/>').attr('value','markdown').text('Markdown'))
MinRK
add raw cell toolbar preset
r13671 .append($('<option/>').attr('value','raw').text('Raw NBConvert'))
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 .append($('<option/>').attr('value','heading1').text('Heading 1'))
.append($('<option/>').attr('value','heading2').text('Heading 2'))
.append($('<option/>').attr('value','heading3').text('Heading 3'))
.append($('<option/>').attr('value','heading4').text('Heading 4'))
.append($('<option/>').attr('value','heading5').text('Heading 5'))
.append($('<option/>').attr('value','heading6').text('Heading 6'))
);
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/>')
MinRK
bootstrap toolbar
r10889 // .addClass('ui-widget-content')
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 .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 maintoolbar file
r7833 MainToolBar.prototype.bind_events = function () {
var that = this;
jon
Added function to create Bootstrap specific drop down.
r16931
Matthias BUSSONNIER
add maintoolbar file
r7833 this.element.find('#cell_type').change(function () {
var cell_type = $(this).val();
if (cell_type === 'code') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_code();
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'markdown') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_markdown();
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'raw') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_raw();
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'heading1') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_heading(undefined, 1);
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'heading2') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_heading(undefined, 2);
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'heading3') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_heading(undefined, 3);
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'heading4') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_heading(undefined, 4);
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'heading5') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_heading(undefined, 5);
Matthias BUSSONNIER
add maintoolbar file
r7833 } else if (cell_type === 'heading6') {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_heading(undefined, 6);
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 });
Jonathan Frederic
Progress...
r17196 this.events.on('selected_cell_type_changed.Notebook', function (event, data) {
Matthias BUSSONNIER
add maintoolbar file
r7833 if (data.cell_type === 'heading') {
that.element.find('#cell_type').val(data.cell_type+data.level);
} else {
that.element.find('#cell_type').val(data.cell_type);
}
});
};
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 // Backwards compatability.
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 });