edited without stripping whitespace

This commit is contained in:
Celina Kilcrease 2018-04-08 10:07:02 -04:00
parent 6f52c39617
commit e1d8bbbc07

View File

@ -75,7 +75,7 @@ define([
* Contains and manages cells.
* @class Notebook
* @param {string} selector
* @param {object} options - Dictionary of keyword arguments.
* @param {object} options - Dictionary of keyword arguments.
* @param {jQuery} options.events - selector of Events
* @param {KeyboardManager} options.keyboard_manager
* @param {Contents} options.contents
@ -88,7 +88,7 @@ define([
function Notebook(selector, options) {
this.config = options.config;
this.config.loaded.then(this.validate_config.bind(this));
this.class_config = new configmod.ConfigWithDefaults(this.config,
this.class_config = new configmod.ConfigWithDefaults(this.config,
Notebook.options_default, 'Notebook');
this.base_url = options.base_url;
this.notebook_path = options.notebook_path;
@ -113,7 +113,7 @@ define([
// We need a better way to deal with circular instance references.
this.keyboard_manager.notebook = this;
this.save_widget.notebook = this;
mathjaxutils.init();
if (marked) {
@ -217,7 +217,7 @@ define([
});
}
});
Object.defineProperty(this, 'header', {
get: function() {
return that.class_config.get_sync('Header');
@ -226,7 +226,7 @@ define([
that.class_config.set('Header', value);
}
});
Object.defineProperty(this, 'toolbar', {
get: function() {
return that.class_config.get_sync('Toolbar');
@ -235,19 +235,19 @@ define([
that.class_config.set('Toolbar', value);
}
});
this.class_config.get('Header').then(function(header) {
if (header === false) {
that.keyboard_manager.actions.call('jupyter-notebook:hide-header');
}
});
this.class_config.get('Toolbar').then(function(toolbar) {
if (toolbar === false) {
that.keyboard_manager.actions.call('jupyter-notebook:hide-toolbar');
}
});
// prevent assign to miss-typed properties.
Object.seal(this);
}
@ -340,7 +340,7 @@ define([
this.events.on('command_mode.Cell', function (event, data) {
that.handle_command_mode(data.cell);
});
this.events.on('spec_changed.Kernel', function(event, data) {
var existing_spec = that.metadata.kernelspec;
that.metadata.kernelspec = {
@ -371,11 +371,11 @@ define([
var cm_mode = langinfo.codemirror_mode || langinfo.name || 'null';
that.set_codemirror_mode(cm_mode);
});
this.events.on('kernel_idle.Kernel', function () {
that.kernel_busy = false;
});
this.events.on('kernel_busy.Kernel', function () {
that.kernel_busy = true;
});
@ -451,7 +451,7 @@ define([
return;
};
};
Notebook.prototype.show_command_palette = function() {
new commandpalette.CommandPalette(this);
@ -475,7 +475,7 @@ define([
// This statement is used simply so that message extraction
// will pick up the strings. The actual setting of the text
// for the button is in dialog.js.
var button_labels = [
var button_labels = [
i18n.msg._("OK"),
i18n.msg._("Restart and Run All Cells"),
i18n.msg._("Restart and Clear All Outputs"),
@ -486,7 +486,7 @@ define([
i18n.msg._("Overwrite"),
i18n.msg._("Trust"),
i18n.msg._("Revert")];
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
@ -515,7 +515,7 @@ define([
/**
* Scroll the top of the page to a given cell.
*
*
* @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
@ -571,7 +571,7 @@ define([
Notebook.prototype.edit_metadata = function () {
var that = this;
dialog.edit_metadata({
md: this.metadata,
md: this.metadata,
callback: function (new_md) {
if(!_.isEqual(that.metadata, new_md)){
that.set_dirty(true);
@ -587,7 +587,7 @@ define([
/**
* Get all cell elements in the notebook.
*
*
* @return {jQuery} A selector of all cell elements
*/
Notebook.prototype.get_cell_elements = function () {
@ -597,7 +597,7 @@ define([
/**
* Get a particular cell element.
*
*
* @param {integer} index An index of a cell to select
* @return {jQuery} A selector of the given cell.
*/
@ -612,7 +612,7 @@ define([
/**
* Try to get a particular cell by msg_id.
*
*
* @param {string} msg_id A message UUID
* @return {Cell} Cell or null if no cell was found.
*/
@ -622,7 +622,7 @@ define([
/**
* Count the cells in this notebook.
*
*
* @return {integer} The number of cells in this notebook
*/
Notebook.prototype.ncells = function () {
@ -631,7 +631,7 @@ define([
/**
* Get all Cell objects in this notebook.
*
*
* @return {Array} This notebook's Cell objects
*/
Notebook.prototype.get_cells = function () {
@ -644,7 +644,7 @@ define([
/**
* Get a Cell objects from this notebook.
*
*
* @param {integer} index - An index of a cell to retrieve
* @return {Cell} Cell or null if no cell was found.
*/
@ -659,7 +659,7 @@ define([
/**
* Get the cell below a given cell.
*
*
* @param {Cell} cell
* @return {Cell} the next cell or null if no cell was found.
*/
@ -671,7 +671,7 @@ define([
}
return result;
};
/**
* Toggles the display of line numbers in all cells.
*/
@ -681,7 +681,7 @@ define([
/**
* Get the cell above a given cell.
*
*
* @param {Cell} cell
* @return {Cell} The previous cell or null if no cell was found.
*/
@ -693,10 +693,10 @@ define([
}
return result;
};
/**
* Get the numeric index of a given cell.
*
*
* @param {Cell} cell
* @return {integer} The cell's numeric index or null if no cell was found.
*/
@ -712,7 +712,7 @@ define([
/**
* Return given index if defined, or the selected index if not.
*
*
* @param {integer} [index] - A cell's index
* @return {integer} cell index
*/
@ -748,7 +748,7 @@ define([
/**
* Get the currently selected cell.
*
*
* @return {Cell} The selected cell
*/
Notebook.prototype.get_selected_cell = function () {
@ -758,7 +758,7 @@ define([
/**
* Check whether a cell index is valid.
*
*
* @param {integer} index - A cell index
* @return True if the index is valid, false otherwise
*/
@ -831,7 +831,7 @@ define([
/**
* Programmatically select a cell.
*
*
* @param {integer} index - A cell's index
* @param {boolean} moveanchor whether to move the selection
* anchor, default to true.
@ -970,9 +970,9 @@ define([
cell.focus_editor();
}
};
/**
* Ensure either cell, or codemirror is focused. Is none
* Ensure either cell, or codemirror is focused. Is none
* is focused, focus the cell.
*/
Notebook.prototype.ensure_focused = function(){
@ -1049,7 +1049,7 @@ define([
/**
* Move given (or selected) cell up and select it.
*
*
* @param {integer} [index] - cell index
* @return {Notebook} This notebook
*/
@ -1060,7 +1060,7 @@ define([
this.move_selection_up();
return this;
}
var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i) && i > 0) {
var pivot = this.get_cell_element(i-1);
@ -1080,7 +1080,7 @@ define([
/**
* Move given (or selected) cell down and select it.
*
*
* @param {integer} [index] - cell index
* @return {Notebook} This notebook
*/
@ -1091,7 +1091,7 @@ define([
this.move_selection_down();
return this;
}
var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i) && this.is_valid_cell_index(i+1)) {
var pivot = this.get_cell_element(i+1);
@ -1114,7 +1114,7 @@ define([
/**
* 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
*/
@ -1211,7 +1211,7 @@ define([
/**
* Delete a cell from the notebook.
*
*
* @param {integer} [index] - cell's numeric index
* @return {Notebook} This notebook
*/
@ -1287,9 +1287,9 @@ define([
if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
var cell_options = {
events: this.events,
config: this.config,
keyboard_manager: this.keyboard_manager,
events: this.events,
config: this.config,
keyboard_manager: this.keyboard_manager,
notebook: this,
tooltip: this.tooltip
};
@ -1350,7 +1350,7 @@ define([
} else {
return false;
}
this.undelete_backup_stack.map(function (undelete_backup) {
if (index < undelete_backup.index) {
undelete_backup.index += 1;
@ -1384,7 +1384,7 @@ define([
* @return {Cell|null} handle to created cell or null
*/
Notebook.prototype.insert_cell_below = function (type, index) {
if (index === null || index === undefined) {
if (index === null || index === undefined) {
index = Math.max(this.get_selected_index(index), this.get_anchor_index());
}
return this.insert_cell_at_index(type, index+1);
@ -1401,7 +1401,7 @@ define([
var len = this.ncells();
return this.insert_cell_below(type,len-1);
};
/**
* Turn one or more cells into code.
*
@ -1411,7 +1411,7 @@ define([
if (indices === undefined){
indices = this.get_selected_cells_indices();
}
for (var i=0; i <indices.length; i++){
this.to_code(indices[i]);
}
@ -1419,7 +1419,7 @@ define([
/**
* Turn a cell into a code cell.
*
*
* @param {integer} [index] - cell index
*/
Notebook.prototype.to_code = function (index) {
@ -1468,7 +1468,7 @@ define([
/**
* Turn a cell into a Markdown cell.
*
*
* @param {integer} [index] - cell index
*/
Notebook.prototype.to_markdown = function (index) {
@ -1522,7 +1522,7 @@ define([
/**
* Turn a cell into a raw text cell.
*
*
* @param {integer} [index] - cell index
*/
Notebook.prototype.to_raw = function (index) {
@ -1557,7 +1557,7 @@ define([
}
}
};
/**
* Warn about heading cell support removal.
*/
@ -1567,7 +1567,7 @@ define([
keyboard_manager: this.keyboard_manager,
title : i18n.msg._("Use markdown headings"),
body : $("<p/>").text(
i18n.msg._('Jupyter no longer uses special heading cells. ' +
i18n.msg._('Jupyter no longer uses special heading cells. ' +
'Instead, write your headings in Markdown cells using # characters:')
).append($('<pre/>').text(
i18n.msg._('## This is a level 2 heading')
@ -1577,10 +1577,10 @@ define([
}
});
};
/**
* Turn a cell into a heading containing markdown cell.
*
*
* @param {integer} [index] - cell index
* @param {integer} [level] - heading level (e.g., 1 for h1)
*/
@ -1645,7 +1645,7 @@ define([
if (cells.length === 0) {
cells = [this.get_selected_cell()];
}
this.clipboard = [];
var cell_json;
for (var i=0; i < cells.length; i++) {
@ -1715,7 +1715,7 @@ define([
first_inserted.focus_cell();
}
};
/**
* Re-render the output of a CodeCell.
*/
@ -1802,7 +1802,7 @@ define([
// Delete the other cells
this.delete_cells(indices);
// Reset the target cell's undo history
target.code_mirror.clearHistory();
@ -1942,7 +1942,7 @@ define([
/**
* Hide a cell's output.
*
*
* @param {integer} index - cell index
*/
Notebook.prototype.collapse_output = function (index) {
@ -1969,7 +1969,7 @@ define([
/**
* Show a cell's output.
*
*
* @param {integer} index - cell index
*/
Notebook.prototype.expand_output = function (index) {
@ -1996,7 +1996,7 @@ define([
/**
* Clear the selected CodeCell's output area.
*
*
* @param {integer} index - cell index
*/
Notebook.prototype.clear_output = function (index) {
@ -2036,7 +2036,7 @@ define([
/**
* Scroll the selected CodeCell's output area.
*
*
* @param {integer} index - cell index
*/
Notebook.prototype.scroll_output = function (index) {
@ -2061,9 +2061,9 @@ define([
this.set_dirty(true);
};
/**
/**
* Toggle whether a cell's output is collapsed or expanded.
*
*
* @param {integer} index - cell index
*/
Notebook.prototype.toggle_output = function (index) {
@ -2105,7 +2105,7 @@ define([
/**
* Toggle a scrollbar for long cell outputs.
*
*
* @param {integer} index - cell index
*/
Notebook.prototype.toggle_output_scroll = function (index) {
@ -2175,7 +2175,7 @@ define([
var _mode_equal = function(mode1, mode2){
return ((mode1||{}).name||mode1)===((mode2||{}).name||mode2);
};
/**
* Set the codemirror mode for all code cells, including the default for
* new code cells.
@ -2187,7 +2187,7 @@ define([
if (_mode_equal(newmode, this.codemirror_mode)) {
return;
}
var that = this;
utils.requireCodeMirrorMode(newmode, function (spec) {
that._dispatch_mode(spec, newmode);
@ -2233,7 +2233,7 @@ define([
/**
* Once a session is started, link the code cells to the kernel and pass the
* Once a session is started, link the code cells to the kernel and pass the
* comm manager to the widget manager.
*/
Notebook.prototype._session_started = function (){
@ -2255,7 +2255,7 @@ define([
this._session_starting = false;
utils.log_ajax_error(jqxhr, status, error);
};
/**
* Prompt the user to restart the kernel and re-run everything.
* if options.confirm === false, no confirmation dialog is shown.
@ -2353,7 +2353,7 @@ define([
};
return this._restart_kernel(restart_options);
};
// inner implementation of restart dialog & promise
Notebook.prototype._restart_kernel = function (options) {
var that = this;
@ -2363,7 +2363,7 @@ define([
resolve_promise = resolve;
reject_promise = reject;
});
function restart_and_resolve () {
that.kernel.restart(function () {
// resolve when the kernel is *ready* not just started
@ -2372,7 +2372,7 @@ define([
}
var do_kernel_action = options.kernel_action || restart_and_resolve;
// no need to confirm if the kernel is not connected
if (options.confirm === false || !that.kernel.is_connected()) {
var default_button = options.dialog.buttons[Object.keys(options.dialog.buttons)[0]];
@ -2401,7 +2401,7 @@ define([
};
/**
*
*
* Halt the kernel and close the notebook window
*/
Notebook.prototype.close_and_halt = function () {
@ -2415,7 +2415,7 @@ define([
// finish with close on success or failure
this.session.delete(close_window, close_window);
};
/**
* Execute cells corresponding to the given indices.
*
@ -2444,7 +2444,7 @@ define([
this.execute_cells(this.get_selected_cells_indices());
};
/**
* Alias for execute_selected_cells, for backwards compatibility --
* previously, doing "Run Cell" would only ever run a single cell (hence
@ -2546,7 +2546,7 @@ define([
/**
* Execute a contiguous range of cells.
*
*
* @param {integer} start - index of the first cell to execute (inclusive)
* @param {integer} end - index of the last cell to execute (exclusive)
*/
@ -2563,7 +2563,7 @@ define([
/**
* Getter method for this notebook's name.
*
*
* @return {string} This notebook's name (excluding file extension)
*/
Notebook.prototype.get_notebook_name = function () {
@ -2583,7 +2583,7 @@ define([
/**
* Check that a notebook's name is valid.
*
*
* @param {string} nbname - A name for this notebook
* @return {boolean} True if the name is valid, false if invalid
*/
@ -2612,7 +2612,7 @@ define([
this.notebook_name = data.name;
this.notebook_path = data.path;
var trusted = true;
// Set the codemirror mode from language_info metadata
if (this.metadata.language_info !== undefined) {
var langinfo = this.metadata.language_info;
@ -2620,7 +2620,7 @@ define([
var cm_mode = langinfo.codemirror_mode || langinfo.name || 'null';
this.set_codemirror_mode(cm_mode);
}
var new_cells = content.cells;
ncells = new_cells.length;
var cell_data = null;
@ -2641,7 +2641,7 @@ define([
/**
* Dump this notebook into a JSON-friendly object.
*
*
* @return {object} A JSON-friendly representation of this notebook.
*/
Notebook.prototype.toJSON = function () {
@ -2675,7 +2675,7 @@ define([
/**
* Start an autosave timer which periodically saves the notebook.
*
*
* @param {integer} interval - the autosave interval in milliseconds
*/
Notebook.prototype.set_autosave_interval = function (interval) {
@ -2688,7 +2688,7 @@ define([
// disable autosave if not writable
interval = 0;
}
this.autosave_interval = this.minimum_autosave_interval = interval;
if (interval) {
this.autosave_timer = setInterval(function() {
@ -2702,7 +2702,7 @@ define([
this.events.trigger("autosave_disabled.Notebook");
}
};
/**
* Save this notebook on the server. This becomes a notebook instance's
* .save_notebook method *after* the entire notebook has been loaded.
@ -2755,7 +2755,7 @@ define([
// In some cases the filesystem reports an inconsistent time,
// so we allow 0.5 seconds difference before complaining.
// This is configurable in nbconfig/notebook.json as `last_modified_check_margin`.
if ((last_modified.getTime() - that.last_modified.getTime()) > last_modified_check_margin) {
if ((last_modified.getTime() - that.last_modified.getTime()) > last_modified_check_margin) {
console.warn("Last saving was done on `"+that.last_modified+"`("+that._last_modified+"), "+
"while the current file seem to have been saved on `"+data.last_modified+"`");
if (that._changed_on_disk_dialog !== null) {
@ -2801,10 +2801,10 @@ define([
return _save();
}
};
/**
* Success callback for saving a notebook.
*
*
* @param {integer} start - Time when the save request start
* @param {object} data - JSON representation of a notebook
*/
@ -2844,10 +2844,10 @@ define([
this._checkpoint_after_save = false;
}
};
/**
* Update the autosave interval based on the duration of the last save.
*
*
* @param {integer} start - when the save request started
*/
Notebook.prototype._update_autosave_interval = function (start) {
@ -2897,7 +2897,7 @@ define([
cell.output_area.trusted = true;
}
}
// If its write only and dirty, save before
// If its write only and dirty, save before
// trusting
var pr;
if(nb.writable && nb.dirty) {
@ -2906,7 +2906,7 @@ define([
else {
pr = Promise.resolve();
}
return pr.then(function() {
return pr.then(function() {
nb.contents.trust(nb.notebook_path)
.then(function() {
nb.events.trigger("trust_changed.Notebook", true);
@ -2950,7 +2950,7 @@ define([
);
});
};
/**
* Ensure a filename has the right extension
* Returns the filename with the appropriate extension, appending if necessary.
@ -2996,7 +2996,7 @@ define([
/**
* Request a notebook's data from the server.
*
*
* @param {string} notebook_path - A notebook to load
*/
Notebook.prototype.load_notebook = function (notebook_path) {
@ -3011,9 +3011,9 @@ define([
/**
* Success callback for loading a notebook from the server.
*
*
* Load notebook data from the JSON response.
*
*
* @param {object} data JSON representation of a notebook
*/
Notebook.prototype.load_notebook_success = function (data) {
@ -3096,7 +3096,7 @@ define([
msg += " ";
msg += i18n.msg._("The next time you save this notebook, the " +
"current notebook format will be used.");
msg += " ";
if (nbmodel.nbformat > orig_nbformat) {
msg += i18n.msg._("Older versions of Jupyter may not be able to read the new format.");
@ -3146,7 +3146,7 @@ define([
}
// load our checkpoint list
this.list_checkpoints();
// load toolbar state
if (this.metadata.celltoolbar) {
celltoolbar.CellToolbar.global_show();
@ -3154,12 +3154,12 @@ define([
} else {
celltoolbar.CellToolbar.global_hide();
}
if (!this.writable) {
this.set_autosave_interval(0);
this.events.trigger('notebook_read_only.Notebook');
}
// now that we're fully loaded, it is safe to restore save functionality
this._fully_loaded = true;
this.events.trigger('notebook_loaded.Notebook');
@ -3171,7 +3171,7 @@ define([
/**
* Failure callback for loading a notebook from the server.
*
*
* @param {Error} error
*/
Notebook.prototype.load_notebook_error = function (error) {
@ -3187,10 +3187,8 @@ define([
console.warn('Error stack trace while loading notebook was:');
console.warn(error.stack);
}
//check if cookies enabled:
if (navigator.cookieEnabled == false){
//set modal message:
msg = i18n.msg._("Please enable cookies and refresh browser.");
msg = i18n.msg._("Jupyter requires cookies to work; please enable cookies and refresh page.");
}
dialog.modal({
notebook: this,
@ -3210,7 +3208,7 @@ define([
};
/********************* checkpoint-related ********************/
/**
* Save the notebook then immediately create a checkpoint.
*/
@ -3218,7 +3216,7 @@ define([
this._checkpoint_after_save = true;
this.save_notebook(true);
};
/**
* Add a checkpoint for this notebook.
*/
@ -3237,7 +3235,7 @@ define([
}
this.last_checkpoint = this.checkpoints[this.checkpoints.length - 1];
};
/**
* List checkpoints for this notebook.
*/
@ -3253,7 +3251,7 @@ define([
/**
* Success callback for listing checkpoints.
*
*
* @param {object} data - JSON representation of a checkpoint
*/
Notebook.prototype.list_checkpoints_success = function (data) {
@ -3281,7 +3279,7 @@ define([
/**
* Success callback for creating a checkpoint.
*
*
* @param {object} data - JSON representation of a checkpoint
*/
Notebook.prototype.create_checkpoint_success = function (data) {
@ -3315,7 +3313,7 @@ define([
' ('+moment(checkpoint.last_modified).fromNow()+')'// Long form: Tuesday, January 27, 2015 12:15 PM
).css("text-align", "center")
);
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
@ -3333,10 +3331,10 @@ define([
}
});
};
/**
* Restore the notebook to a checkpoint state.
*
*
* @param {string} checkpoint ID
*/
Notebook.prototype.restore_checkpoint = function (checkpoint) {
@ -3349,7 +3347,7 @@ define([
}
);
};
/**
* Success callback for restoring a notebook to a checkpoint.
*/
@ -3360,7 +3358,7 @@ define([
/**
* Delete a notebook checkpoint.
*
*
* @param {string} checkpoint ID
*/
Notebook.prototype.delete_checkpoint = function (checkpoint) {
@ -3373,7 +3371,7 @@ define([
}
);
};
/**
* Success callback for deleting a notebook checkpoint.
*/
@ -3383,4 +3381,4 @@ define([
};
return {Notebook: Notebook};
});
});