##// END OF EJS Templates
Merge pull request #7457 from minrk/rm-prevent-default...
Merge pull request #7457 from minrk/rm-prevent-default disable trust-notebook click event

File last commit:

r19886:9443bd65
r19920:492fdbd9 merge
Show More
notebook.js
2434 lines | 79.9 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.
Jonathan Frederic
Start JSDoc integration
r19503 /**
* @module notebook
*/
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 define([
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 'base/js/utils',
'base/js/dialog',
Min RK
Handle unrecognized outputs and cells from the future
r18999 'notebook/js/cell',
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 'notebook/js/textcell',
'notebook/js/codecell',
Thomas Kluyver
Remove user_config js module
r19529 'services/config',
MinRK
remove unnecessary 'js' subdir from services...
r18422 'services/sessions/session',
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 'notebook/js/celltoolbar',
Jonathan Frederic
Almost done!...
r17198 'components/marked/lib/marked',
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 'codemirror/lib/codemirror',
'codemirror/addon/runmode/runmode',
Jonathan Frederic
Almost done!...
r17198 'notebook/js/mathjaxutils',
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 'base/js/keyboard',
Jonathan Frederic
More requirejs fixes
r17215 'notebook/js/tooltip',
Jonathan Frederic
Fixed cell toolbars
r17217 'notebook/js/celltoolbarpresets/default',
'notebook/js/celltoolbarpresets/rawcell',
'notebook/js/celltoolbarpresets/slideshow',
Jonathan Frederic
Added scroll mode selector,...
r17869 'notebook/js/scrollmanager'
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 ], function (
IPython,
Min RK
Handle unrecognized outputs and cells from the future
r18999 $,
utils,
dialog,
cellmod,
textcell,
codecell,
Thomas Kluyver
Remove user_config js module
r19529 configmod,
Jonathan Frederic
Fix imports of "modules",...
r17202 session,
Min RK
Handle unrecognized outputs and cells from the future
r18999 celltoolbar,
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 marked,
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 CodeMirror,
runMode,
Jonathan Frederic
Almost done!...
r17198 mathjaxutils,
Jonathan Frederic
More requirejs fixes
r17215 keyboard,
Jonathan Frederic
Fixed cell toolbars
r17217 tooltip,
default_celltoolbar,
rawcell_celltoolbar,
Jonathan Frederic
Added scroll mode selector,...
r17869 slideshow_celltoolbar,
scrollmanager
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 ) {
Matthias Bussonnier
Some cleanup unused code and missig use-strict
r18991 "use strict";
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192
Jonathan Frederic
Start JSDoc integration
r19503 /**
Jonathan Frederic
Make notebook.js jsdoc compatible
r19505 * Contains and manages cells.
Jonathan Frederic
Clean up comments
r19511 *
Jonathan Frederic
Make notebook.js jsdoc compatible
r19505 * @class Notebook
Jonathan Frederic
Clean up comments
r19511 * @param {string} selector
* @param {object} options - Dictionary of keyword arguments.
* @param {jQuery} options.events - selector of Events
* @param {KeyboardManager} options.keyboard_manager
* @param {Contents} options.contents
* @param {SaveWidget} options.save_widget
* @param {object} options.config
* @param {string} options.base_url
* @param {string} options.notebook_path
* @param {string} options.notebook_name
Jonathan Frederic
Start JSDoc integration
r19503 */
jon
In person review with @ellisonbg
r17210 var Notebook = function (selector, options) {
Thomas Kluyver
Remove user_config js module
r19529 this.config = options.config;
this.class_config = new configmod.ConfigWithDefaults(this.config,
Notebook.options_default, 'Notebook');
jon
In person review with @ellisonbg
r17210 this.base_url = options.base_url;
this.notebook_path = options.notebook_path;
this.notebook_name = options.notebook_name;
this.events = options.events;
this.keyboard_manager = options.keyboard_manager;
Jeff Hemmelgarn
Move contentmanager to contents
r18643 this.contents = options.contents;
jon
In person review with @ellisonbg
r17210 this.save_widget = options.save_widget;
Jonathan Frederic
Fix all the tests
r17216 this.tooltip = new tooltip.Tooltip(this.events);
MinRK
pass ws_url to kernel constructor...
r17308 this.ws_url = options.ws_url;
MinRK
avoid race condition when deleting/starting sessions...
r17649 this._session_starting = false;
Jonathan Frederic
Added scroll mode selector,...
r17869
Jonathan Frederic
Removed ScrollManager selector combo.
r17872 // Create default scroll manager.
Jonathan Frederic
Make the default the single page scroller.
r17880 this.scroll_manager = new scrollmanager.ScrollManager(this);
Jonathan Frederic
Removed ScrollManager selector combo.
r17872
Jonathan Frederic
@carreau review changes
r17204 // TODO: This code smells (and the other `= this` line a couple lines down)
// We need a better way to deal with circular instance references.
jon
In person review with @ellisonbg
r17210 this.keyboard_manager.notebook = this;
this.save_widget.notebook = this;
Jonathan Frederic
Almost done!...
r17198
mathjaxutils.init();
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194
if (marked) {
marked.setOptions({
gfm : true,
tables: true,
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 // FIXME: probably want central config for CodeMirror theme when we have js config
langPrefix: "cm-s-ipython language-",
highlight: function(code, lang, callback) {
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 if (!lang) {
// no language, no highlight
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 if (callback) {
callback(null, code);
return;
} else {
return code;
}
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 }
Nicholas Bollweg (Nick)
using codemirror mode/meta for detection
r19286 utils.requireCodeMirrorMode(lang, function (spec) {
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 var el = document.createElement("div");
Nicholas Bollweg (Nick)
using codemirror mode/meta for detection
r19286 var mode = CodeMirror.getMode({}, spec);
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 if (!mode) {
console.log("No CodeMirror mode: " + lang);
callback(null, code);
return;
}
try {
Nicholas Bollweg (Nick)
using codemirror mode/meta for detection
r19286 CodeMirror.runMode(code, spec, el);
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 callback(null, el.innerHTML);
} catch (err) {
Min RK
handle various permission failures...
r19005 console.log("Failed to highlight " + lang + " code", err);
MinRK
use CodeMirror.runMode to highlight in markdown...
r18864 callback(err, code);
}
}, function (err) {
console.log("No CodeMirror mode: " + lang);
callback(err, code);
});
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 }
});
}
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.element = $(selector);
this.element.scroll();
this.element.data("notebook", this);
this.next_prompt_number = 1;
Zachary Sailer
manual rebase static/notebook/js files
r12986 this.session = null;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.kernel = null;
Brian Granger
Added cell level cut/copy/paste.
r5879 this.clipboard = null;
David Warde-Farley
Add a simple 'undo' for cell deletion....
r8691 this.undelete_backup = null;
this.undelete_index = null;
this.undelete_below = false;
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 this.paste_enabled = false;
Min RK
handle various permission failures...
r19005 this.writable = false;
Brian E. Granger
Lots of updates and changes....
r14021 // It is important to start out in command mode to match the intial mode
// of the KeyboardManager.
Brian E. Granger
More work on the dual mode UX.
r14015 this.mode = 'command';
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(false);
Brian E. Granger
Implemented metadata for notebook format.
r4637 this.metadata = {};
MinRK
expose notebook checkpoints in html/js...
r10501 this._checkpoint_after_save = false;
this.last_checkpoint = null;
MinRK
minor checkpoint cleanup...
r12050 this.checkpoints = [];
MinRK
add autosave timer...
r10505 this.autosave_interval = 0;
this.autosave_timer = null;
MinRK
set default autosave interval to two minutes
r10507 // autosave *at most* every two minutes
this.minimum_autosave_interval = 120000;
Brian Granger
Make : invalid in filenames in the Notebook JS code.
r7229 this.notebook_name_blacklist_re = /[\/\\:]/;
MinRK
update html/js to nbformat 4
r18584 this.nbformat = 4; // Increment this when changing the nbformat
Min RK
Preserve nbformat_minor from the future...
r19107 this.nbformat_minor = this.current_nbformat_minor = 0; // Increment this when changing the nbformat
Matthias BUSSONNIER
remove js styling, already done in css + deprecate warning
r17425 this.codemirror_mode = 'ipython';
Brian E. Granger
Improving the scrolling model.
r4364 this.create_elements();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.bind_events();
Matthias Bussonnier
Some cleanup unused code and missig use-strict
r18991 this.kernel_selector = null;
this.dirty = null;
this.trusted = null;
this._fully_loaded = false;
Jonathan Frederic
Fixed cell toolbars
r17217
// Trigger cell toolbar registration.
Matthias BUSSONNIER
Use global event for celltoolbar
r17454 default_celltoolbar.register(this);
rawcell_celltoolbar.register(this);
slideshow_celltoolbar.register(this);
Matthias Bussonnier
Some cleanup unused code and missig use-strict
r18991
// prevent assign to miss-typed properties.
Object.seal(this);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Jonathan Frederic
Added scroll mode selector,...
r17869
MinRK
make default cell type configurable...
r17785 Notebook.options_default = {
// can be any cell type, or the special values of
// 'above', 'below', or 'selected' to get the value from another cell.
Thomas Kluyver
Fix default_cell_type option for notebook
r19530 default_cell_type: 'code'
MinRK
make default cell type configurable...
r17785 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Create an HTML and CSS representation of the notebook.
*/
Brian E. Granger
Improving the scrolling model.
r4364 Notebook.prototype.create_elements = function () {
Brian E. Granger
Binding to notebook div not document.
r14018 var that = this;
this.element.attr('tabindex','-1');
this.container = $("<div/>").addClass("container").attr("id", "notebook-container");
Brian E. Granger
Improving the scrolling model.
r4364 // We add this end_space div to the end of the notebook div to:
// i) provide a margin between the last cell and the end of the notebook
// ii) to prevent the div from scrolling up when the last cell is being
// edited, but is too low on the page, which browsers will do automatically.
MinRK
specify end-space height in less
r10938 var end_space = $('<div/>').addClass('end_space');
Brian E. Granger
Double clicking on the end space will insert a new cell.
r4628 end_space.dblclick(function (e) {
var ncells = that.ncells();
Brian Granger
Refactoring of the notebooks cell management....
r5945 that.insert_cell_below('code',ncells-1);
Brian E. Granger
Double clicking on the end space will insert a new cell.
r4628 });
MinRK
only put the notebook in a container...
r10909 this.element.append(this.container);
this.container.append(end_space);
Brian E. Granger
Improving the scrolling model.
r4364 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Bind JavaScript events: key presses and custom IPython events.
*/
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.bind_events = function () {
var that = this;
Matthias BUSSONNIER
Clean code, retab and minor fix...
r7170
Jonathan Frederic
Fixed events
r17195 this.events.on('set_next_input.Notebook', function (event, data) {
Thomas Kluyver
Machinery to replace the current cell instead of adding a new one
r19250 if (data.replace) {
data.cell.set_text(data.text);
Thomas Kluyver
Clear output after replacing cell contents
r19252 data.cell.clear_output();
Thomas Kluyver
Machinery to replace the current cell instead of adding a new one
r19250 } else {
var index = that.find_cell_index(data.cell);
var new_cell = that.insert_cell_below('code',index);
new_cell.set_text(data.text);
}
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 that.dirty = true;
});
Min RK
Preserve nbformat_minor from the future...
r19107 this.events.on('unrecognized_cell.Cell', function () {
that.warn_nbformat_minor();
});
this.events.on('unrecognized_output.OutputArea', function () {
that.warn_nbformat_minor();
});
Jonathan Frederic
Fixed events
r17195 this.events.on('set_dirty.Notebook', function (event, data) {
Brian Granger
Making Notebook.set_dirty an event so CodeCell can set it....
r7228 that.dirty = data.value;
});
MinRK
trigger trust_changed properly on load...
r18196 this.events.on('trust_changed.Notebook', function (event, trusted) {
that.trusted = trusted;
MinRK
disable trust notebook menu item on trusted notebooks
r15657 });
Jonathan Frederic
Fixed events
r17195 this.events.on('select.Cell', function (event, data) {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var index = that.find_cell_index(data.cell);
Matthias BUSSONNIER
Clean code, retab and minor fix...
r7170 that.select(index);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 });
Brian E. Granger
More work on the dual mode UX.
r14015
Jonathan Frederic
Fixed events
r17195 this.events.on('edit_mode.Cell', function (event, data) {
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 that.handle_edit_mode(data.cell);
Brian E. Granger
More work on the dual mode UX.
r14015 });
Brian E. Granger
Semi working version of basic dual mode UX....
r14016
Jonathan Frederic
Fixed events
r17195 this.events.on('command_mode.Cell', function (event, data) {
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 that.handle_command_mode(data.cell);
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 });
Thomas Kluyver
Use JS events for switching kernelspecs
r17380
this.events.on('spec_changed.Kernel', function(event, data) {
Thomas Kluyver
Move language info from kernelspec to kernel_info_reply
r18468 that.metadata.kernelspec =
Min RK
add resource URLs to kernelspec model...
r19681 {name: data.name, display_name: data.spec.display_name};
Min RK
cleanup kernelspec loading...
r19886 // start session if the current session isn't already correct
if (!(this.session && this.session.kernel && this.session.kernel.name === data.name)) {
that.start_session(data.name);
}
Thomas Kluyver
Move language info from kernelspec to kernel_info_reply
r18468 });
this.events.on('kernel_ready.Kernel', function(event, data) {
Min RK
update frontend with path/name changes...
r18752 var kinfo = data.kernel.info_reply;
Thomas Kluyver
Move language info from kernelspec to kernel_info_reply
r18468 var langinfo = kinfo.language_info || {};
that.metadata.language_info = langinfo;
Thomas Kluyver
Add pygments_lexer key to kernelspec
r18380 // Mode 'null' should be plain, unhighlighted text.
Min RK
fix loading of language name from kernel_info...
r19021 var cm_mode = langinfo.codemirror_mode || langinfo.name || 'null';
Thomas Kluyver
Add pygments_lexer key to kernelspec
r18380 that.set_codemirror_mode(cm_mode);
Thomas Kluyver
Use JS events for switching kernelspecs
r17380 });
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168
Brian E. Granger
More work on the dual mode UX.
r14015 var collapse_time = function (time) {
Bussonnier Matthias
main_app -> ipython-main-app
r9265 var app_height = $('#ipython-main-app').height(); // content height
Brian E. Granger
More accuract height calculations for the pager collapse/expand.
r4362 var splitter_height = $('div#pager_splitter').outerHeight(true);
var new_height = app_height - splitter_height;
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 that.element.animate({height : new_height + 'px'}, time);
Brian E. Granger
More work on the dual mode UX.
r14015 };
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723
Brian E. Granger
More work on the dual mode UX.
r14015 this.element.bind('collapse_pager', function (event, extrap) {
MinRK
holy crap, semicolons
r15236 var time = (extrap !== undefined) ? ((extrap.duration !== undefined ) ? extrap.duration : 'fast') : 'fast';
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 collapse_time(time);
Brian E. Granger
Pager is working again.
r4361 });
Brian E. Granger
More work on the dual mode UX.
r14015 var expand_time = function (time) {
Bussonnier Matthias
main_app -> ipython-main-app
r9265 var app_height = $('#ipython-main-app').height(); // content height
Brian E. Granger
More accuract height calculations for the pager collapse/expand.
r4362 var splitter_height = $('div#pager_splitter').outerHeight(true);
Brian E. Granger
Pager is working again.
r4361 var pager_height = $('div#pager').outerHeight(true);
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var new_height = app_height - pager_height - splitter_height;
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 that.element.animate({height : new_height + 'px'}, time);
Brian E. Granger
More work on the dual mode UX.
r14015 };
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723
this.element.bind('expand_pager', function (event, extrap) {
MinRK
holy crap, semicolons
r15236 var time = (extrap !== undefined) ? ((extrap.duration !== undefined ) ? extrap.duration : 'fast') : 'fast';
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 expand_time(time);
Brian E. Granger
Pager is working again.
r4361 });
MinRK
use `window.onbeforeunload=` for nav-away warning...
r11111
// Firefox 22 broke $(window).on("beforeunload")
// I'm not sure why or how.
window.onbeforeunload = function (e) {
Brian Granger
Implemented menu based UI using Wijmo.
r5857 // TODO: Make killing the kernel configurable.
var kill_kernel = false;
Brian E. Granger
Disabling auto-save at exit.
r4542 if (kill_kernel) {
Jessica B. Hamrick
Use session.delete rather than kernel.kill
r18219 that.session.delete();
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 }
MinRK
restore "unsaved changes" warning on unload...
r11047 // if we are autosaving, trigger an autosave on nav-away.
// still warn, because if we don't the autosave may fail.
MinRK
remove notebook read-only view...
r11644 if (that.dirty) {
MinRK
restore "unsaved changes" warning on unload...
r11047 if ( that.autosave_interval ) {
MinRK
add delay to autosave in beforeunload...
r11625 // schedule autosave in a timeout
// this gives you a chance to forcefully discard changes
// by reloading the page if you *really* want to.
// the timer doesn't start until you *dismiss* the dialog.
setTimeout(function () {
if (that.dirty) {
that.save_notebook();
}
}, 1000);
MinRK
update before unload message...
r11048 return "Autosave in progress, latest changes may be lost.";
} else {
return "Unsaved changes will be lost.";
MinRK
restore "unsaved changes" warning on unload...
r11047 }
MinRK
holy crap, semicolons
r15236 }
Fernando Perez
Fix bug where "don't leave" dialog was appearing when not needed in nb....
r5502 // Null is the *only* return value that will make the browser not
// pop up the "don't leave" dialog.
return null;
MinRK
use `window.onbeforeunload=` for nav-away warning...
r11111 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Min RK
Preserve nbformat_minor from the future...
r19107
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 /**
Jonathan Frederic
Some clean-up
r19509 * Trigger a warning dialog about missing functionality from newer minor versions
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 */
Min RK
Preserve nbformat_minor from the future...
r19107 Notebook.prototype.warn_nbformat_minor = function (event) {
var v = 'v' + this.nbformat + '.';
var orig_vs = v + this.nbformat_minor;
var this_vs = v + this.current_nbformat_minor;
var msg = "This notebook is version " + orig_vs + ", but we only fully support up to " +
this_vs + ". You can still work with this notebook, but cell and output types " +
"introduced in later notebook versions will not be available.";
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Newer Notebook",
body : msg,
buttons : {
OK : {
"class" : "btn-danger"
}
}
});
Jonathan Frederic
Write a plugin to handle private function automatically.
r19510 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
MinRK
setting the notebook dirty flag is now an event...
r10781 * Set the dirty flag, and trigger the set_dirty.Notebook event
*/
Notebook.prototype.set_dirty = function (value) {
if (value === undefined) {
value = true;
}
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (this.dirty === value) {
MinRK
setting the notebook dirty flag is now an event...
r10781 return;
}
Jonathan Frederic
Fixed events
r17195 this.events.trigger('set_dirty.Notebook', {value: value});
MinRK
setting the notebook dirty flag is now an event...
r10781 };
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Scroll the top of the page to a given cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - An index of the cell to view
* @param {integer} time - Animation time in milliseconds
* @return {integer} Pixel offset from the top of the container
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Jonathan Frederic
Clean up comments
r19511 Notebook.prototype.scroll_to_cell = function (index, time) {
Matthias BUSSONNIER
Add scroll_to_cell(cell_number) to the notebook
r8419 var cells = this.get_cells();
MinRK
holy crap, semicolons
r15236 time = time || 0;
Jonathan Frederic
Clean up comments
r19511 index = Math.min(cells.length-1,index);
index = Math.max(0 ,index);
var scroll_value = cells[index].element.position().top-cells[0].element.position().top ;
Min RK
fix scroll actions...
r19733 this.scroll_manager.element.animate({scrollTop:scroll_value}, time);
Matthias BUSSONNIER
Add scroll_to_cell(cell_number) to the notebook
r8419 return scroll_value;
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Scroll to the bottom of the page.
*/
Brian E. Granger
Improving the scrolling model.
r4364 Notebook.prototype.scroll_to_bottom = function () {
Min RK
fix scroll actions...
r19733 this.scroll_manager.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0);
Brian E. Granger
Improving the scrolling model.
r4364 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Scroll to the top of the page.
*/
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 Notebook.prototype.scroll_to_top = function () {
Min RK
fix scroll actions...
r19733 this.scroll_manager.element.animate({scrollTop:0}, 0);
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
MinRK
add Edit Notebook Metadata to Edit menu
r12913 // Edit Notebook metadata
Jonathan Frederic
Some clean-up
r19509 /**
* Display a dialog that allows the user to edit the Notebook's metadata.
*/
MinRK
add Edit Notebook Metadata to Edit menu
r12913 Notebook.prototype.edit_metadata = function () {
var that = this;
Jonathan Frederic
More review changes
r17214 dialog.edit_metadata({
md: this.metadata,
callback: function (md) {
that.metadata = md;
Thomas Kluyver
Move language info from kernelspec to kernel_info_reply
r18468 },
Jonathan Frederic
More review changes
r17214 name: 'Notebook',
notebook: this,
keyboard_manager: this.keyboard_manager});
MinRK
add Edit Notebook Metadata to Edit menu
r12913 };
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Cell indexing, retrieval, etc.
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get all cell elements in the notebook.
*
* @return {jQuery} A selector of all cell elements
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_cell_elements = function () {
Bussonnier Matthias
get cell correctly in nested context...
r19086 return this.container.find(".cell").not('.cell .cell');
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get a particular cell element.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index An index of a cell to select
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {jQuery} A selector of the given cell.
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_cell_element = function (index) {
var result = null;
var e = this.get_cell_elements().eq(index);
if (e.length !== 0) {
result = e;
}
return result;
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 * Try to get a particular cell by msg_id.
*
Jonathan Frederic
Some clean-up
r19509 * @param {string} msg_id A message UUID
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 * @return {Cell} Cell or null if no cell was found.
*/
Notebook.prototype.get_msg_cell = function (msg_id) {
Jonathan Frederic
Fix imports of "modules",...
r17202 return codecell.CodeCell.msg_cells[msg_id] || null;
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 };
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Count the cells in this notebook.
*
Jonathan Frederic
Clean up comments
r19511 * @return {integer} The number of cells in this notebook
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Notebook.prototype.ncells = function () {
Brian Granger
Refactoring of the notebooks cell management....
r5945 return this.get_cell_elements().length;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get all Cell objects in this notebook.
*
* @return {Array} This notebook's Cell objects
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_cells = function () {
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 // TODO: we are often calling cells as cells()[i], which we should optimize
// to cells(i) or a new method.
Brian Granger
Refactoring of the notebooks cell management....
r5945 return this.get_cell_elements().toArray().map(function (e) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return $(e).data("cell");
});
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Get a Cell objects from this notebook.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - An index of a cell to retrieve
Doug Blank
Update documentation for functions that can return null
r18029 * @return {Cell} Cell or null if no cell was found.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_cell = function (index) {
var result = null;
var ce = this.get_cell_element(index);
if (ce !== null) {
result = ce.data('cell');
}
return result;
MinRK
holy crap, semicolons
r15236 };
Brian Granger
Refactoring of the notebooks cell management....
r5945
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get the cell below a given cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {Cell} cell
Doug Blank
Update documentation for functions that can return null
r18029 * @return {Cell} the next cell or null if no cell was found.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_next_cell = function (cell) {
var result = null;
var index = this.find_cell_index(cell);
Matthias BUSSONNIER
factor valid cell index logic
r9549 if (this.is_valid_cell_index(index+1)) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 result = this.get_cell(index+1);
}
return result;
MinRK
holy crap, semicolons
r15236 };
Brian Granger
Refactoring of the notebooks cell management....
r5945
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get the cell above a given cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {Cell} cell
Doug Blank
Update documentation for functions that can return null
r18029 * @return {Cell} The previous cell or null if no cell was found.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_prev_cell = function (cell) {
var result = null;
var index = this.find_cell_index(cell);
Doug Blank
Fixed off by one error in get_prev_cell...
r18020 if (index !== null && index > 0) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 result = this.get_cell(index-1);
}
return result;
MinRK
holy crap, semicolons
r15236 };
David Wyde
Add YUIDoc in notebook.js.
r10033
/**
* Get the numeric index of a given cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {Cell} cell
* @return {integer} The cell's numeric index or null if no cell was found.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.find_cell_index = function (cell) {
var result = null;
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.get_cell_elements().filter(function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if ($(this).data("cell") === cell) {
result = index;
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
return result;
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Return given index if defined, or the selected index if not.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - A cell's index
* @return {integer} cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.index_or_selected = function (index) {
Brian Granger
Cell splitting and merging is done!
r5898 var i;
Brian Granger
Refactoring of the notebooks cell management....
r5945 if (index === undefined || index === null) {
i = this.get_selected_index();
Brian Granger
Cell splitting and merging is done!
r5898 if (i === null) {
i = 0;
}
} else {
i = index;
}
return i;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get the currently selected cell.
Jonathan Frederic
Clean up comments
r19511 *
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Cell} The selected cell
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_selected_cell = function () {
var index = this.get_selected_index();
return this.get_cell(index);
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Check whether a cell index is valid.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - A cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return True if the index is valid, false otherwise
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.is_valid_cell_index = function (index) {
if (index !== null && index >= 0 && index < this.ncells()) {
return true;
} else {
return false;
MinRK
holy crap, semicolons
r15236 }
};
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Get the index of the currently selected cell.
Jonathan Frederic
Clean up comments
r19511 *
* @return {integer} The selected cell's numeric index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_selected_index = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var result = null;
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.get_cell_elements().filter(function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if ($(this).data("cell").selected === true) {
result = index;
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
return result;
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian Granger
Refactoring of the notebooks cell management....
r5945 // Cell selection.
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Programmatically select a cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - A cell's index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Notebook} This notebook
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.select = function (index) {
Matthias BUSSONNIER
factor valid cell index logic
r9549 if (this.is_valid_cell_index(index)) {
MinRK
holy crap, semicolons
r15236 var sindex = this.get_selected_index();
Brian Granger
Lots of small notebook improvements....
r5946 if (sindex !== null && index !== sindex) {
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 // If we are about to select a different cell, make sure we are
// first in command mode.
if (this.mode !== 'command') {
this.command_mode();
}
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.get_cell(sindex).unselect();
MinRK
holy crap, semicolons
r15236 }
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var cell = this.get_cell(index);
Brian Granger
Further work on the toolbar UI....
r5994 cell.select();
Brian Granger
Heading/plaintext cells now wired up to toolbar UI.
r6028 if (cell.cell_type === 'heading') {
Jonathan Frederic
Fixed events
r17195 this.events.trigger('selected_cell_type_changed.Notebook',
Brian Granger
Major refactoring of saving, notification....
r6047 {'cell_type':cell.cell_type,level:cell.level}
);
Brian Granger
Heading/plaintext cells now wired up to toolbar UI.
r6028 } else {
Jonathan Frederic
Fixed events
r17195 this.events.trigger('selected_cell_type_changed.Notebook',
Brian Granger
Major refactoring of saving, notification....
r6047 {'cell_type':cell.cell_type}
);
MinRK
holy crap, semicolons
r15236 }
}
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 return this;
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Programmatically select the next cell.
*
* @return {Notebook} This notebook
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.select_next = function () {
var index = this.get_selected_index();
Matthias BUSSONNIER
factor valid cell index logic
r9549 this.select(index+1);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Programmatically select the previous cell.
*
* @return {Notebook} This notebook
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.select_prev = function () {
var index = this.get_selected_index();
Matthias BUSSONNIER
factor valid cell index logic
r9549 this.select(index-1);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
More work on the dual mode UX.
r14015 // Edit/Command mode
Jonathan Frederic
Standardized comments and removed last logs
r15500 /**
* Gets the index of the cell that is in edit mode.
*
Jonathan Frederic
Clean up comments
r19511 * @return {integer} index
*/
Jonathan Frederic
Standardized comments and removed last logs
r15500 Notebook.prototype.get_edit_index = function () {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 var result = null;
this.get_cell_elements().filter(function (index) {
if ($(this).data("cell").mode === 'edit') {
Jonathan Frederic
Standardized comments and removed last logs
r15500 result = index;
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 });
return result;
};
Jonathan Frederic
Standardized comments and removed last logs
r15500 /**
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 * Handle when a a cell blurs and the notebook should enter command mode.
Jonathan Frederic
Standardized comments and removed last logs
r15500 *
Jonathan Frederic
Clean up comments
r19511 * @param {Cell} [cell] - Cell to enter command mode on.
*/
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 Notebook.prototype.handle_command_mode = function (cell) {
Brian E. Granger
More work on the dual mode UX.
r14015 if (this.mode !== 'command') {
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 cell.command_mode();
Brian E. Granger
Lots of updates and changes....
r14021 this.mode = 'command';
Jonathan Frederic
Fixed events
r17195 this.events.trigger('command_mode.Notebook');
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 this.keyboard_manager.command_mode();
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
More work on the dual mode UX.
r14015 };
Jonathan Frederic
Standardized comments and removed last logs
r15500 /**
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 * Make the notebook enter command mode.
Jonathan Frederic
Clean up comments
r19511 */
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 Notebook.prototype.command_mode = function () {
var cell = this.get_cell(this.get_edit_index());
if (cell && this.mode !== 'command') {
// We don't call cell.command_mode, but rather call cell.focus_cell()
// which will blur and CM editor and trigger the call to
// handle_command_mode.
cell.focus_cell();
}
};
/**
Jonathan Frederic
implemented whiteboard logic
r15531 * Handle when a cell fires it's edit_mode event.
Jonathan Frederic
Standardized comments and removed last logs
r15500 *
Jonathan Frederic
Some clean-up
r19509 * @param {Cell} [cell] Cell to enter edit mode on.
Jonathan Frederic
Clean up comments
r19511 */
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 Notebook.prototype.handle_edit_mode = function (cell) {
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 if (cell && this.mode !== 'edit') {
Jonathan Frederic
Couple of whiteboard logic implementation misses
r15534 cell.edit_mode();
Brian E. Granger
Lots of updates and changes....
r14021 this.mode = 'edit';
Jonathan Frederic
Fixed events
r17195 this.events.trigger('edit_mode.Notebook');
Jonathan Frederic
Finished moving code into final(?) resting modules
r17194 this.keyboard_manager.edit_mode();
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
More work on the dual mode UX.
r14015 };
Jonathan Frederic
Standardized comments and removed last logs
r15500 /**
Jonathan Frederic
implemented whiteboard logic
r15531 * Make a cell enter edit mode.
Jonathan Frederic
Clean up comments
r19511 */
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 Notebook.prototype.edit_mode = function () {
var cell = this.get_selected_cell();
if (cell && this.mode !== 'edit') {
Jonathan Frederic
implemented whiteboard logic
r15531 cell.unrender();
cell.focus_editor();
}
};
/**
Jonathan Frederic
Standardized comments and removed last logs
r15500 * Focus the currently selected cell.
Jonathan Frederic
Clean up comments
r19511 */
Brian E. Granger
Don't always call focus_cell in Cell.command_mode....
r14073 Notebook.prototype.focus_cell = function () {
var cell = this.get_selected_cell();
if (cell === null) {return;} // No cell is selected
cell.focus_cell();
};
Brian E. Granger
More work on the dual mode UX.
r14015
Brian Granger
Refactoring of the notebooks cell management....
r5945 // Cell movement
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 /**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Move given (or selected) cell up and select it.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Notebook} This notebook
Jonathan Frederic
Clean up comments
r19511 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.move_cell_up = function (index) {
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i) && i > 0) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 var pivot = this.get_cell_element(i-1);
var tomove = this.get_cell_element(i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (pivot !== null && tomove !== null) {
tomove.detach();
pivot.before(tomove);
this.select(i-1);
Brian E. Granger
Moving a cell focuses it after the move....
r14025 var cell = this.get_selected_cell();
cell.focus_cell();
MinRK
holy crap, semicolons
r15236 }
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 /**
Jonathan Frederic
Clean up comments
r19511 * Move given (or selected) cell down and select it.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Notebook} This notebook
Jonathan Frederic
Clean up comments
r19511 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.move_cell_down = function (index) {
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 var i = this.index_or_selected(index);
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 if (this.is_valid_cell_index(i) && this.is_valid_cell_index(i+1)) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 var pivot = this.get_cell_element(i+1);
var tomove = this.get_cell_element(i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (pivot !== null && tomove !== null) {
tomove.detach();
pivot.after(tomove);
this.select(i+1);
Brian E. Granger
Moving a cell focuses it after the move....
r14025 var cell = this.get_selected_cell();
cell.focus_cell();
MinRK
holy crap, semicolons
r15236 }
}
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian Granger
Refactoring of the notebooks cell management....
r5945 // Insertion, deletion.
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Bussonnier Matthias
fix restore checkpoint add an empty cell
r19582 * Delete a cell from the notebook without any precautions
* Needed to reload checkpoints and other things like that.
*
* @param {integer} [index] - cell's numeric index
* @return {Notebook} This notebook
*/
Bussonnier Matthias
make method private
r19588 Notebook.prototype._unsafe_delete_cell = function (index) {
Bussonnier Matthias
fix restore checkpoint add an empty cell
r19582 var i = this.index_or_selected(index);
var cell = this.get_cell(i);
$('#undelete_cell').addClass('disabled');
if (this.is_valid_cell_index(i)) {
var old_ncells = this.ncells();
var ce = this.get_cell_element(i);
ce.remove();
this.set_dirty(true);
}
return this;
};
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Delete a cell from the notebook.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell's numeric index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Notebook} This notebook
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.delete_cell = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var i = this.index_or_selected(index);
Jessica B. Hamrick
Handle 'deletable' cell metadata
r17998 var cell = this.get_cell(i);
if (!cell.is_deletable()) {
return this;
}
David Warde-Farley
Add a simple 'undo' for cell deletion....
r8691 this.undelete_backup = cell.toJSON();
MinRK
use bootstrap `disabled` instead of `ui-state-disabled`...
r11118 $('#undelete_cell').removeClass('disabled');
Brian Granger
Refactoring of the notebooks cell management....
r5945 if (this.is_valid_cell_index(i)) {
Brian E. Granger
Fixing delete/undelete logic.
r14032 var old_ncells = this.ncells();
Brian Granger
Refactoring of the notebooks cell management....
r5945 var ce = this.get_cell_element(i);
ce.remove();
Brian E. Granger
Fixing delete/undelete logic.
r14032 if (i === 0) {
// Always make sure we have at least one cell.
if (old_ncells === 1) {
this.insert_cell_below('code');
}
this.select(0);
this.undelete_index = 0;
this.undelete_below = false;
} else if (i === old_ncells-1 && i !== 0) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.select(i-1);
David Warde-Farley
Add a simple 'undo' for cell deletion....
r8691 this.undelete_index = i - 1;
this.undelete_below = true;
Brian Granger
Refactoring of the notebooks cell management....
r5945 } else {
this.select(i);
David Warde-Farley
Add a simple 'undo' for cell deletion....
r8691 this.undelete_index = i;
this.undelete_below = false;
MinRK
holy crap, semicolons
r15236 }
Jonathan Frederic
Fixed events
r17195 this.events.trigger('delete.Cell', {'cell': cell, 'index': i});
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Refactoring of the notebooks cell management....
r5945 return this;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
Matthias BUSSONNIER
refactor cellc
r9550 /**
Brian E. Granger
Fixing delete/undelete logic.
r14032 * Restore the most recently deleted cell.
*/
Notebook.prototype.undelete_cell = function() {
if (this.undelete_backup !== null && this.undelete_index !== null) {
var current_index = this.get_selected_index();
if (this.undelete_index < current_index) {
current_index = current_index + 1;
}
if (this.undelete_index >= this.ncells()) {
this.select(this.ncells() - 1);
}
else {
this.select(this.undelete_index);
}
var cell_data = this.undelete_backup;
var new_cell = null;
if (this.undelete_below) {
new_cell = this.insert_cell_below(cell_data.cell_type);
} else {
new_cell = this.insert_cell_above(cell_data.cell_type);
}
new_cell.fromJSON(cell_data);
if (this.undelete_below) {
this.select(current_index+1);
} else {
this.select(current_index);
}
this.undelete_backup = null;
this.undelete_index = null;
}
$('#undelete_cell').addClass('disabled');
MinRK
holy crap, semicolons
r15236 };
Brian E. Granger
Fixing delete/undelete logic.
r14032
/**
Matthias BUSSONNIER
refactor cellc
r9550 * Insert a cell so that after insertion the cell is at given index.
*
Paul Ivanov
use current cell's type when inserting...
r16777 * If cell type is not provided, it will default to the type of the
* currently active cell.
*
Jonathan Frederic
Clean up comments
r19511 * Similar to insert_above, but index parameter is mandatory.
Matthias BUSSONNIER
refactor cellc
r9550 *
Jonathan Frederic
Clean up comments
r19511 * Index will be brought back into the accessible range [0,n].
Matthias BUSSONNIER
refactor cellc
r9550 *
Jonathan Frederic
Clean up comments
r19511 * @param {string} [type] - in ['code','markdown', 'raw'], defaults to 'code'
* @param {integer} [index] - a valid index where to insert cell
Jonathan Frederic
Some clean-up
r19509 * @return {Cell|null} created cell or null
Jonathan Frederic
Clean up comments
r19511 */
Matthias BUSSONNIER
remove opts not to conflict with brian...
r13576 Notebook.prototype.insert_cell_at_index = function(type, index){
Bussonnier Matthias
abstract, cleanup and document...
r9677 var ncells = this.ncells();
MinRK
make default cell type configurable...
r17785 index = Math.min(index, ncells);
index = Math.max(index, 0);
Brian Granger
A first go at RST cell support in the notebook.
r6017 var cell = null;
Thomas Kluyver
Remove user_config js module
r19529 type = type || this.class_config.get_sync('default_cell_type');
MinRK
make default cell type configurable...
r17785 if (type === 'above') {
if (index > 0) {
type = this.get_cell(index-1).cell_type;
} else {
type = 'code';
}
} else if (type === 'below') {
if (index < ncells) {
type = this.get_cell(index).cell_type;
} else {
type = 'code';
}
} else if (type === 'selected') {
type = this.get_selected_cell().cell_type;
}
Matthias BUSSONNIER
refactor cellc
r9550
Matthias BUSSONNIER
fix one more == to ===
r9789 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
jon
In person review with @ellisonbg
r17210 var cell_options = {
events: this.events,
config: this.config,
keyboard_manager: this.keyboard_manager,
Jonathan Frederic
More requirejs fixes
r17215 notebook: this,
Bussonnier Matthias
some extra comma/semicolon cleanup
r18993 tooltip: this.tooltip
jon
In person review with @ellisonbg
r17210 };
MinRK
remove heading cells in v4
r18596 switch(type) {
case 'code':
jon
In person review with @ellisonbg
r17210 cell = new codecell.CodeCell(this.kernel, cell_options);
Brian Granger
Refactoring of the notebooks cell management....
r5945 cell.set_input_prompt();
MinRK
remove heading cells in v4
r18596 break;
case 'markdown':
jon
Added some nice comments,...
r17211 cell = new textcell.MarkdownCell(cell_options);
MinRK
remove heading cells in v4
r18596 break;
case 'raw':
jon
Added some nice comments,...
r17211 cell = new textcell.RawCell(cell_options);
MinRK
remove heading cells in v4
r18596 break;
default:
Min RK
Handle unrecognized outputs and cells from the future
r18999 console.log("Unrecognized cell type: ", type, cellmod);
cell = new cellmod.UnrecognizedCell(cell_options);
Bussonnier Matthias
abstract, cleanup and document...
r9677 }
Brian E. Granger
More work on the dual mode UX.
r14015 if(this._insert_element_at_index(cell.element,index)) {
Brian Granger
Lots of small notebook improvements....
r5946 cell.render();
Jonathan Frederic
Fixed events
r17195 this.events.trigger('create.Cell', {'cell': cell, 'index': index});
Brian E. Granger
More work on the dual mode UX.
r14015 cell.refresh();
Brian E. Granger
Fixing select when inserting cell using menu.
r14029 // We used to select the cell after we refresh it, but there
// are now cases were this method is called where select is
// not appropriate. The selection logic should be handled by the
// caller of the the top level insert_cell methods.
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
Bussonnier Matthias
abstract, cleanup and document...
r9677 }
}
Brian Granger
A first go at RST cell support in the notebook.
r6017 return cell;
Matthias BUSSONNIER
refactor cellc
r9550
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Starting work on a Markdown cell.
r4507
Bussonnier Matthias
abstract, cleanup and document...
r9677 /**
* Insert an element at given cell index.
*
Jonathan Frederic
Some clean-up
r19509 * @param {HTMLElement} element - a cell element
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - a valid index where to inser cell
* @returns {boolean} success
*/
Bussonnier Matthias
abstract, cleanup and document...
r9677 Notebook.prototype._insert_element_at_index = function(element, index){
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 if (element === undefined){
Matthias BUSSONNIER
simplify logic
r9688 return false;
}
Bussonnier Matthias
abstract, cleanup and document...
r9677 var ncells = this.ncells();
Matthias BUSSONNIER
simplify logic
r9688 if (ncells === 0) {
// special case append if empty
this.element.find('div.end_space').before(element);
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 } else if ( ncells === index ) {
Matthias BUSSONNIER
simplify logic
r9688 // special case append it the end, but not empty
this.get_cell_element(index-1).after(element);
} else if (this.is_valid_cell_index(index)) {
// otherwise always somewhere to append to
this.get_cell_element(index).before(element);
} else {
return false;
}
Brian E. Granger
Starting work on a Markdown cell.
r4507
David Warde-Farley
Make undelete respect order after insertions/deletions.
r8694 if (this.undelete_index !== null && index <= this.undelete_index) {
this.undelete_index = this.undelete_index + 1;
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
David Warde-Farley
Make undelete respect order after insertions/deletions.
r8694 }
Matthias BUSSONNIER
simplify logic
r9688 return true;
Matthias BUSSONNIER
refactor cellc
r9550 };
/**
* Insert a cell of given type above given index, or at top
* of notebook if index smaller than 0.
*
Jonathan Frederic
Clean up comments
r19511 * @param {string} [type] - cell type
* @param {integer} [index] - defaults to the currently selected cell
Jonathan Frederic
Some clean-up
r19509 * @return {Cell|null} handle to created cell or null
Jonathan Frederic
Clean up comments
r19511 */
Matthias BUSSONNIER
refactor cellc
r9550 Notebook.prototype.insert_cell_above = function (type, index) {
index = this.index_or_selected(index);
return this.insert_cell_at_index(type, index);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Starting work on a Markdown cell.
r4507
Bussonnier Matthias
abstract, cleanup and document...
r9677 /**
* Insert a cell of given type below given index, or at bottom
Paul Ivanov
use current cell's type when inserting...
r16777 * of notebook if index greater than number of cells
Bussonnier Matthias
abstract, cleanup and document...
r9677 *
Jonathan Frederic
Clean up comments
r19511 * @param {string} [type] - cell type
* @param {integer} [index] - defaults to the currently selected cell
Jonathan Frederic
Some clean-up
r19509 * @return {Cell|null} handle to created cell or null
Jonathan Frederic
Clean up comments
r19511 */
Matthias BUSSONNIER
remove opts not to conflict with brian...
r13576 Notebook.prototype.insert_cell_below = function (type, index) {
Bussonnier Matthias
abstract, cleanup and document...
r9677 index = this.index_or_selected(index);
Matthias BUSSONNIER
remove opts not to conflict with brian...
r13576 return this.insert_cell_at_index(type, index+1);
Bussonnier Matthias
abstract, cleanup and document...
r9677 };
/**
* Insert cell at end of notebook
*
Jonathan Frederic
Clean up comments
r19511 * @param {string} type - cell type
* @return {Cell|null} handle to created cell or null
*/
Matthias BUSSONNIER
remove opts not to conflict with brian...
r13576 Notebook.prototype.insert_cell_at_bottom = function (type){
Bussonnier Matthias
abstract, cleanup and document...
r9677 var len = this.ncells();
Matthias BUSSONNIER
remove opts not to conflict with brian...
r13576 return this.insert_cell_below(type,len-1);
Bussonnier Matthias
abstract, cleanup and document...
r9677 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Turn a cell into a code cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Starting work on a Markdown cell.
r4507 Notebook.prototype.to_code = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var i = this.index_or_selected(index);
Brian Granger
Refactoring of the notebooks cell management....
r5945 if (this.is_valid_cell_index(i)) {
Pierre Gerold
Typo and presentation
r17844 var source_cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (!(source_cell instanceof codecell.CodeCell)) {
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var target_cell = this.insert_cell_below('code',i);
Brian Granger
Refactoring of the notebooks cell management....
r5945 var text = source_cell.get_text();
if (text === source_cell.placeholder) {
text = '';
}
Pierre Gerold
Typo and presentation
r17844 //metadata
target_cell.metadata = source_cell.metadata;
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843
Brian Granger
Refactoring of the notebooks cell management....
r5945 target_cell.set_text(text);
Paul Ivanov
fix for #1678, undo no longer clears cells...
r7587 // make this value the starting point, so that we can only undo
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843 source_cell.element.remove();
Brian E. Granger
Binding to notebook div not document.
r14018 this.select(i);
Jonathan Frederic
Remember cursor position on cell type change
r16818 var cursor = source_cell.code_mirror.getCursor();
target_cell.code_mirror.setCursor(cursor);
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 }
}
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Turn a cell into a Markdown cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 Notebook.prototype.to_markdown = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var i = this.index_or_selected(index);
Brian Granger
Refactoring of the notebooks cell management....
r5945 if (this.is_valid_cell_index(i)) {
Pierre Gerold
Typo and presentation
r17844 var source_cell = this.get_cell(i);
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843
jon
Added some nice comments,...
r17211 if (!(source_cell instanceof textcell.MarkdownCell)) {
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var target_cell = this.insert_cell_below('markdown',i);
Brian Granger
Refactoring of the notebooks cell management....
r5945 var text = source_cell.get_text();
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843
Brian Granger
Refactoring of the notebooks cell management....
r5945 if (text === source_cell.placeholder) {
Brian Granger
Lots of small notebook improvements....
r5946 text = '';
MinRK
holy crap, semicolons
r15236 }
Pierre Gerold
Typo and presentation
r17844 // metadata
Min RK
update frontend with path/name changes...
r18752 target_cell.metadata = source_cell.metadata;
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 // We must show the editor before setting its contents
Brian E. Granger
Adding new logic to cells.
r14014 target_cell.unrender();
Brian Granger
A first go at RST cell support in the notebook.
r6017 target_cell.set_text(text);
Paul Ivanov
fix for #1678, undo no longer clears cells...
r7587 // make this value the starting point, so that we can only undo
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843 source_cell.element.remove();
Brian E. Granger
More work on the dual mode UX.
r14015 this.select(i);
jon
Added some nice comments,...
r17211 if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) {
Brian E. Granger
Don't enter edit mode when changing cell type and preserve renderd.
r14943 target_cell.render();
}
Jonathan Frederic
Remember cursor position on cell type change
r16818 var cursor = source_cell.code_mirror.getCursor();
target_cell.code_mirror.setCursor(cursor);
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 }
}
Brian E. Granger
Starting work on a Markdown cell.
r4507 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Turn a cell into a raw text cell.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
rename plaintext cell -> raw cell
r6248 Notebook.prototype.to_raw = function (index) {
Brian Granger
A first go at RST cell support in the notebook.
r6017 var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i)) {
var target_cell = null;
Pierre Gerold
Typo and presentation
r17844 var source_cell = this.get_cell(i);
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843
jon
Added some nice comments,...
r17211 if (!(source_cell instanceof textcell.RawCell)) {
MinRK
rename plaintext cell -> raw cell
r6248 target_cell = this.insert_cell_below('raw',i);
Brian Granger
A first go at RST cell support in the notebook.
r6017 var text = source_cell.get_text();
if (text === source_cell.placeholder) {
text = '';
MinRK
holy crap, semicolons
r15236 }
Pierre Gerold
Typo and presentation
r17844 //metadata
target_cell.metadata = source_cell.metadata;
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 // We must show the editor before setting its contents
Brian E. Granger
Adding new logic to cells.
r14014 target_cell.unrender();
Brian Granger
A first go at RST cell support in the notebook.
r6017 target_cell.set_text(text);
Paul Ivanov
fix for #1678, undo no longer clears cells...
r7587 // make this value the starting point, so that we can only undo
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
Pierre Gerold
Modify cells converter funcs to keep metadata through
r17843 source_cell.element.remove();
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 this.select(i);
Jonathan Frederic
Remember cursor position on cell type change
r16818 var cursor = source_cell.code_mirror.getCursor();
target_cell.code_mirror.setCursor(cursor);
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 }
}
Brian Granger
A first go at RST cell support in the notebook.
r6017 };
Min RK
deprecate heading cells in UI...
r18680
Jonathan Frederic
Some clean-up
r19509 /**
Jonathan Frederic
Clean up comments
r19511 * Warn about heading cell support removal.
Jonathan Frederic
Some clean-up
r19509 */
Min RK
deprecate heading cells in UI...
r18680 Notebook.prototype._warn_heading = function () {
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title : "Use markdown headings",
body : $("<p/>").text(
'IPython no longer uses special heading cells. ' +
'Instead, write your headings in Markdown cells using # characters:'
).append($('<pre/>').text(
'## This is a level 2 heading'
)),
buttons : {
Bussonnier Matthias
some extra comma/semicolon cleanup
r18993 "OK" : {}
Min RK
deprecate heading cells in UI...
r18680 }
});
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Turn a cell into a heading containing markdown cell.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} [index] - cell index
* @param {integer} [level] - heading level (e.g., 1 for h1)
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Jonathan Frederic
Some clean-up
r19509 Notebook.prototype.to_heading = function (index, level) {
Min RK
deprecate heading cells in UI...
r18680 this.to_markdown(index);
Brian Granger
Finishing first draft of RST and heading cells.
r6019 level = level || 1;
var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i)) {
Min RK
deprecate heading cells in UI...
r18680 var cell = this.get_cell(i);
cell.set_heading_level(level);
Brian E. Granger
Changing a heading cell level should enter edit mode and set dirty
r14031 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Finishing first draft of RST and heading cells.
r6019 };
Brian Granger
Refactoring of the notebooks cell management....
r5945 // Cut/Copy/Paste
Brian Granger
Added cell level cut/copy/paste.
r5879
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Enable the UI elements for pasting cells.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Added cell level cut/copy/paste.
r5879 Notebook.prototype.enable_paste = function () {
var that = this;
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 if (!this.paste_enabled) {
MinRK
use bootstrap `disabled` instead of `ui-state-disabled`...
r11118 $('#paste_cell_replace').removeClass('disabled')
David Warde-Farley
Make 'Paste Above' the default paste behavior....
r8715 .on('click', function () {that.paste_cell_replace();});
MinRK
use bootstrap `disabled` instead of `ui-state-disabled`...
r11118 $('#paste_cell_above').removeClass('disabled')
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 .on('click', function () {that.paste_cell_above();});
MinRK
use bootstrap `disabled` instead of `ui-state-disabled`...
r11118 $('#paste_cell_below').removeClass('disabled')
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 .on('click', function () {that.paste_cell_below();});
this.paste_enabled = true;
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Added cell level cut/copy/paste.
r5879 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Disable the UI elements for pasting cells.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Added cell level cut/copy/paste.
r5879 Notebook.prototype.disable_paste = function () {
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 if (this.paste_enabled) {
MinRK
use bootstrap `disabled` instead of `ui-state-disabled`...
r11118 $('#paste_cell_replace').addClass('disabled').off('click');
$('#paste_cell_above').addClass('disabled').off('click');
$('#paste_cell_below').addClass('disabled').off('click');
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 this.paste_enabled = false;
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Added cell level cut/copy/paste.
r5879 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Cut a cell.
*/
Brian Granger
Added cell level cut/copy/paste.
r5879 Notebook.prototype.cut_cell = function () {
this.copy_cell();
this.delete_cell();
MinRK
holy crap, semicolons
r15236 };
Brian Granger
Added cell level cut/copy/paste.
r5879
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Copy a cell.
*/
Brian Granger
Added cell level cut/copy/paste.
r5879 Notebook.prototype.copy_cell = function () {
Brian Granger
Refactoring of the notebooks cell management....
r5945 var cell = this.get_selected_cell();
Brian Granger
Added cell level cut/copy/paste.
r5879 this.clipboard = cell.toJSON();
Jessica B. Hamrick
Handle 'deletable' cell metadata
r17998 // remove undeletable status from the copied cell
if (this.clipboard.metadata.deletable !== undefined) {
delete this.clipboard.metadata.deletable;
}
Brian Granger
Added cell level cut/copy/paste.
r5879 this.enable_paste();
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Replace the selected cell with the cell in the clipboard.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
David Warde-Farley
Make 'Paste Above' the default paste behavior....
r8715 Notebook.prototype.paste_cell_replace = function () {
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 if (this.clipboard !== null && this.paste_enabled) {
Brian Granger
Added cell level cut/copy/paste.
r5879 var cell_data = this.clipboard;
Brian Granger
Refactoring of the notebooks cell management....
r5945 var new_cell = this.insert_cell_above(cell_data.cell_type);
Brian Granger
Updating cell logic....
r5944 new_cell.fromJSON(cell_data);
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var old_cell = this.get_next_cell(new_cell);
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.delete_cell(this.find_cell_index(old_cell));
this.select(this.find_cell_index(new_cell));
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Added cell level cut/copy/paste.
r5879 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Paste a cell from the clipboard above the selected cell.
*/
Brian Granger
Added cell level cut/copy/paste.
r5879 Notebook.prototype.paste_cell_above = function () {
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 if (this.clipboard !== null && this.paste_enabled) {
Brian Granger
Added cell level cut/copy/paste.
r5879 var cell_data = this.clipboard;
Brian Granger
Refactoring of the notebooks cell management....
r5945 var new_cell = this.insert_cell_above(cell_data.cell_type);
Brian Granger
Updating cell logic....
r5944 new_cell.fromJSON(cell_data);
Paul Ivanov
make paste focuses the pasted cell...
r14972 new_cell.focus_cell();
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Added cell level cut/copy/paste.
r5879 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Paste a cell from the clipboard below the selected cell.
*/
Brian Granger
Added cell level cut/copy/paste.
r5879 Notebook.prototype.paste_cell_below = function () {
Brian Granger
Minor, but important fixes to cut/copy/paste....
r5912 if (this.clipboard !== null && this.paste_enabled) {
Brian Granger
Added cell level cut/copy/paste.
r5879 var cell_data = this.clipboard;
Brian Granger
Refactoring of the notebooks cell management....
r5945 var new_cell = this.insert_cell_below(cell_data.cell_type);
Brian Granger
Updating cell logic....
r5944 new_cell.fromJSON(cell_data);
Paul Ivanov
make paste focuses the pasted cell...
r14972 new_cell.focus_cell();
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Added cell level cut/copy/paste.
r5879 };
Brian Granger
Refactoring of the notebooks cell management....
r5945 // Split/merge
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Split the selected cell into two cells.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
More of the initial split cell capability.
r5897 Notebook.prototype.split_cell = function () {
Brian Granger
Refactoring of the notebooks cell management....
r5945 var cell = this.get_selected_cell();
Brian Granger
Lots of small notebook improvements....
r5946 if (cell.is_splittable()) {
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var texta = cell.get_pre_cursor();
var textb = cell.get_post_cursor();
Paul Ivanov
allow splitting and merging of heading cells...
r17417 cell.set_text(textb);
var new_cell = this.insert_cell_above(cell.cell_type);
// Unrender the new cell so we can call set_text.
new_cell.unrender();
new_cell.set_text(texta);
MinRK
holy crap, semicolons
r15236 }
Brian Granger
More of the initial split cell capability.
r5897 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Merge the selected cell into the cell above it.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Cell splitting and merging is done!
r5898 Notebook.prototype.merge_cell_above = function () {
Brian Granger
Refactoring of the notebooks cell management....
r5945 var index = this.get_selected_index();
Brian Granger
Lots of small notebook improvements....
r5946 var cell = this.get_cell(index);
Brian E. Granger
Carefully manage rendered state in merge cell.
r14028 var render = cell.rendered;
MinRK
add Cell.is_mergeable method...
r12509 if (!cell.is_mergeable()) {
return;
}
Brian Granger
Cell splitting and merging is done!
r5898 if (index > 0) {
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var upper_cell = this.get_cell(index-1);
MinRK
add Cell.is_mergeable method...
r12509 if (!upper_cell.is_mergeable()) {
return;
}
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var upper_text = upper_cell.get_text();
var text = cell.get_text();
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian Granger
Lots of small notebook improvements....
r5946 cell.set_text(upper_text+'\n'+text);
Paul Ivanov
allow splitting and merging of heading cells...
r17417 } else {
Brian E. Granger
Carefully manage rendered state in merge cell.
r14028 cell.unrender(); // Must unrender before we set_text.
Brian E. Granger
Split cell keyboard shortcut wired up. Merge markdown adds 2nd \n.
r14026 cell.set_text(upper_text+'\n\n'+text);
Brian E. Granger
Carefully manage rendered state in merge cell.
r14028 if (render) {
// The rendered state of the final cell should match
// that of the original selected cell;
cell.render();
}
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Lots of small notebook improvements....
r5946 this.delete_cell(index-1);
this.select(this.find_cell_index(cell));
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Cell splitting and merging is done!
r5898 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Merge the selected cell into the cell below it.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Cell splitting and merging is done!
r5898 Notebook.prototype.merge_cell_below = function () {
Brian Granger
Refactoring of the notebooks cell management....
r5945 var index = this.get_selected_index();
Brian Granger
Lots of small notebook improvements....
r5946 var cell = this.get_cell(index);
Brian E. Granger
Carefully manage rendered state in merge cell.
r14028 var render = cell.rendered;
MinRK
add Cell.is_mergeable method...
r12509 if (!cell.is_mergeable()) {
return;
}
Brian Granger
Cell splitting and merging is done!
r5898 if (index < this.ncells()-1) {
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var lower_cell = this.get_cell(index+1);
MinRK
add Cell.is_mergeable method...
r12509 if (!lower_cell.is_mergeable()) {
return;
}
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var lower_text = lower_cell.get_text();
var text = cell.get_text();
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian Granger
Lots of small notebook improvements....
r5946 cell.set_text(text+'\n'+lower_text);
Paul Ivanov
allow splitting and merging of heading cells...
r17417 } else {
Brian E. Granger
Carefully manage rendered state in merge cell.
r14028 cell.unrender(); // Must unrender before we set_text.
Brian E. Granger
Split cell keyboard shortcut wired up. Merge markdown adds 2nd \n.
r14026 cell.set_text(text+'\n\n'+lower_text);
Brian E. Granger
Carefully manage rendered state in merge cell.
r14028 if (render) {
// The rendered state of the final cell should match
// that of the original selected cell;
cell.render();
}
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Lots of small notebook improvements....
r5946 this.delete_cell(index+1);
this.select(this.find_cell_index(cell));
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Cell splitting and merging is done!
r5898 };
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Brian E. Granger
Clear all output is implemented.
r4543 // Cell collapsing and output clearing
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Hide a cell's output.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.collapse_output = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var i = this.index_or_selected(index);
Brian E. Granger
Cleaning up output management in code and menus.
r14867 var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell !== null && (cell instanceof codecell.CodeCell)) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 cell.collapse_output();
this.set_dirty(true);
}
};
/**
* Hide each code cell's output area.
*/
Notebook.prototype.collapse_all_output = function () {
Matthias Bussonnier
Use native map when possible...
r18410 this.get_cells().map(function (cell, i) {
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 cell.collapse_output();
Brian E. Granger
Cleaning up output management in code and menus.
r14867 }
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 });
Brian E. Granger
Cleaning up output management in code and menus.
r14867 // this should not be set if the `collapse` key is removed from nbformat
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
Brian Granger
Initial reply handling implemented along with css fixes.
r4299 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Show a cell's output.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.expand_output = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var i = this.index_or_selected(index);
Brian E. Granger
Cleaning up output management in code and menus.
r14867 var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell !== null && (cell instanceof codecell.CodeCell)) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 cell.expand_output();
this.set_dirty(true);
}
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Cleaning up output management in code and menus.
r14867 /**
* Expand each code cell's output area, and remove scrollbars.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.expand_all_output = function () {
Matthias Bussonnier
Use native map when possible...
r18410 this.get_cells().map(function (cell, i) {
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 cell.expand_output();
Brian E. Granger
Cleaning up output management in code and menus.
r14867 }
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 });
Brian E. Granger
Cleaning up output management in code and menus.
r14867 // this should not be set if the `collapse` key is removed from nbformat
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
Brian E. Granger
Cell collapse/expand is not called "Toggle".
r4639 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * Clear the selected CodeCell's output area.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.clear_output = function (index) {
MinRK
add ^M-O for toggling output scroll
r7429 var i = this.index_or_selected(index);
Brian E. Granger
Cleaning up output management in code and menus.
r14867 var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell !== null && (cell instanceof codecell.CodeCell)) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 cell.clear_output();
this.set_dirty(true);
}
MinRK
add ^M-O for toggling output scroll
r7429 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * Clear each code cell's output area.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.clear_all_output = function () {
Matthias Bussonnier
Use native map when possible...
r18410 this.get_cells().map(function (cell, i) {
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 cell.clear_output();
MinRK
third attempt at scrolled long output...
r7362 }
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 });
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
third attempt at scrolled long output...
r7362 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * Scroll the selected CodeCell's output area.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - cell index
Brian E. Granger
Cleaning up output management in code and menus.
r14867 */
Notebook.prototype.scroll_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell !== null && (cell instanceof codecell.CodeCell)) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 cell.scroll_output();
this.set_dirty(true);
}
};
/**
Jonathan Frederic
Clean up comments
r19511 * Expand each code cell's output area and add a scrollbar for long output.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
third attempt at scrolled long output...
r7362 Notebook.prototype.scroll_all_output = function () {
Matthias Bussonnier
Use native map when possible...
r18410 this.get_cells().map(function (cell, i) {
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 cell.scroll_output();
MinRK
third attempt at scrolled long output...
r7362 }
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 });
MinRK
third attempt at scrolled long output...
r7362 // this should not be set if the `collapse` key is removed from nbformat
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
MinRK
third attempt at scrolled long output...
r7362 };
Jonathan Frederic
Clean up comments
r19511 /**
* Toggle whether a cell's output is collapsed or expanded.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.toggle_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell !== null && (cell instanceof codecell.CodeCell)) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 cell.toggle_output();
this.set_dirty(true);
}
MinRK
third attempt at scrolled long output...
r7362 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Toggle the output of all cells.
Brian E. Granger
Simplified Cell menu items related to output.
r14871 */
Notebook.prototype.toggle_all_output = function () {
Matthias Bussonnier
Use native map when possible...
r18410 this.get_cells().map(function (cell, i) {
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian E. Granger
Simplified Cell menu items related to output.
r14871 cell.toggle_output();
}
});
// this should not be set if the `collapse` key is removed from nbformat
this.set_dirty(true);
};
/**
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * Toggle a scrollbar for long cell outputs.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Jonathan Frederic
Clean up comments
r19511 * @param {integer} index - cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Cleaning up output management in code and menus.
r14867 Notebook.prototype.toggle_output_scroll = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell !== null && (cell instanceof codecell.CodeCell)) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 cell.toggle_output_scroll();
this.set_dirty(true);
}
Brian E. Granger
Clear all output is implemented.
r4543 };
Brian E. Granger
Simplified Cell menu items related to output.
r14871 /**
* Toggle the scrolling of long output on all cells.
*/
Notebook.prototype.toggle_all_output_scroll = function () {
Matthias Bussonnier
Use native map when possible...
r18410 this.get_cells().map(function (cell, i) {
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
Brian E. Granger
Simplified Cell menu items related to output.
r14871 cell.toggle_output_scroll();
}
});
// this should not be set if the `collapse` key is removed from nbformat
this.set_dirty(true);
};
Brian Granger
Fixing auto-indent issues in CodeMirror config....
r5959
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 // Other cell functions: line numbers, ...
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Toggle line numbers in the selected cell's input area.
*/
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 Notebook.prototype.cell_toggle_line_numbers = function() {
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.get_selected_cell().toggle_line_numbers();
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 };
Thomas Kluyver
Add method to change codemirror mode of all code cells
r17376
/**
* Set the codemirror mode for all code cells, including the default for
* new code cells.
*/
Notebook.prototype.set_codemirror_mode = function(newmode){
if (newmode === this.codemirror_mode) {
return;
}
this.codemirror_mode = newmode;
Thomas Kluyver
Fix JS iteration...
r17383 codecell.CodeCell.options_default.cm_config.mode = newmode;
MinRK
remove heading cells in v4
r18596
Min RK
update frontend with path/name changes...
r18752 var that = this;
Nicholas Bollweg (Nick)
more fidgeting before starting over
r19290 utils.requireCodeMirrorMode(newmode, function (spec) {
Matthias Bussonnier
Use native map when possible...
r18410 that.get_cells().map(function(cell, i) {
Thomas Kluyver
Fix JS iteration...
r17383 if (cell.cell_type === 'code'){
Nicholas Bollweg (Nick)
more fidgeting before starting over
r19290 cell.code_mirror.setOption('mode', spec);
Thomas Kluyver
Add method to change codemirror mode of all code cells
r17376 // This is currently redundant, because cm_config ends up as
// codemirror's own .options object, but I don't want to
// rely on that.
Nicholas Bollweg (Nick)
more fidgeting before starting over
r19290 cell.cm_config.mode = spec;
Thomas Kluyver
Add method to change codemirror mode of all code cells
r17376 }
Thomas Kluyver
Fix JS iteration...
r17383 });
MinRK
remove heading cells in v4
r18596 });
Thomas Kluyver
Add method to change codemirror mode of all code cells
r17376 };
Brian E. Granger
Clear all output is implemented.
r4543
Zachary Sailer
manual rebase static/notebook/js files
r12986 // Session related things
Brian Granger
Basic notebook saving and loading....
r4315
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Zachary Sailer
manual rebase static/notebook/js files
r12986 * Start a new session and set it on each code cell.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Thomas Kluyver
Allow switching kernel from the notebook UI
r17370 Notebook.prototype.start_session = function (kernel_name) {
MinRK
avoid race condition when deleting/starting sessions...
r17649 if (this._session_starting) {
throw new session.SessionAlreadyStarting();
}
this._session_starting = true;
Jessica B. Hamrick
Use Session.restart in Notebook.start_session
r18222
var options = {
Jonathan Frederic
Some JS test fixes
r17212 base_url: this.base_url,
MinRK
pass ws_url to kernel constructor...
r17308 ws_url: this.ws_url,
Jonathan Frederic
Some JS test fixes
r17212 notebook_path: this.notebook_path,
notebook_name: this.notebook_name,
Thomas Kluyver
Allow switching kernel from the notebook UI
r17370 kernel_name: kernel_name,
Jessica B. Hamrick
Use Session.restart in Notebook.start_session
r18222 notebook: this
};
var success = $.proxy(this._session_started, this);
var failure = $.proxy(this._session_start_failed, this);
Thomas Kluyver
Update JS for kernels and sessions APIs
r17223
Jessica B. Hamrick
Use Session.restart in Notebook.start_session
r18222 if (this.session !== null) {
this.session.restart(options, success, failure);
} else {
this.session = new session.Session(options);
this.session.start(success, failure);
}
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 };
Zachary Sailer
Fixed bug when linking kernel to new code cells
r12999
/**
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 * Once a session is started, link the code cells to the kernel and pass the
Jonathan Frederic
Clean up comments
r19511 * comm manager to the widget manager.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
avoid race condition when deleting/starting sessions...
r17649 Notebook.prototype._session_started = function (){
this._session_starting = false;
MinRK
Cells shouldn't know about Sessions
r13133 this.kernel = this.session.kernel;
Brian Granger
Fixed order of notebook loading and kernel starting....
r7197 var ncells = this.ncells();
for (var i=0; i<ncells; i++) {
var cell = this.get_cell(i);
Jonathan Frederic
Fix all the bugs!
r17203 if (cell instanceof codecell.CodeCell) {
MinRK
Cells shouldn't know about Sessions
r13133 cell.set_kernel(this.session.kernel);
MinRK
holy crap, semicolons
r15236 }
}
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 };
Jonathan Frederic
Clean up comments
r19511
Jonathan Frederic
Start JSDoc integration
r19503 /**
Jonathan Frederic
Clean up comments
r19511 * Called when the session fails to start.
Jonathan Frederic
Start JSDoc integration
r19503 */
Jonathan Frederic
Clean up comments
r19511 Notebook.prototype._session_start_failed = function(jqxhr, status, error){
MinRK
avoid race condition when deleting/starting sessions...
r17649 this._session_starting = false;
utils.log_ajax_error(jqxhr, status, error);
};
Jonathan Frederic
Added heading and slideshow scroll managers
r17870
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Prompt the user to restart the IPython kernel.
*/
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Notebook.prototype.restart_kernel = function () {
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 var that = this;
Jonathan Frederic
Fix imports of "modules",...
r17202 dialog.modal({
Jonathan Frederic
Some JS test fixes
r17212 notebook: this,
keyboard_manager: this.keyboard_manager,
MinRK
bootstrap dialogs
r10895 title : "Restart kernel or continue running?",
Matthias BUSSONNIER
some $.html( -> $.text(...
r14634 body : $("<p/>").text(
MinRK
bootstrap dialogs
r10895 'Do you want to restart the current kernel? You will lose all variables defined in it.'
),
Fernando Perez
Add confirmation dialog to kernel restart action.
r5021 buttons : {
MinRK
bootstrap dialogs
r10895 "Continue running" : {},
"Restart" : {
"class" : "btn-danger",
"click" : function() {
Jessica B. Hamrick
Fix reference to session in notebook.js
r18199 that.kernel.restart();
MinRK
bootstrap dialogs
r10895 }
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 }
}
});
};
Zachary Sailer
fix restart/interrupt kernel buttons
r12994
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Brian E. Granger
Renaming execute methods.
r14085 * Execute or render cell outputs and go into command mode.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Renaming execute methods.
r14085 Notebook.prototype.execute_cell = function () {
Jonathan Frederic
Start JSDoc integration
r19503 // mode = shift, ctrl, alt
Brian E. Granger
Renaming execute methods.
r14085 var cell = this.get_selected_cell();
cell.execute();
Jonathan Frederic
Fixed lots of bugs...
r15493 this.command_mode();
Brian E. Granger
Renaming execute methods.
r14085 this.set_dirty(true);
MinRK
holy crap, semicolons
r15236 };
Brian E. Granger
Renaming execute methods.
r14085
/**
* Execute or render cell outputs and insert a new cell below.
*/
Notebook.prototype.execute_cell_and_insert_below = function () {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 var cell = this.get_selected_cell();
var cell_index = this.find_cell_index(cell);
Brian E. Granger
More work on the dual mode UX.
r14015
cell.execute();
Brian E. Granger
Semi working version of basic dual mode UX....
r14016
// If we are at the end always insert a new cell and return
Brian E. Granger
Renaming execute methods.
r14085 if (cell_index === (this.ncells()-1)) {
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.command_mode();
Paul Ivanov
inserting new cells preserves type closes #4917
r16778 this.insert_cell_below();
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.select(cell_index+1);
this.edit_mode();
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 this.scroll_to_bottom();
this.set_dirty(true);
return;
Brian E. Granger
Renaming execute methods.
r14085 }
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669
this.command_mode();
Paul Ivanov
inserting new cells preserves type closes #4917
r16778 this.insert_cell_below();
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.select(cell_index+1);
this.edit_mode();
Brian E. Granger
Renaming execute methods.
r14085 this.set_dirty(true);
};
/**
* Execute or render cell outputs and select the next cell.
*/
Notebook.prototype.execute_cell_and_select_below = function () {
var cell = this.get_selected_cell();
var cell_index = this.find_cell_index(cell);
cell.execute();
// If we are at the end always insert a new cell and return
if (cell_index === (this.ncells()-1)) {
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.command_mode();
Paul Ivanov
inserting new cells preserves type closes #4917
r16778 this.insert_cell_below();
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.select(cell_index+1);
this.edit_mode();
Brian E. Granger
Renaming execute methods.
r14085 this.scroll_to_bottom();
this.set_dirty(true);
return;
Brian E. Granger
More work on the dual mode UX.
r14015 }
Brian E. Granger
Renaming execute methods.
r14085
Jonathan Frederic
Fixed lots of bugs...
r15493 this.command_mode();
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.select(cell_index+1);
Jonathan Frederic
focus next cell on shift+enter
r15749 this.focus_cell();
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(true);
Brian E. Granger
Fixing execution related things....
r4378 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Execute all cells below the selected cell.
*/
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 Notebook.prototype.execute_cells_below = function () {
this.execute_cell_range(this.get_selected_index(), this.ncells());
Matthias BUSSONNIER
undefinied that -> this
r8821 this.scroll_to_bottom();
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Execute all cells above the selected cell.
*/
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 Notebook.prototype.execute_cells_above = function () {
this.execute_cell_range(0, this.get_selected_index());
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Execute all cells.
*/
Brian E. Granger
Fixing execution related things....
r4378 Notebook.prototype.execute_all_cells = function () {
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 this.execute_cell_range(0, this.ncells());
Matthias BUSSONNIER
fix run-all (that-> this)
r9816 this.scroll_to_bottom();
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Execute a contiguous range of cells.
*
Jonathan Frederic
Clean up comments
r19511 * @param {integer} start - index of the first cell to execute (inclusive)
* @param {integer} end - index of the last cell to execute (exclusive)
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 Notebook.prototype.execute_cell_range = function (start, end) {
Brian E. Granger
Make sure we are in command mode before we select a new cell.
r15669 this.command_mode();
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 for (var i=start; i<end; i++) {
Brian E. Granger
Fixing execution related things....
r4378 this.select(i);
Brian E. Granger
Renaming execute methods.
r14085 this.execute_cell();
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Fixing execution related things....
r4378 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Persistance and loading
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Getter method for this notebook's name.
*
Jonathan Frederic
Some clean-up
r19509 * @return {string} This notebook's name (excluding file extension)
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Major refactoring of saving, notification....
r6047 Notebook.prototype.get_notebook_name = function () {
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 var nbname = this.notebook_name.substring(0,this.notebook_name.length-6);
Zachary Sailer
drop file ext off notebook name in notebook
r13005 return nbname;
Brian Granger
Major refactoring of saving, notification....
r6047 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Setter method for this notebook's name.
*
Jonathan Frederic
Clean up comments
r19511 * @param {string} name
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Major refactoring of saving, notification....
r6047 Notebook.prototype.set_notebook_name = function (name) {
Min RK
update frontend with path/name changes...
r18752 var parent = utils.url_path_split(this.notebook_path)[0];
Brian Granger
Major refactoring of saving, notification....
r6047 this.notebook_name = name;
Min RK
update frontend with path/name changes...
r18752 this.notebook_path = utils.url_path_join(parent, name);
Brian Granger
Major refactoring of saving, notification....
r6047 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Check that a notebook's name is valid.
*
Jonathan Frederic
Some clean-up
r19509 * @param {string} nbname - A name for this notebook
* @return {boolean} True if the name is valid, false if invalid
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian Granger
Major refactoring of saving, notification....
r6047 Notebook.prototype.test_notebook_name = function (nbname) {
nbname = nbname || '';
MinRK
holy crap, semicolons
r15236 if (nbname.length>0 && !this.notebook_name_blacklist_re.test(nbname)) {
Brian Granger
Major refactoring of saving, notification....
r6047 return true;
} else {
return false;
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Major refactoring of saving, notification....
r6047 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Load a notebook from JSON (.ipynb).
*
Jonathan Frederic
Clean up comments
r19511 * @param {object} data - JSON representation of a notebook
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.fromJSON = function (data) {
MinRK
add dialogs for failed save/load...
r18249
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 var content = data.content;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var ncells = this.ncells();
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var i;
for (i=0; i<ncells; i++) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Always delete cell 0 as they get renumbered as they are deleted.
Bussonnier Matthias
make method private
r19588 this._unsafe_delete_cell(0);
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Major refactoring of saving, notification....
r6047 // Save the metadata and name.
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 this.metadata = content.metadata;
this.notebook_name = data.name;
Min RK
update frontend with path/name changes...
r18752 this.notebook_path = data.path;
MinRK
disable trust notebook menu item on trusted notebooks
r15657 var trusted = true;
Thomas Kluyver
Set codemirror mode from kernelspecs
r17377
Thomas Kluyver
Move language info from kernelspec to kernel_info_reply
r18468 // Set the codemirror mode from language_info metadata
if (this.metadata.language_info !== undefined) {
var langinfo = this.metadata.language_info;
// Mode 'null' should be plain, unhighlighted text.
Min RK
fix loading of language name from kernel_info...
r19021 var cm_mode = langinfo.codemirror_mode || langinfo.name || 'null';
Thomas Kluyver
Move language info from kernelspec to kernel_info_reply
r18468 this.set_codemirror_mode(cm_mode);
}
MinRK
update html/js to nbformat 4
r18584 var new_cells = content.cells;
ncells = new_cells.length;
var cell_data = null;
var new_cell = null;
for (i=0; i<ncells; i++) {
cell_data = new_cells[i];
new_cell = this.insert_cell_at_index(cell_data.cell_type, i);
new_cell.fromJSON(cell_data);
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (new_cell.cell_type === 'code' && !new_cell.output_area.trusted) {
MinRK
update html/js to nbformat 4
r18584 trusted = false;
MinRK
holy crap, semicolons
r15236 }
}
Jason Grout
Fix several small bugs in the notebook trust framework...
r17833 if (trusted !== this.trusted) {
MinRK
disable trust notebook menu item on trusted notebooks
r15657 this.trusted = trusted;
MinRK
trigger trust_changed properly on load...
r18196 this.events.trigger("trust_changed.Notebook", trusted);
MinRK
disable trust notebook menu item on trusted notebooks
r15657 }
Brian Granger
Basic notebook saving and loading....
r4315 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Dump this notebook into a JSON-friendly object.
*
Jonathan Frederic
Clean up comments
r19511 * @return {object} A JSON-friendly representation of this notebook.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.toJSON = function () {
Jonathan Frederic
Start JSDoc integration
r19503 // remove the conversion indicator, which only belongs in-memory
MinRK
update html/js to nbformat 4
r18584 delete this.metadata.orig_nbformat;
delete this.metadata.orig_nbformat_minor;
Brian Granger
Refactoring of the notebooks cell management....
r5945 var cells = this.get_cells();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var ncells = cells.length;
Brian Granger
Adding missing var statements in notebook.js.
r7179 var cell_array = new Array(ncells);
MinRK
disable trust notebook menu item on trusted notebooks
r15657 var trusted = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 for (var i=0; i<ncells; i++) {
MinRK
disable trust notebook menu item on trusted notebooks
r15657 var cell = cells[i];
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (cell.cell_type === 'code' && !cell.output_area.trusted) {
MinRK
disable trust notebook menu item on trusted notebooks
r15657 trusted = false;
}
cell_array[i] = cell.toJSON();
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Adding missing var statements in notebook.js.
r7179 var data = {
MinRK
update html/js to nbformat 4
r18584 cells: cell_array,
Thomas Kluyver
Set notebook nbformat in toJSON
r18675 metadata: this.metadata,
nbformat: this.nbformat,
nbformat_minor: this.nbformat_minor
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (trusted !== this.trusted) {
MinRK
disable trust notebook menu item on trusted notebooks
r15657 this.trusted = trusted;
Jonathan Frederic
Fixed events
r17195 this.events.trigger("trust_changed.Notebook", trusted);
MinRK
disable trust notebook menu item on trusted notebooks
r15657 }
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 return data;
Brian E. Granger
Massive work on the notebook document format....
r4484 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Start an autosave timer which periodically saves the notebook.
MinRK
add autosave timer...
r10505 *
Jonathan Frederic
Some clean-up
r19509 * @param {integer} interval - the autosave interval in milliseconds
MinRK
add autosave timer...
r10505 */
MinRK
s/autosave_notebook/set_autosave_interval/
r10508 Notebook.prototype.set_autosave_interval = function (interval) {
MinRK
add autosave timer...
r10505 var that = this;
// clear previous interval, so we don't get simultaneous timers
if (this.autosave_timer) {
clearInterval(this.autosave_timer);
}
Min RK
handle various permission failures...
r19005 if (!this.writable) {
// disable autosave if not writable
interval = 0;
}
MinRK
add autosave timer...
r10505
MinRK
s/autosave_notebook/set_autosave_interval/
r10508 this.autosave_interval = this.minimum_autosave_interval = interval;
MinRK
add autosave timer...
r10505 if (interval) {
this.autosave_timer = setInterval(function() {
MinRK
only autosave when dirty
r10506 if (that.dirty) {
that.save_notebook();
}
MinRK
add autosave timer...
r10505 }, interval);
Jonathan Frederic
Fixed events
r17195 this.events.trigger("autosave_enabled.Notebook", interval);
MinRK
add autosave timer...
r10505 } else {
this.autosave_timer = null;
Jonathan Frederic
Fixed events
r17195 this.events.trigger("autosave_disabled.Notebook");
MinRK
holy crap, semicolons
r15236 }
MinRK
add autosave timer...
r10505 };
/**
Paul Ivanov
prevent saving of partially loaded notebooks...
r15881 * Save this notebook on the server. This becomes a notebook instance's
* .save_notebook method *after* the entire notebook has been loaded.
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Thomas Kluyver
Eliminate remaining uses of extra_settings
r18774 Notebook.prototype.save_notebook = function () {
Min RK
handle various permission failures...
r19005 if (!this._fully_loaded) {
Bussonnier Matthias
update to use event
r18992 this.events.trigger('notebook_save_failed.Notebook',
new Error("Load failed, save is disabled")
);
Bussonnier Matthias
some extra comma/semicolon cleanup
r18993 return;
Min RK
handle various permission failures...
r19005 } else if (!this.writable) {
this.events.trigger('notebook_save_failed.Notebook',
new Error("Notebook is read-only")
);
return;
Matthias Bussonnier
Some cleanup unused code and missig use-strict
r18991 }
Min RK
handle various permission failures...
r19005
Jonathan Frederic
Add an event that fires before the notebook saves
r19359 // Trigger an event before save, which allows listeners to modify
// the notebook as needed.
this.events.trigger('before_save.Notebook');
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 // Create a JSON model to be sent to the server.
Thomas Kluyver
Make contents JS API consistent
r18653 var model = {
type : "notebook",
Thomas Kluyver
Set notebook nbformat in toJSON
r18675 content : this.toJSON()
Thomas Kluyver
Make contents JS API consistent
r18653 };
MinRK
add autosave timer...
r10505 // time the ajax call for autosave tuning purposes.
var start = new Date().getTime();
Thomas Kluyver
Make contents JS API consistent
r18653
var that = this;
Thomas Kluyver
Fix asyncy nbconvert to download
r18969 return this.contents.save(this.notebook_path, model).then(
Thomas Kluyver
All aboard the promise train
r18829 $.proxy(this.save_notebook_success, this, start),
function (error) {
Min RK
update frontend with path/name changes...
r18752 that.events.trigger('notebook_save_failed.Notebook', error);
Thomas Kluyver
Make contents JS API consistent
r18653 }
Thomas Kluyver
All aboard the promise train
r18829 );
Brian Granger
Basic notebook saving and loading....
r4315 };
MinRK
expose notebook checkpoints in html/js...
r10501
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Success callback for saving a notebook.
*
Jonathan Frederic
Some clean-up
r19509 * @param {integer} start - Time when the save request start
Jonathan Frederic
Clean up comments
r19511 * @param {object} data - JSON representation of a notebook
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Kester Tong
Modifies Contents API to return Error objects...
r18661 Notebook.prototype.save_notebook_success = function (start, data) {
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(false);
MinRK
add dialogs for failed save/load...
r18249 if (data.message) {
// save succeeded, but validation failed.
var body = $("<div>");
var title = "Notebook validation failed";
body.append($("<p>").text(
"The save operation succeeded," +
" but the notebook does not appear to be valid." +
" The validation error was:"
)).append($("<div>").addClass("validation-error").append(
$("<pre>").text(data.message)
));
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title: title,
body: body,
buttons : {
OK : {
"class" : "btn-primary"
}
}
});
}
Jonathan Frederic
Fixed events
r17195 this.events.trigger('notebook_saved.Notebook');
MinRK
add autosave timer...
r10505 this._update_autosave_interval(start);
MinRK
expose notebook checkpoints in html/js...
r10501 if (this._checkpoint_after_save) {
this.create_checkpoint();
this._checkpoint_after_save = false;
MinRK
holy crap, semicolons
r15236 }
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
MinRK
expose notebook checkpoints in html/js...
r10501
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Jonathan Frederic
Clean up comments
r19511 * Update the autosave interval based on the duration of the last save.
MinRK
add autosave timer...
r10505 *
Jonathan Frederic
Some clean-up
r19509 * @param {integer} timestamp - when the save request started
MinRK
add autosave timer...
r10505 */
Notebook.prototype._update_autosave_interval = function (start) {
var duration = (new Date().getTime() - start);
if (this.autosave_interval) {
// new save interval: higher of 10x save duration or parameter (default 30 seconds)
var interval = Math.max(10 * duration, this.minimum_autosave_interval);
// round to 10 seconds, otherwise we will be setting a new interval too often
interval = 10000 * Math.round(interval / 10000);
// set new interval, if it's changed
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (interval !== this.autosave_interval) {
MinRK
s/autosave_notebook/set_autosave_interval/
r10508 this.set_autosave_interval(interval);
MinRK
add autosave timer...
r10505 }
}
};
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997
MinRK
Add Trust Notebook to File menu
r15655 /**
* Explicitly trust the output of this notebook.
*/
Thomas Kluyver
Eliminate remaining uses of extra_settings
r18774 Notebook.prototype.trust_notebook = function () {
MinRK
Add Trust Notebook to File menu
r15655 var body = $("<div>").append($("<p>")
MinRK
make trust notebook dialog a single paragraph
r15673 .text("A trusted IPython notebook may execute hidden malicious code ")
.append($("<strong>")
.append(
$("<em>").text("when you open it")
)
).append(".").append(
" Selecting trust will immediately reload this notebook in a trusted state."
).append(
" For more information, see the "
MinRK
update link...
r16046 ).append($("<a>").attr("href", "http://ipython.org/ipython-doc/2/notebook/security.html")
MinRK
make trust notebook dialog a single paragraph
r15673 .text("IPython security documentation")
).append(".")
);
MinRK
Add Trust Notebook to File menu
r15655
var nb = this;
Jonathan Frederic
Fix imports of "modules",...
r17202 dialog.modal({
Jonathan Frederic
Some JS test fixes
r17212 notebook: this,
keyboard_manager: this.keyboard_manager,
MinRK
Add Trust Notebook to File menu
r15655 title: "Trust this notebook?",
body: body,
buttons: {
Cancel : {},
Trust : {
class : "btn-danger",
click : function () {
MinRK
trust via mark cells and save, rather than trust API request
r15663 var cells = nb.get_cells();
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (cell.cell_type === 'code') {
MinRK
trust via mark cells and save, rather than trust API request
r15663 cell.output_area.trusted = true;
}
}
Jason Grout
Fix several small bugs in the notebook trust framework...
r17833 nb.events.on('notebook_saved.Notebook', function () {
MinRK
trust via mark cells and save, rather than trust API request
r15663 window.location.reload();
});
nb.save_notebook();
MinRK
Add Trust Notebook to File menu
r15655 }
}
}
});
};
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 /**
* Make a copy of the current notebook.
*/
Min RK
handle various permission failures...
r19005 Notebook.prototype.copy_notebook = function () {
var that = this;
MinRK
s/base_project_url/base_url/...
r15238 var base_url = this.base_url;
Thomas Kluyver
Eliminate remaining uses of extra_settings
r18774 var w = window.open();
Min RK
update frontend with path/name changes...
r18752 var parent = utils.url_path_split(this.notebook_path)[0];
Thomas Kluyver
All aboard the promise train
r18829 this.contents.copy(this.notebook_path, parent).then(
function (data) {
Thomas Kluyver
Eliminate remaining uses of extra_settings
r18774 w.location = utils.url_join_encode(
Min RK
update frontend with path/name changes...
r18752 base_url, 'notebooks', data.path
Thomas Kluyver
Eliminate remaining uses of extra_settings
r18774 );
},
Thomas Kluyver
All aboard the promise train
r18829 function(error) {
Thomas Kluyver
Eliminate remaining uses of extra_settings
r18774 w.close();
Min RK
handle various permission failures...
r19005 that.events.trigger('notebook_copy_failed', error);
Thomas Kluyver
All aboard the promise train
r18829 }
);
Zachary Sailer
Change new/copy URLS to POST requests
r13017 };
Min RK
add Notebook.ensure_extension...
r19684
/**
* Ensure a filename has the right extension
* Returns the filename with the appropriate extension, appending if necessary.
*/
Notebook.prototype.ensure_extension = function (name) {
if (!name.match(/\.ipynb$/)) {
name = name + ".ipynb";
}
return name;
};
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 /**
Jonathan Frederic
Clean up comments
r19511 * Rename the notebook.
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 * @param {string} new_name
* @return {Promise} promise that resolves when the notebook is renamed.
*/
Thomas Kluyver
Make contents JS API consistent
r18653 Notebook.prototype.rename = function (new_name) {
Min RK
add Notebook.ensure_extension...
r19684 new_name = this.ensure_extension(new_name);
Brian E. Granger
Fixing issues with js tests....
r14965
var that = this;
Min RK
update frontend with path/name changes...
r18752 var parent = utils.url_path_split(this.notebook_path)[0];
var new_path = utils.url_path_join(parent, new_name);
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 return this.contents.rename(this.notebook_path, new_path).then(
Thomas Kluyver
All aboard the promise train
r18829 function (json) {
Min RK
update frontend with path/name changes...
r18752 that.notebook_name = json.name;
that.notebook_path = json.path;
that.session.rename_notebook(json.path);
Thomas Kluyver
Cut out some superfluous events
r18654 that.events.trigger('notebook_renamed.Notebook', json);
Min RK
Don't dismiss rename dialog until rename is complete...
r18964 }
Thomas Kluyver
All aboard the promise train
r18829 );
Brian E. Granger
Fixing issues with js tests....
r14965 };
Jonathan Frederic
Make sure every function appears in the Notebook class.
r19508 /**
* Delete this notebook
*/
KesterTong
Use events for rename_notebook...
r18634 Notebook.prototype.delete = function () {
Min RK
update frontend with path/name changes...
r18752 this.contents.delete(this.notebook_path);
MinRK
holy crap, semicolons
r15236 };
Zachary Sailer
Renaming fixed
r13018
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Request a notebook's data from the server.
*
Jonathan Frederic
Some clean-up
r19509 * @param {string} notebook_path - A notebook to load
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Min RK
update frontend with path/name changes...
r18752 Notebook.prototype.load_notebook = function (notebook_path) {
Min RK
use promises to wait for kernelspecs on notebook load...
r19884 var that = this;
MinRK
add utils.url_path_join...
r13063 this.notebook_path = notebook_path;
Min RK
update frontend with path/name changes...
r18752 this.notebook_name = utils.url_path_split(this.notebook_path)[1];
Jonathan Frederic
Fixed events
r17195 this.events.trigger('notebook_loading.Notebook');
Thomas Kluyver
Use promises for GET requests
r18827 this.contents.get(notebook_path, {type: 'notebook'}).then(
Min RK
move promise sync to kernelselector, from notebook
r19885 $.proxy(this.load_notebook_success, this),
Thomas Kluyver
Use promises for GET requests
r18827 $.proxy(this.load_notebook_error, this)
);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Success callback for loading a notebook from the server.
*
* Load notebook data from the JSON response.
*
Jonathan Frederic
Clean up comments
r19511 * @param {object} data JSON representation of a notebook
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Kester Tong
Modifies Contents API to return Error objects...
r18661 Notebook.prototype.load_notebook_success = function (data) {
Min RK
update frontend with path/name changes...
r18752 var failed, msg;
MinRK
add dialogs for failed save/load...
r18249 try {
this.fromJSON(data);
} catch (e) {
failed = e;
console.log("Notebook failed to load from JSON:", e);
}
if (failed || data.message) {
// *either* fromJSON failed or validation failed
var body = $("<div>");
var title;
if (failed) {
title = "Notebook failed to load";
body.append($("<p>").text(
"The error was: "
)).append($("<div>").addClass("js-error").text(
failed.toString()
)).append($("<p>").text(
"See the error console for details."
));
} else {
title = "Notebook validation failed";
}
if (data.message) {
if (failed) {
Min RK
update frontend with path/name changes...
r18752 msg = "The notebook also failed validation:";
MinRK
add dialogs for failed save/load...
r18249 } else {
msg = "An invalid notebook may not function properly." +
Min RK
update frontend with path/name changes...
r18752 " The validation error was:";
MinRK
add dialogs for failed save/load...
r18249 }
body.append($("<p>").text(
msg
)).append($("<div>").addClass("validation-error").append(
$("<pre>").text(data.message)
));
}
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
title: title,
body: body,
buttons : {
OK : {
"class" : "btn-primary"
}
}
});
}
Brian E. Granger
Massive work on the notebook document format....
r4484 if (this.ncells() === 0) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 this.insert_cell_below('code');
Jonathan Frederic
s/trigger_edit_mode/edit_mode
r15541 this.edit_mode(0);
Brian E. Granger
More work on the dual mode UX.
r14015 } else {
this.select(0);
Brian E. Granger
Refactoring Notebook.command_mode.
r15629 this.handle_command_mode(this.get_cell(0));
MinRK
holy crap, semicolons
r15236 }
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(false);
Brian Granger
Fixing bugs in CodeMirror refreshing.
r5950 this.scroll_to_top();
Min RK
handle various permission failures...
r19005 this.writable = data.writable || false;
MinRK
update html/js to nbformat 4
r18584 var nbmodel = data.content;
var orig_nbformat = nbmodel.metadata.orig_nbformat;
var orig_nbformat_minor = nbmodel.metadata.orig_nbformat_minor;
if (orig_nbformat !== undefined && nbmodel.nbformat !== orig_nbformat) {
Min RK
don't assume converted notebooks are old...
r18672 var src;
v923z
replaced nbmodel.orig_nbformat by orig_nbformat
r18686 if (nbmodel.nbformat > orig_nbformat) {
Min RK
don't assume converted notebooks are old...
r18672 src = " an older notebook format ";
} else {
src = " a newer notebook format ";
}
Min RK
update frontend with path/name changes...
r18752 msg = "This notebook has been converted from" + src +
v923z
replaced nbmodel.orig_nbformat by orig_nbformat
r18686 "(v"+orig_nbformat+") to the current notebook " +
v923z
fixed notebook checking code
r18685 "format (v"+nbmodel.nbformat+"). The next time you save this notebook, the " +
Min RK
don't assume converted notebooks are old...
r18672 "current notebook format will be used.";
v923z
replaced nbmodel.orig_nbformat by orig_nbformat
r18686 if (nbmodel.nbformat > orig_nbformat) {
Min RK
don't assume converted notebooks are old...
r18672 msg += " Older versions of IPython may not be able to read the new format.";
} else {
msg += " Some features of the original notebook may not be available.";
}
msg += " To preserve the original version, close the " +
"notebook without saving it.";
Jonathan Frederic
Fix imports of "modules",...
r17202 dialog.modal({
Jonathan Frederic
Some JS test fixes
r17212 notebook: this,
keyboard_manager: this.keyboard_manager,
MinRK
bootstrap dialogs
r10895 title : "Notebook converted",
body : msg,
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 buttons : {
MinRK
bootstrap dialogs
r10895 OK : {
class : "btn-primary"
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 }
MinRK
bootstrap dialogs
r10895 }
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 });
Min RK
Preserve nbformat_minor from the future...
r19107 } else if (this.nbformat_minor < nbmodel.nbformat_minor) {
this.nbformat_minor = nbmodel.nbformat_minor;
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 }
MinRK
add Revert to the menu bar
r10503
MinRK
holy crap, semicolons
r15236 if (this.session === null) {
Min RK
allow kernel_name to be specified in url parameter
r19257 var kernel_name;
if (this.metadata.kernelspec) {
var kernelspec = this.metadata.kernelspec || {};
kernel_name = kernelspec.name;
} else {
kernel_name = utils.get_url_param('kernel_name');
}
Min RK
cleanup kernelspec loading...
r19886 if (kernel_name) {
// setting kernel_name here triggers start_session
this.kernel_selector.set_kernel(kernel_name);
} else {
// start a new session with the server's default kernel
// spec_changed events will fire after kernel is loaded
this.start_session();
}
Zachary Sailer
manual rebase static/notebook/js files
r12986 }
MinRK
remove notebook read-only view...
r11644 // load our checkpoint list
MinRK
store cell toolbar preset in notebook metadata...
r13679 this.list_checkpoints();
// load toolbar state
if (this.metadata.celltoolbar) {
Jonathan Frederic
Fix imports of "modules",...
r17202 celltoolbar.CellToolbar.global_show();
Matthias BUSSONNIER
Use global event for celltoolbar
r17454 celltoolbar.CellToolbar.activate_preset(this.metadata.celltoolbar);
Raffaele De Feo
Make sure that celltoolbars are hidden...
r16534 } else {
Jonathan Frederic
Fix imports of "modules",...
r17202 celltoolbar.CellToolbar.global_hide();
MinRK
store cell toolbar preset in notebook metadata...
r13679 }
Min RK
handle various permission failures...
r19005
if (!this.writable) {
this.set_autosave_interval(0);
this.events.trigger('notebook_read_only.Notebook');
}
Paul Ivanov
prevent saving of partially loaded notebooks...
r15881 // now that we're fully loaded, it is safe to restore save functionality
Matthias Bussonnier
Some cleanup unused code and missig use-strict
r18991 this._fully_loaded = true;
Jonathan Frederic
Fixed events
r17195 this.events.trigger('notebook_loaded.Notebook');
Brian E. Granger
Massive work on the notebook document format....
r4484 };
Matthias BUSSONNIER
load the per kernel kernel.js and kernel.css...
r19404 Notebook.prototype.set_kernelselector = function(k_selector){
this.kernel_selector = k_selector;
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Failure callback for loading a notebook from the server.
*
Kester Tong
Modifies Contents API to return Error objects...
r18661 * @param {Error} error
*/
Notebook.prototype.load_notebook_error = function (error) {
this.events.trigger('notebook_load_failed.Notebook', error);
var msg;
Min RK
update frontend with path/name changes...
r18752 if (error.name === utils.XHR_ERROR && error.xhr.status === 500) {
Kester Tong
Modifies Contents API to return Error objects...
r18661 utils.log_ajax_error(error.xhr, error.xhr_status, error.xhr_error);
msg = "An unknown error occurred while loading this notebook. " +
MinRK
better message when notebook format is not supported...
r11643 "This version can load notebook formats " +
Kester Tong
Modifies Contents API to return Error objects...
r18661 "v" + this.nbformat + " or earlier. See the server log for details.";
} else {
msg = error.message;
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 }
Jonathan Frederic
Fix imports of "modules",...
r17202 dialog.modal({
Jonathan Frederic
Some JS test fixes
r17212 notebook: this,
keyboard_manager: this.keyboard_manager,
MinRK
better message when notebook format is not supported...
r11643 title: "Error loading notebook",
body : msg,
buttons : {
"OK": {}
}
});
MinRK
holy crap, semicolons
r15236 };
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839
Jonathan Frederic
Clean up comments
r19511 /********************* checkpoint-related ********************/
MinRK
expose notebook checkpoints in html/js...
r10501
/**
* Save the notebook then immediately create a checkpoint.
*/
Notebook.prototype.save_checkpoint = function () {
this._checkpoint_after_save = true;
this.save_notebook();
};
/**
MinRK
minor checkpoint cleanup...
r12050 * Add a checkpoint for this notebook.
*/
Notebook.prototype.add_checkpoint = function (checkpoint) {
var found = false;
for (var i = 0; i < this.checkpoints.length; i++) {
var existing = this.checkpoints[i];
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 if (existing.id === checkpoint.id) {
MinRK
minor checkpoint cleanup...
r12050 found = true;
this.checkpoints[i] = checkpoint;
break;
}
}
if (!found) {
this.checkpoints.push(checkpoint);
}
this.last_checkpoint = this.checkpoints[this.checkpoints.length - 1];
};
/**
MinRK
expose notebook checkpoints in html/js...
r10501 * List checkpoints for this notebook.
*/
Notebook.prototype.list_checkpoints = function () {
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 var that = this;
Thomas Kluyver
All aboard the promise train
r18829 this.contents.list_checkpoints(this.notebook_path).then(
$.proxy(this.list_checkpoints_success, this),
function(error) {
Min RK
update frontend with path/name changes...
r18752 that.events.trigger('list_checkpoints_failed.Notebook', error);
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 }
Thomas Kluyver
All aboard the promise train
r18829 );
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Success callback for listing checkpoints.
*
Jonathan Frederic
Clean up comments
r19511 * @param {object} data - JSON representation of a checkpoint
MinRK
expose notebook checkpoints in html/js...
r10501 */
Kester Tong
Modifies Contents API to return Error objects...
r18661 Notebook.prototype.list_checkpoints_success = function (data) {
MinRK
minor checkpoint cleanup...
r12050 this.checkpoints = data;
MinRK
expose notebook checkpoints in html/js...
r10501 if (data.length) {
MinRK
minor checkpoint cleanup...
r12050 this.last_checkpoint = data[data.length - 1];
MinRK
expose notebook checkpoints in html/js...
r10501 } else {
this.last_checkpoint = null;
}
Jonathan Frederic
Fixed events
r17195 this.events.trigger('checkpoints_listed.Notebook', [data]);
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Create a checkpoint of this notebook on the server from the most recent save.
*/
Notebook.prototype.create_checkpoint = function () {
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 var that = this;
Thomas Kluyver
All aboard the promise train
r18829 this.contents.create_checkpoint(this.notebook_path).then(
$.proxy(this.create_checkpoint_success, this),
function (error) {
Min RK
update frontend with path/name changes...
r18752 that.events.trigger('checkpoint_failed.Notebook', error);
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 }
Thomas Kluyver
All aboard the promise train
r18829 );
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Success callback for creating a checkpoint.
*
Jonathan Frederic
Clean up comments
r19511 * @param {object} data - JSON representation of a checkpoint
MinRK
expose notebook checkpoints in html/js...
r10501 */
Kester Tong
Modifies Contents API to return Error objects...
r18661 Notebook.prototype.create_checkpoint_success = function (data) {
MinRK
minor checkpoint cleanup...
r12050 this.add_checkpoint(data);
Jonathan Frederic
Fixed events
r17195 this.events.trigger('checkpoint_created.Notebook', data);
MinRK
expose notebook checkpoints in html/js...
r10501 };
Jonathan Frederic
Some clean-up
r19509 /**
* Display the restore checkpoint dialog
* @param {string} checkpoint ID
*/
MinRK
restore checkpoints in a sub-list...
r10520 Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) {
MinRK
expose notebook checkpoints in html/js...
r10501 var that = this;
MinRK
holy crap, semicolons
r15236 checkpoint = checkpoint || this.last_checkpoint;
MinRK
expose notebook checkpoints in html/js...
r10501 if ( ! checkpoint ) {
console.log("restore dialog, but no checkpoint to restore to!");
return;
}
MinRK
bootstrap dialogs
r10895 var body = $('<div/>').append(
MinRK
restore checkpoints in a sub-list...
r10520 $('<p/>').addClass("p-space").text(
"Are you sure you want to revert the notebook to " +
MinRK
expose notebook checkpoints in html/js...
r10501 "the latest checkpoint?"
).append(
$("<strong/>").text(
" This cannot be undone."
)
)
).append(
MinRK
restore checkpoints in a sub-list...
r10520 $('<p/>').addClass("p-space").text("The checkpoint was last updated at:")
MinRK
expose notebook checkpoints in html/js...
r10501 ).append(
MinRK
restore checkpoints in a sub-list...
r10520 $('<p/>').addClass("p-space").text(
Date(checkpoint.last_modified)
).css("text-align", "center")
MinRK
expose notebook checkpoints in html/js...
r10501 );
Jonathan Frederic
Fix imports of "modules",...
r17202 dialog.modal({
Jonathan Frederic
Some JS test fixes
r17212 notebook: this,
keyboard_manager: this.keyboard_manager,
MinRK
bootstrap dialogs
r10895 title : "Revert notebook to checkpoint",
body : body,
MinRK
expose notebook checkpoints in html/js...
r10501 buttons : {
MinRK
bootstrap dialogs
r10895 Revert : {
class : "btn-danger",
click : function () {
MinRK
use 'id' for checkpoint ID key...
r13122 that.restore_checkpoint(checkpoint.id);
MinRK
bootstrap dialogs
r10895 }
MinRK
expose notebook checkpoints in html/js...
r10501 },
MinRK
bootstrap dialogs
r10895 Cancel : {}
MinRK
expose notebook checkpoints in html/js...
r10501 }
});
MinRK
holy crap, semicolons
r15236 };
MinRK
expose notebook checkpoints in html/js...
r10501
/**
* Restore the notebook to a checkpoint state.
*
Jonathan Frederic
Some clean-up
r19509 * @param {string} checkpoint ID
MinRK
expose notebook checkpoints in html/js...
r10501 */
Notebook.prototype.restore_checkpoint = function (checkpoint) {
Jonathan Frederic
Fixed events
r17195 this.events.trigger('notebook_restoring.Notebook', checkpoint);
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 var that = this;
Thomas Kluyver
All aboard the promise train
r18829 this.contents.restore_checkpoint(this.notebook_path, checkpoint).then(
$.proxy(this.restore_checkpoint_success, this),
function (error) {
Min RK
update frontend with path/name changes...
r18752 that.events.trigger('checkpoint_restore_failed.Notebook', error);
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 }
Thomas Kluyver
All aboard the promise train
r18829 );
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Success callback for restoring a notebook to a checkpoint.
*/
Kester Tong
Modifies Contents API to return Error objects...
r18661 Notebook.prototype.restore_checkpoint_success = function () {
Jonathan Frederic
Fixed events
r17195 this.events.trigger('checkpoint_restored.Notebook');
Min RK
update frontend with path/name changes...
r18752 this.load_notebook(this.notebook_path);
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Delete a notebook checkpoint.
*
Jonathan Frederic
Some clean-up
r19509 * @param {string} checkpoint ID
MinRK
expose notebook checkpoints in html/js...
r10501 */
Notebook.prototype.delete_checkpoint = function (checkpoint) {
Jonathan Frederic
Fixed events
r17195 this.events.trigger('notebook_restoring.Notebook', checkpoint);
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 var that = this;
Thomas Kluyver
All aboard the promise train
r18829 this.contents.delete_checkpoint(this.notebook_path, checkpoint).then(
$.proxy(this.delete_checkpoint_success, this),
function (error) {
Kester Tong
Modifies Contents API to return Error objects...
r18661 that.events.trigger('checkpoint_delete_failed.Notebook', error);
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 }
Thomas Kluyver
All aboard the promise train
r18829 );
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
Jonathan Frederic
Clean up comments
r19511 * Success callback for deleting a notebook checkpoint.
MinRK
expose notebook checkpoints in html/js...
r10501 */
Kester Tong
Modifies Contents API to return Error objects...
r18661 Notebook.prototype.delete_checkpoint_success = function () {
this.events.trigger('checkpoint_deleted.Notebook');
Min RK
update frontend with path/name changes...
r18752 this.load_notebook(this.notebook_path);
MinRK
expose notebook checkpoints in html/js...
r10501 };
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 // For backwards compatability.
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Notebook = Notebook;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'Notebook': Notebook};
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 });