##// END OF EJS Templates
s/unfocus/blur
s/unfocus/blur

File last commit:

r15498:a5dd9888
r15498:a5dd9888
Show More
notebook.js
2332 lines | 76.0 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
MinRK
add utils.url_path_join...
r13063 // Copyright (C) 2011 The IPython Development Team
Brian E. Granger
More review changes....
r4609 //
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian Granger
Basic notebook saving and loading....
r4315
Brian Granger
Initial reply handling implemented along with css fixes.
r4299 //============================================================================
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 // Notebook
//============================================================================
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var IPython = (function (IPython) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Initial payload handling....
r4356 var utils = IPython.utils;
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* A notebook contains and manages cells.
*
* @class Notebook
* @constructor
* @param {String} selector A jQuery selector for the notebook's DOM element
* @param {Object} [options] A config object
*/
Matthias BUSSONNIER
pass baseUrl as option
r9505 var Notebook = function (selector, options) {
MinRK
various unicode fixes...
r15234 this.options = options = options || {};
MinRK
s/base_project_url/base_url/...
r15238 this.base_url = options.base_url;
MinRK
various unicode fixes...
r15234 this.notebook_path = options.notebook_path;
this.notebook_name = options.notebook_name;
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;
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;
MinRK
add empty metadata field on cells/worksheets...
r7523 // single worksheet for now
this.worksheet_metadata = {};
Brian Granger
Make : invalid in filenames in the Notebook JS code.
r7229 this.notebook_name_blacklist_re = /[\/\\:]/;
MinRK
various unicode fixes...
r15234 this.nbformat = 3; // Increment this when changing the nbformat
this.nbformat_minor = 0; // Increment this when changing the nbformat
Brian E. Granger
Refactoring pager into its own class.
r4357 this.style();
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();
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Tweak the notebook's CSS style.
*
* @method style
*/
Brian E. Granger
Refactoring pager into its own class.
r4357 Notebook.prototype.style = function () {
Brian E. Granger
Left panel is now working.
r4363 $('div#notebook').addClass('border-box-sizing');
Brian E. Granger
Refactoring pager into its own class.
r4357 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Create an HTML and CSS representation of the notebook.
*
* @method create_elements
*/
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.
*
* @method bind_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
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 $([IPython.events]).on('set_next_input.Notebook', function (event, data) {
var index = that.find_cell_index(data.cell);
var new_cell = that.insert_cell_below('code',index);
new_cell.set_text(data.text);
that.dirty = true;
});
Brian Granger
Making Notebook.set_dirty an event so CodeCell can set it....
r7228 $([IPython.events]).on('set_dirty.Notebook', function (event, data) {
that.dirty = data.value;
});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 $([IPython.events]).on('select.Cell', function (event, data) {
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 lots of bugs...
r15493 $([IPython.events]).on('focus_text.Cell', function (event, data) {
Jonathan Frederic
Post in person review...
r15497 that.handle_cell_text_focus(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 lots of bugs...
r15493 $([IPython.events]).on('blur_text.Cell', function (event, data) {
Jonathan Frederic
Post in person review...
r15497 that.handle_cell_text_blur(data.cell);
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 });
MinRK
move restart dialog to notebook.js
r11077 $([IPython.events]).on('status_autorestarting.Kernel', function () {
IPython.dialog.modal({
title: "Kernel Restarting",
body: "The kernel appears to have died. It will restart automatically.",
buttons: {
OK : {
class : "btn-primary"
}
}
});
});
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) {
Zachary Sailer
Fixed bug when linking kernel to new code cells
r12999 that.session.kill_kernel();
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 };
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
*
* @method set_dirty
*/
Notebook.prototype.set_dirty = function (value) {
if (value === undefined) {
value = true;
}
if (this.dirty == value) {
return;
}
$([IPython.events]).trigger('set_dirty.Notebook', {value: value});
};
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Scroll the top of the page to a given cell.
*
* @method scroll_to_cell
* @param {Number} cell_number An index of the cell to view
* @param {Number} time Animation time in milliseconds
* @return {Number} Pixel offset from the top of the container
*/
Matthias BUSSONNIER
Add scroll_to_cell(cell_number) to the notebook
r8419 Notebook.prototype.scroll_to_cell = function (cell_number, time) {
var cells = this.get_cells();
MinRK
holy crap, semicolons
r15236 time = time || 0;
Matthias BUSSONNIER
Add scroll_to_cell(cell_number) to the notebook
r8419 cell_number = Math.min(cells.length-1,cell_number);
cell_number = Math.max(0 ,cell_number);
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var scroll_value = cells[cell_number].element.position().top-cells[0].element.position().top ;
Matthias BUSSONNIER
Add scroll_to_cell(cell_number) to the notebook
r8419 this.element.animate({scrollTop:scroll_value}, time);
return scroll_value;
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Scroll to the bottom of the page.
*
* @method scroll_to_bottom
*/
Brian E. Granger
Improving the scrolling model.
r4364 Notebook.prototype.scroll_to_bottom = function () {
Brian Granger
Minor fixes to fonts and spacing.
r4366 this.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.
*
* @method scroll_to_top
*/
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 Notebook.prototype.scroll_to_top = function () {
this.element.animate({scrollTop:0}, 0);
};
MinRK
add Edit Notebook Metadata to Edit menu
r12913 // Edit Notebook metadata
Notebook.prototype.edit_metadata = function () {
var that = this;
IPython.dialog.edit_metadata(this.metadata, function (md) {
that.metadata = md;
}, 'Notebook');
};
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.
*
* @method get_cell_elements
* @return {jQuery} A selector of all cell elements
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_cell_elements = function () {
MinRK
only put the notebook in a container...
r10909 return this.container.children("div.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.
*
* @method get_cell_element
* @param {Number} index An index of a cell to select
* @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.
*
* @method get_msg_cell
* @param {String} msg_id A message UUID
* @return {Cell} Cell or null if no cell was found.
*/
Notebook.prototype.get_msg_cell = function (msg_id) {
Jonathan Frederic
Simplify get_msg_cell function of notebook.js
r14833 return IPython.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.
*
* @method ncells
* @return {Number} The number of cells in this notebook
*/
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.
*
* @method get_cells
* @return {Array} This notebook's Cell objects
*/
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // 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 Notebook.prototype.get_cells = function () {
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 /**
* Get a Cell object from this notebook.
*
* @method get_cell
* @param {Number} index An index of a cell to retrieve
* @return {Cell} A particular cell
*/
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.
*
* @method get_next_cell
* @param {Cell} cell The provided cell
* @return {Cell} The next cell
*/
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.
*
* @method get_prev_cell
* @param {Cell} cell The provided cell
* @return {Cell} The previous cell
*/
Brian Granger
Refactoring of the notebooks cell management....
r5945 Notebook.prototype.get_prev_cell = function (cell) {
David Wyde
Add YUIDoc in notebook.js.
r10033 // TODO: off-by-one
// nb.get_prev_cell(nb.get_cell(1)) is null
Brian Granger
Refactoring of the notebooks cell management....
r5945 var result = null;
var index = this.find_cell_index(cell);
if (index !== null && index > 1) {
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.
*
* @method find_cell_index
* @param {Cell} cell The provided cell
* @return {Number} The cell's numeric index
*/
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 /**
* Get a given index , or the selected index if none is provided.
*
* @method index_or_selected
* @param {Number} index A cell's index
* @return {Number} The given index, or selected index if none is provided.
*/
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.
* @method get_selected_cell
* @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.
*
* @method is_valid_cell_index
* @param {Number} index A cell index
* @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.
* @method get_selected_index
* @return {Number} The selected cell's numeric index
*/
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.
*
* @method select
* @param {Number} index A cell's index
* @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) {
Jonathan Frederic
Fixed lots of bugs...
r15493 // Put the cell in command mode and unselect it.
this.get_cell(sindex).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') {
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
{'cell_type':cell.cell_type,level:cell.level}
);
Brian Granger
Heading/plaintext cells now wired up to toolbar UI.
r6028 } else {
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
{'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.
*
* @method select_next
* @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.
*
* @method select_prev
* @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
Fixed lots of bugs...
r15493 Notebook.prototype.get_edit_index = function (ignore_index) {
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
Fixed lots of bugs...
r15493 if (ignore_index===undefined || ignore_index!==index) {
result = index;
}
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 });
return result;
};
Brian E. Granger
More work on the dual mode UX.
r14015 Notebook.prototype.command_mode = function () {
Jonathan Frederic
Fixed lots of bugs...
r15493
// Make sure there isn't an edit mode cell lingering around.
var cell = this.get_cell(this.get_edit_index());
if (cell) {
cell.command_mode();
}
// Notify the keyboard manager if this is a change of mode for the
// notebook as a whole.
Brian E. Granger
More work on the dual mode UX.
r14015 if (this.mode !== 'command') {
Brian E. Granger
Lots of updates and changes....
r14021 this.mode = 'command';
Jonathan Frederic
Fixed lots of bugs...
r15493 $([IPython.events]).trigger('command_mode.Notebook');
Brian E. Granger
Lots of updates and changes....
r14021 IPython.keyboard_manager.command_mode();
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
More work on the dual mode UX.
r14015 };
Jonathan Frederic
Fixed lots of bugs...
r15493 Notebook.prototype.edit_mode = function (index) {
// Either use specified index or selected cell's index.
// Must explictly check for undefined CBool(0) = false.
Jonathan Frederic
Post in person review...
r15497 var focus_editor = false;
Jonathan Frederic
Fixed lots of bugs...
r15493 if (index===undefined) {
index = this.get_selected_index();
Jonathan Frederic
Post in person review...
r15497 focus_editor = true;
} else {
this.select(index);
Jonathan Frederic
Fixed lots of bugs...
r15493 }
// Make sure the cell exists.
Jonathan Frederic
Post in person review...
r15497 var cell = this.get_cell(index);
Jonathan Frederic
Fixed lots of bugs...
r15493 if (cell === null) { return; }
// Set the cell to edit mode and notify the keyboard manager if this
// is a change of mode for the notebook as a whole.
Jonathan Frederic
Post in person review...
r15497 cell.edit_mode(focus_editor);
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 if (this.mode !== 'edit') {
Brian E. Granger
Lots of updates and changes....
r14021 this.mode = 'edit';
Jonathan Frederic
Fixed lots of bugs...
r15493 $([IPython.events]).trigger('edit_mode.Notebook');
Brian E. Granger
Adding keyboard manager logic....
r14020 IPython.keyboard_manager.edit_mode();
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
More work on the dual mode UX.
r14015 };
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
Jonathan Frederic
Post in person review...
r15497 Notebook.prototype.handle_cell_text_focus = function (cell) {
console.log('notebook.handle_cell_text_focus', cell);
this.edit_mode(this.find_cell_index(cell));
Jonathan Frederic
Fixed lots of bugs...
r15493 };
Jonathan Frederic
Post in person review...
r15497 Notebook.prototype.handle_cell_text_blur = function (cell) {
// In Firefox the focus event is called before the blur event. In
// other words, two cells elements may be focused at any given time.
// This has been witnessed on Win7 x64 w/ FF 25&26.
console.log('notebook.handle_cell_text_blur', cell);
Jonathan Frederic
Fixed lots of bugs...
r15493
Jonathan Frederic
Added cell unfocus event canceller API
r15495 // Check if this unfocus event is legit.
Jonathan Frederic
s/unfocus/blur
r15498 if (!this.should_cancel_blur(cell)) {
Jonathan Frederic
Post in person review...
r15497 this.command_mode();
Jonathan Frederic
Fixed lots of bugs...
r15493 }
};
Jonathan Frederic
s/unfocus/blur
r15498 Notebook.prototype.should_cancel_blur = function (cell) {
Jonathan Frederic
Added cell unfocus event canceller API
r15495 // Determine whether or not the unfocus event should be aknowledged.
// If the tooltip is visible, ignore the unfocus.
var tooltip_visible = IPython.tooltip && IPython.tooltip.is_visible();
if (tooltip_visible) { return true; }
Jonathan Frederic
s/unfocus/blur
r15498 // Check the cell's should_cancel_blur method.
return (cell.should_cancel_blur !== undefined && cell.should_cancel_blur());
Jonathan Frederic
Added cell unfocus event canceller API
r15495 };
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.
*
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 * @method move_cell_up
* @param [index] {integer} cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Notebook} This notebook
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 **/
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 /**
* Move given (or selected) cell down and select it
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 * @method move_cell_down
* @param [index] {integer} cell index
David Wyde
Add YUIDoc in notebook.js.
r10033 * @return {Notebook} This notebook
Matthias BUSSONNIER
fix i/index in move up/down and == -> ===
r9788 **/
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 /**
* Delete a cell from the notebook.
*
* @method delete_cell
* @param [index] A cell's numeric index
* @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);
David Warde-Farley
Add a simple 'undo' for cell deletion....
r8691 var cell = this.get_selected_cell();
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 }
MinRK
add create.Cell and delete.Cell js events...
r11214 $([IPython.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.
*
* @method undelete
*/
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.
*
* Similar to insert_above, but index parameter is mandatory
*
* Index will be brought back into the accissible range [0,n]
*
David Wyde
Add YUIDoc in notebook.js.
r10033 * @method insert_cell_at_index
David Wyde
Remove references to HTMLCell (dead code).
r10375 * @param type {string} in ['code','markdown','heading']
Bussonnier Matthias
abstract, cleanup and document...
r9677 * @param [index] {int} a valid index where to inser cell
Matthias BUSSONNIER
refactor cellc
r9550 *
Bussonnier Matthias
abstract, cleanup and document...
r9677 * @return cell {cell|null} created cell or null
Matthias BUSSONNIER
refactor cellc
r9550 **/
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
holy crap, semicolons
r15236 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;
Matthias BUSSONNIER
refactor cellc
r9550
Matthias BUSSONNIER
fix one more == to ===
r9789 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
Brian Granger
Refactoring of the notebooks cell management....
r5945 if (type === 'code') {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 cell = new IPython.CodeCell(this.kernel);
Brian Granger
Refactoring of the notebooks cell management....
r5945 cell.set_input_prompt();
} else if (type === 'markdown') {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 cell = new IPython.MarkdownCell();
MinRK
rename plaintext cell -> raw cell
r6248 } else if (type === 'raw') {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 cell = new IPython.RawCell();
Brian Granger
Finishing first draft of RST and heading cells.
r6019 } else if (type === 'heading') {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 cell = new IPython.HeadingCell();
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();
MinRK
add create.Cell and delete.Cell js events...
r11214 $([IPython.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.
*
David Wyde
Add YUIDoc in notebook.js.
r10033 * @method _insert_element_at_index
Bussonnier Matthias
abstract, cleanup and document...
r9677 * @param element {dom element} a cell element
* @param [index] {int} a valid index where to inser cell
* @private
*
* return true if everything whent fine.
**/
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.
*
* default index value is the one of currently selected cell
*
David Wyde
Add YUIDoc in notebook.js.
r10033 * @method insert_cell_above
Matthias BUSSONNIER
refactor cellc
r9550 * @param type {string} cell type
* @param [index] {integer}
*
* @return handle to created cell or null
**/
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
* of notebook if index greater thatn number of cell
*
* default index value is the one of currently selected cell
*
* @method insert_cell_below
* @param type {string} cell type
* @param [index] {integer}
*
* @return handle to created cell or null
*
**/
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
*
* @method insert_cell_at_bottom
David Wyde
Add YUIDoc in notebook.js.
r10033 * @param {String} type cell type
Bussonnier Matthias
abstract, cleanup and document...
r9677 *
* @return the added 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.
*
* @method to_code
* @param {Number} [index] A cell's index
*/
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)) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
if (!(source_cell instanceof IPython.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 = '';
}
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();
Brian Granger
Refactoring of the notebooks cell management....
r5945 source_element.remove();
Brian E. Granger
Binding to notebook div not document.
r14018 this.select(i);
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.
*
* @method to_markdown
* @param {Number} [index] A cell's index
*/
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)) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
if (!(source_cell instanceof IPython.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();
if (text === source_cell.placeholder) {
Brian Granger
Lots of small notebook improvements....
r5946 text = '';
MinRK
holy crap, semicolons
r15236 }
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();
Brian Granger
A first go at RST cell support in the notebook.
r6017 source_element.remove();
Brian E. Granger
More work on the dual mode UX.
r14015 this.select(i);
Brian E. Granger
Don't enter edit mode when changing cell type and preserve renderd.
r14943 if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) {
target_cell.render();
}
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.
*
* @method to_raw
* @param {Number} [index] A cell's index
*/
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 source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
var target_cell = null;
MinRK
rename plaintext cell -> raw cell
r6248 if (!(source_cell instanceof IPython.RawCell)) {
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 }
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();
Brian Granger
A first go at RST cell support in the notebook.
r6017 source_element.remove();
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 this.select(i);
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 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Turn a cell into a heading cell.
*
* @method to_heading
* @param {Number} [index] A cell's index
* @param {Number} [level] A heading level (e.g., 1 becomes &lt;h1&gt;)
*/
Brian Granger
Finishing first draft of RST and heading cells.
r6019 Notebook.prototype.to_heading = function (index, level) {
level = level || 1;
var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i)) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
var target_cell = null;
if (source_cell instanceof IPython.HeadingCell) {
source_cell.set_level(level);
} else {
target_cell = this.insert_cell_below('heading',i);
var text = source_cell.get_text();
if (text === source_cell.placeholder) {
text = '';
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 // We must show the editor before setting its contents
Brian Granger
Finishing first draft of RST and heading cells.
r6019 target_cell.set_level(level);
Brian E. Granger
Adding new logic to cells.
r14014 target_cell.unrender();
Brian Granger
Finishing first draft of RST and heading cells.
r6019 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();
Brian Granger
Finishing first draft of RST and heading cells.
r6019 source_element.remove();
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 this.select(i);
Brian E. Granger
Don't enter edit mode when changing cell type and preserve renderd.
r14943 if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) {
target_cell.render();
}
MinRK
holy crap, semicolons
r15236 }
Brian E. Granger
Changing a heading cell level should enter edit mode and set dirty
r14031 this.set_dirty(true);
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
{'cell_type':'heading',level:level}
);
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 /**
* Enable UI elements for pasting cells.
*
* @method enable_paste
*/
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 /**
* Disable UI elements for pasting cells.
*
* @method disable_paste
*/
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.
*
* @method cut_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.
*
* @method copy_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();
this.enable_paste();
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Replace the selected cell with a cell in the clipboard.
*
* @method paste_cell_replace
*/
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.
*
* @method paste_cell_above
*/
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.
*
* @method paste_cell_below
*/
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 /**
* Split the selected cell into two, at the cursor.
*
* @method split_cell
*/
Brian Granger
More of the initial split cell capability.
r5897 Notebook.prototype.split_cell = function () {
Brian E. Granger
Cell splitting merging works with RawCell now.
r14061 var mdc = IPython.MarkdownCell;
var rc = IPython.RawCell;
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();
Brian Granger
Lots of small notebook improvements....
r5946 if (cell instanceof IPython.CodeCell) {
Brian E. Granger
Ongoing work on cell splitting.
r14057 // In this case the operations keep the notebook in its existing mode
// so we don't need to do any post-op mode changes.
MinRK
split adds new cell above, rather than below...
r12956 cell.set_text(textb);
var new_cell = this.insert_cell_above('code');
new_cell.set_text(texta);
Brian E. Granger
Reordering conditional.
r14086 } else if ((cell instanceof mdc && !cell.rendered) || (cell instanceof rc)) {
Brian E. Granger
Cleanup of cell splitting.
r14060 // We know cell is !rendered so we can use set_text.
MinRK
split adds new cell above, rather than below...
r12956 cell.set_text(textb);
Brian E. Granger
Cell splitting merging works with RawCell now.
r14061 var new_cell = this.insert_cell_above(cell.cell_type);
Brian E. Granger
Cleanup of cell splitting.
r14060 // Unrender the new cell so we can call set_text.
Brian E. Granger
Ongoing work on cell splitting.
r14057 new_cell.unrender();
Brian E. Granger
Cleanup of cell splitting.
r14060 new_cell.set_text(texta);
David Wyde
Remove references to HTMLCell (dead code).
r10375 }
MinRK
holy crap, semicolons
r15236 }
Brian Granger
More of the initial split cell capability.
r5897 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Combine the selected cell into the cell above it.
*
* @method merge_cell_above
*/
Brian Granger
Cell splitting and merging is done!
r5898 Notebook.prototype.merge_cell_above = function () {
Brian E. Granger
Cell splitting merging works with RawCell now.
r14061 var mdc = IPython.MarkdownCell;
var rc = IPython.RawCell;
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();
Brian Granger
Lots of small notebook improvements....
r5946 if (cell instanceof IPython.CodeCell) {
cell.set_text(upper_text+'\n'+text);
Brian E. Granger
Cell splitting merging works with RawCell now.
r14061 } else if ((cell instanceof mdc) || (cell instanceof rc)) {
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 /**
* Combine the selected cell into the cell below it.
*
* @method merge_cell_below
*/
Brian Granger
Cell splitting and merging is done!
r5898 Notebook.prototype.merge_cell_below = function () {
Brian E. Granger
Cell splitting merging works with RawCell now.
r14061 var mdc = IPython.MarkdownCell;
var rc = IPython.RawCell;
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();
Brian Granger
Lots of small notebook improvements....
r5946 if (cell instanceof IPython.CodeCell) {
cell.set_text(text+'\n'+lower_text);
Brian E. Granger
Cell splitting merging works with RawCell now.
r14061 } else if ((cell instanceof mdc) || (cell instanceof rc)) {
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.
*
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * @method collapse_output
David Wyde
Add YUIDoc in notebook.js.
r10033 * @param {Number} index A cell's numeric index
*/
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);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
cell.collapse_output();
this.set_dirty(true);
}
};
/**
* Hide each code cell's output area.
*
* @method collapse_all_output
*/
Notebook.prototype.collapse_all_output = function () {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 $.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
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.
*
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * @method expand_output
David Wyde
Add YUIDoc in notebook.js.
r10033 * @param {Number} index A cell's numeric index
*/
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);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
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 * @method expand_all_output
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 () {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 $.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
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 *
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * @method clear_output
David Wyde
Add YUIDoc in notebook.js.
r10033 * @param {Number} index A cell's numeric index
*/
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);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
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 * @method clear_all_output
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 () {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 $.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
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.
*
* @method scroll_output
* @param {Number} index A cell's numeric index
*/
Notebook.prototype.scroll_output = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_cell(i);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
cell.scroll_output();
this.set_dirty(true);
}
};
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Expand each code cell's output area, and add a scrollbar for long output.
*
* @method scroll_all_output
*/
MinRK
third attempt at scrolled long output...
r7362 Notebook.prototype.scroll_all_output = function () {
Brian E. Granger
Converting loops in *_all_output to $.map().
r14870 $.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
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 };
Brian E. Granger
Cleaning up output management in code and menus.
r14867 /** Toggle whether a cell's output is collapsed or expanded.
David Wyde
Add YUIDoc in notebook.js.
r10033 *
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * @method toggle_output
* @param {Number} index A cell's numeric 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);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
cell.toggle_output();
this.set_dirty(true);
}
MinRK
third attempt at scrolled long output...
r7362 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
Brian E. Granger
Simplified Cell menu items related to output.
r14871 * Hide/show the output of all cells.
*
* @method toggle_all_output
*/
Notebook.prototype.toggle_all_output = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
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 *
Brian E. Granger
Cleaning up output management in code and menus.
r14867 * @method toggle_output_scroll
* @param {Number} index A cell's numeric 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);
if (cell !== null && (cell instanceof IPython.CodeCell)) {
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.
*
* @method toggle_all_output_scrolling
*/
Notebook.prototype.toggle_all_output_scroll = function () {
$.map(this.get_cells(), function (cell, i) {
if (cell instanceof IPython.CodeCell) {
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.
*
* @method cell_toggle_line_numbers
*/
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 };
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 *
Zachary Sailer
manual rebase static/notebook/js files
r12986 * @method start_session
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Zachary Sailer
manual rebase static/notebook/js files
r12986 Notebook.prototype.start_session = function () {
MinRK
various unicode fixes...
r15234 this.session = new IPython.Session(this, this.options);
MinRK
Cells shouldn't know about Sessions
r13133 this.session.start($.proxy(this._session_started, this));
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
* comm manager to the widget manager
Zachary Sailer
Fixed bug when linking kernel to new code cells
r12999 *
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
Cells shouldn't know about Sessions
r13133 Notebook.prototype._session_started = function(){
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);
if (cell instanceof IPython.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 };
Zachary Sailer
Fixed bug when linking kernel to new code cells
r12999
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Prompt the user to restart the IPython kernel.
*
* @method restart_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;
MinRK
bootstrap dialogs
r10895 IPython.dialog.modal({
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() {
Zachary Sailer
fix restart/interrupt kernel buttons
r12994 that.session.restart_kernel();
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 * @method execute_cell
David Wyde
Add YUIDoc in notebook.js.
r10033 */
Brian E. Granger
Renaming execute methods.
r14085 Notebook.prototype.execute_cell = function () {
Brian E. Granger
More work on the dual mode UX.
r14015 // mode = shift, ctrl, alt
Brian E. Granger
Renaming execute methods.
r14085 var cell = this.get_selected_cell();
var cell_index = this.find_cell_index(cell);
cell.execute();
Brian E. Granger
Adding sorting and better layout to the KB shortcuts.
r14093 cell.focus_cell();
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.
*
* @method execute_cell_and_insert_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
Semi working version of basic dual mode UX....
r14016 this.insert_cell_below('code');
Jonathan Frederic
Post in person review...
r15497 this.edit_mode(cell_index+1);
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
Semi working version of basic dual mode UX....
r14016
Brian E. Granger
alt+enter should always insert below
r14944 this.insert_cell_below('code');
Jonathan Frederic
Post in person review...
r15497 this.edit_mode(cell_index+1);
Brian E. Granger
Renaming execute methods.
r14085 this.set_dirty(true);
};
/**
* Execute or render cell outputs and select the next cell.
*
* @method execute_cell_and_select_below
*/
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)) {
this.insert_cell_below('code');
Jonathan Frederic
Post in person review...
r15497 this.edit_mode(cell_index+1);
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
this.select(cell_index+1);
this.get_cell(cell_index+1).focus_cell();
Jonathan Frederic
Fixed lots of bugs...
r15493 this.command_mode();
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.
*
* @method execute_cells_below
*/
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.
*
* @method execute_cells_above
*/
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.
*
* @method 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.
*
* @method execute_cell_range
* @param {Number} start Index of the first cell to execute (inclusive)
* @param {Number} end Index of the last cell to execute (exclusive)
*/
Paul Ivanov
fine-grained notebook 'run' controls, closes #2521...
r8606 Notebook.prototype.execute_cell_range = function (start, end) {
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.
*
* @method get_notebook_name
MinRK
various unicode fixes...
r15234 * @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.
*
* @method set_notebook_name
* @param {String} name A new name for this notebook
*/
Brian Granger
Major refactoring of saving, notification....
r6047 Notebook.prototype.set_notebook_name = function (name) {
this.notebook_name = name;
};
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Check that a notebook's name is valid.
*
* @method test_notebook_name
* @param {String} nbname A name for this notebook
* @return {Boolean} True if the name is valid, false if invalid
*/
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).
*
* This currently handles one worksheet: others are deleted.
*
* @method fromJSON
* @param {Object} data JSON representation of a notebook
*/
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.fromJSON = function (data) {
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.
this.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;
Brian E. Granger
Massive work on the notebook document format....
r4484 // Only handle 1 worksheet for now.
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 var worksheet = content.worksheets[0];
Brian E. Granger
Massive work on the notebook document format....
r4484 if (worksheet !== undefined) {
MinRK
add empty metadata field on cells/worksheets...
r7523 if (worksheet.metadata) {
this.worksheet_metadata = worksheet.metadata;
}
Brian E. Granger
Massive work on the notebook document format....
r4484 var new_cells = worksheet.cells;
ncells = new_cells.length;
var cell_data = null;
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var new_cell = null;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 for (i=0; i<ncells; i++) {
Brian E. Granger
Massive work on the notebook document format....
r4484 cell_data = new_cells[i];
MinRK
add VERSIONHACK markers for never-released plaintext handling
r6477 // VERSIONHACK: plaintext -> raw
// handle never-released plaintext name for raw cells
MinRK
interpret 'plaintext' cells with their new name 'raw'
r6255 if (cell_data.cell_type === 'plaintext'){
cell_data.cell_type = 'raw';
}
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 new_cell = this.insert_cell_at_index(cell_data.cell_type, i);
Brian Granger
Refactoring of the notebooks cell management....
r5945 new_cell.fromJSON(cell_data);
MinRK
holy crap, semicolons
r15236 }
}
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 if (content.worksheets.length > 1) {
MinRK
bootstrap dialogs
r10895 IPython.dialog.modal({
title : "Multiple worksheets",
body : "This notebook has " + data.worksheets.length + " worksheets, " +
"but this version of IPython can only handle the first. " +
"If you save this notebook, worksheets after the first will be lost.",
MinRK
add future-warning about multiple notebooks
r7610 buttons : {
MinRK
bootstrap dialogs
r10895 OK : {
class : "btn-danger"
MinRK
add future-warning about multiple notebooks
r7610 }
MinRK
bootstrap dialogs
r10895 }
MinRK
add future-warning about multiple notebooks
r7610 });
}
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.
*
* @method toJSON
* @return {Object} A JSON-friendly representation of this notebook.
*/
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.toJSON = function () {
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);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 for (var i=0; i<ncells; i++) {
cell_array[i] = cells[i].toJSON();
MinRK
holy crap, semicolons
r15236 }
Brian Granger
Adding missing var statements in notebook.js.
r7179 var data = {
Brian E. Granger
Massive work on the notebook document format....
r4484 // Only handle 1 worksheet for now.
MinRK
add empty metadata field on cells/worksheets...
r7523 worksheets : [{
cells: cell_array,
metadata: this.worksheet_metadata
}],
Brian E. Granger
Implemented metadata for notebook format.
r4637 metadata : this.metadata
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 /**
MinRK
add autosave timer...
r10505 * Start an autosave timer, for periodically saving the notebook.
*
MinRK
s/autosave_notebook/set_autosave_interval/
r10508 * @method set_autosave_interval
MinRK
add autosave timer...
r10505 * @param {Integer} interval the autosave interval in milliseconds
*/
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);
}
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);
$([IPython.events]).trigger("autosave_enabled.Notebook", interval);
} else {
this.autosave_timer = null;
$([IPython.events]).trigger("autosave_disabled.Notebook");
MinRK
holy crap, semicolons
r15236 }
MinRK
add autosave timer...
r10505 };
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Save this notebook on the server.
*
* @method save_notebook
*/
MinRK
save before download-as...
r13076 Notebook.prototype.save_notebook = function (extra_settings) {
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 // Create a JSON model to be sent to the server.
MinRK
fix dashboard upload
r13072 var model = {};
model.name = this.notebook_name;
model.path = this.notebook_path;
model.content = this.toJSON();
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 model.content.nbformat = this.nbformat;
model.content.nbformat_minor = this.nbformat_minor;
MinRK
add autosave timer...
r10505 // time the ajax call for autosave tuning purposes.
var start = new Date().getTime();
Brian Granger
Fixing broken notebook saves.
r5958 // We do the call with settings so we can set cache to false.
var settings = {
processData : false,
cache : false,
type : "PUT",
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 data : JSON.stringify(model),
Brian Granger
Fixing broken notebook saves.
r5958 headers : {'Content-Type': 'application/json'},
MinRK
add autosave timer...
r10505 success : $.proxy(this.save_notebook_success, this, start),
error : $.proxy(this.save_notebook_error, this)
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
MinRK
save before download-as...
r13076 if (extra_settings) {
for (var key in extra_settings) {
settings[key] = extra_settings[key];
}
}
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('notebook_saving.Notebook');
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
make sure to encode URL components for API requests...
r13693 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name
);
Brian Granger
Fixing broken notebook saves.
r5958 $.ajax(url, settings);
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.
*
* @method save_notebook_success
MinRK
add autosave timer...
r10505 * @param {Integer} start the time when the save request started
David Wyde
Add YUIDoc in notebook.js.
r10033 * @param {Object} data JSON representation of a notebook
* @param {String} status Description of response status
* @param {jqXHR} xhr jQuery Ajax object
*/
MinRK
add autosave timer...
r10505 Notebook.prototype.save_notebook_success = function (start, data, status, xhr) {
MinRK
setting the notebook dirty flag is now an event...
r10781 this.set_dirty(false);
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.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 /**
MinRK
add autosave timer...
r10505 * update the autosave interval based on how long the last save took
*
* @method _update_autosave_interval
* @param {Integer} timestamp when the save request started
*/
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
if (interval != this.autosave_interval) {
MinRK
s/autosave_notebook/set_autosave_interval/
r10508 this.set_autosave_interval(interval);
MinRK
add autosave timer...
r10505 }
}
};
/**
David Wyde
Add YUIDoc in notebook.js.
r10033 * Failure callback for saving a notebook.
*
* @method save_notebook_error
* @param {jqXHR} xhr jQuery Ajax object
* @param {String} status Description of response status
MinRK
uniformity in ajax error handler arguments...
r13858 * @param {String} error HTTP error message
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
uniformity in ajax error handler arguments...
r13858 Notebook.prototype.save_notebook_error = function (xhr, status, error) {
$([IPython.events]).trigger('notebook_save_failed.Notebook', [xhr, status, error]);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 Notebook.prototype.new_notebook = function(){
MinRK
make sure to encode URL components for API requests...
r13693 var path = this.notebook_path;
MinRK
s/base_project_url/base_url/...
r15238 var base_url = this.base_url;
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 var settings = {
processData : false,
cache : false,
type : "POST",
dataType : "json",
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 async : false,
success : function (data, status, xhr){
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 var notebook_name = data.name;
MinRK
add utils.url_path_join...
r13063 window.open(
MinRK
make sure to encode URL components for API requests...
r13693 utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 base_url,
MinRK
add utils.url_path_join...
r13063 'notebooks',
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 path,
MinRK
add utils.url_path_join...
r13063 notebook_name
),
'_blank'
);
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 }
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 };
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 base_url,
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 'api/notebooks',
path
);
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 $.ajax(url,settings);
};
Zachary Sailer
handle path separators with os.sep and add tests...
r13032
Zachary Sailer
Change new/copy URLS to POST requests
r13017 Notebook.prototype.copy_notebook = function(){
MinRK
make sure to encode URL components for API requests...
r13693 var path = this.notebook_path;
MinRK
s/base_project_url/base_url/...
r15238 var base_url = this.base_url;
Zachary Sailer
Change new/copy URLS to POST requests
r13017 var settings = {
processData : false,
cache : false,
type : "POST",
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 dataType : "json",
MinRK
update copy API in js
r13139 data : JSON.stringify({copy_from : this.notebook_name}),
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 async : false,
success : function (data, status, xhr) {
MinRK
make sure to encode URL components for API requests...
r13693 window.open(utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 base_url,
MinRK
add utils.url_path_join...
r13063 'notebooks',
MinRK
update copy API in js
r13139 data.path,
data.name
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 ), '_blank');
}
Zachary Sailer
Change new/copy URLS to POST requests
r13017 };
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 base_url,
MinRK
update upload and copy...
r13074 'api/notebooks',
MinRK
update copy API in js
r13139 path
MinRK
add utils.url_path_join...
r13063 );
Zachary Sailer
Change new/copy URLS to POST requests
r13017 $.ajax(url,settings);
};
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997
MinRK
Cells shouldn't know about Sessions
r13133 Notebook.prototype.rename = function (nbname) {
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 var that = this;
MinRK
only add .ipynb if extension is not included...
r15237 if (!nbname.match(/\.ipynb$/)) {
nbname = nbname + ".ipynb";
}
var data = {name: nbname};
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 var settings = {
processData : false,
cache : false,
type : "PATCH",
MinRK
Cells shouldn't know about Sessions
r13133 data : JSON.stringify(data),
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 dataType: "json",
headers : {'Content-Type': 'application/json'},
Zachary Sailer
Renaming fixed
r13018 success : $.proxy(that.rename_success, this),
error : $.proxy(that.rename_error, this)
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 };
MinRK
Cells shouldn't know about Sessions
r13133 $([IPython.events]).trigger('rename_notebook.Notebook', data);
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
make sure to encode URL components for API requests...
r13693 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name
);
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 $.ajax(url, settings);
};
Brian E. Granger
Fixing issues with js tests....
r14965
Brian E. Granger
Notebook.delete should take no args.
r14978 Notebook.prototype.delete = function () {
Brian E. Granger
Fixing issues with js tests....
r14965 var that = this;
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType: "json",
};
var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
Brian E. Granger
Fixing issues with js tests....
r14965 'api/notebooks',
this.notebook_path,
this.notebook_name
);
$.ajax(url, settings);
};
MinRK
expose notebook checkpoints in html/js...
r10501
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 Notebook.prototype.rename_success = function (json, status, xhr) {
MinRK
holy crap, semicolons
r15236 var name = this.notebook_name = json.name;
MinRK
make sure to encode URL components for API requests...
r13693 var path = json.path;
MinRK
Cells shouldn't know about Sessions
r13133 this.session.rename_notebook(name, path);
$([IPython.events]).trigger('notebook_renamed.Notebook', json);
MinRK
holy crap, semicolons
r15236 };
Zachary Sailer
Renaming fixed
r13018
MinRK
uniformity in ajax error handler arguments...
r13858 Notebook.prototype.rename_error = function (xhr, status, error) {
Zachary Sailer
Renaming fixed
r13018 var that = this;
var dialog = $('<div/>').append(
$("<p/>").addClass("rename-message")
Matthias BUSSONNIER
some $.html( -> $.text(...
r14634 .text('This notebook name already exists.')
MinRK
holy crap, semicolons
r15236 );
MinRK
uniformity in ajax error handler arguments...
r13858 $([IPython.events]).trigger('notebook_rename_failed.Notebook', [xhr, status, error]);
Zachary Sailer
Renaming fixed
r13018 IPython.dialog.modal({
title: "Notebook Rename Error!",
body: dialog,
buttons : {
"Cancel": {},
"OK": {
class: "btn-primary",
click: function () {
IPython.save_widget.rename_notebook();
}}
},
open : function (event, ui) {
var that = $(this);
// Upon ENTER, click the OK button.
that.find('input[type="text"]').keydown(function (event, ui) {
if (event.which === utils.keycodes.ENTER) {
that.find('.btn-primary').first().click();
}
});
that.find('input[type="text"]').focus();
}
});
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.
*
* @method load_notebook
MinRK
fixup bad rebase
r13102 * @param {String} notebook_name and path A notebook to load
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
add utils.url_path_join...
r13063 Notebook.prototype.load_notebook = function (notebook_name, notebook_path) {
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var that = this;
MinRK
add utils.url_path_join...
r13063 this.notebook_name = notebook_name;
this.notebook_path = notebook_path;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // We do the call with settings so we can set cache to false.
var settings = {
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 processData : false,
cache : false,
type : "GET",
dataType : "json",
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 success : $.proxy(this.load_notebook_success,this),
error : $.proxy(this.load_notebook_error,this),
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('notebook_loading.Notebook');
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
make sure to encode URL components for API requests...
r13693 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name
);
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 $.ajax(url, settings);
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.
*
* @method load_notebook_success
* @param {Object} data JSON representation of a notebook
* @param {String} status Description of response status
* @param {jqXHR} xhr jQuery Ajax object
*/
Brian Granger
Major refactoring of saving, notification....
r6047 Notebook.prototype.load_notebook_success = function (data, status, xhr) {
Brian E. Granger
Massive work on the notebook document format....
r4484 this.fromJSON(data);
Jonathan Frederic
DEBUG...
r15492 console.log('load notebook success');
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
Post in person review...
r15497 this.edit_mode(0);
Brian E. Granger
More work on the dual mode UX.
r14015 } else {
this.select(0);
this.command_mode();
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();
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 if (data.orig_nbformat !== undefined && data.nbformat !== data.orig_nbformat) {
MinRK
bootstrap dialogs
r10895 var msg = "This notebook has been converted from an older " +
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 "notebook format (v"+data.orig_nbformat+") to the current notebook " +
"format (v"+data.nbformat+"). The next time you save this notebook, the " +
MinRK
bootstrap dialogs
r10895 "newer notebook format will be used and older versions of IPython " +
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 "may not be able to read it. To keep the older version, close the " +
"notebook without saving it.";
MinRK
bootstrap dialogs
r10895 IPython.dialog.modal({
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 });
MinRK
add dialog when loading newer minor-version notebooks
r7546 } else if (data.orig_nbformat_minor !== undefined && data.nbformat_minor !== data.orig_nbformat_minor) {
var that = this;
var orig_vs = 'v' + data.nbformat + '.' + data.orig_nbformat_minor;
var this_vs = 'v' + data.nbformat + '.' + this.nbformat_minor;
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var msg = "This notebook is version " + orig_vs + ", but we only fully support up to " +
MinRK
add dialog when loading newer minor-version notebooks
r7546 this_vs + ". You can still work with this notebook, but some features " +
MinRK
holy crap, semicolons
r15236 "introduced in later notebook versions may not be available.";
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839
MinRK
bootstrap dialogs
r10895 IPython.dialog.modal({
title : "Newer Notebook",
body : msg,
MinRK
add dialog when loading newer minor-version notebooks
r7546 buttons : {
MinRK
bootstrap dialogs
r10895 OK : {
class : "btn-danger"
MinRK
add dialog when loading newer minor-version notebooks
r7546 }
MinRK
bootstrap dialogs
r10895 }
MinRK
add dialog when loading newer minor-version notebooks
r7546 });
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 }
MinRK
add Revert to the menu bar
r10503
Zachary Sailer
manual rebase static/notebook/js files
r12986 // Create the session after the notebook is completely loaded to prevent
Brian Granger
Fixed order of notebook loading and kernel starting....
r7197 // code execution upon loading, which is a security risk.
MinRK
holy crap, semicolons
r15236 if (this.session === null) {
Zachary Sailer
handle path separators with os.sep and add tests...
r13032 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) {
IPython.CellToolbar.global_show();
IPython.CellToolbar.activate_preset(this.metadata.celltoolbar);
}
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('notebook_loaded.Notebook');
Brian E. Granger
Massive work on the notebook document format....
r4484 };
David Wyde
Add YUIDoc in notebook.js.
r10033 /**
* Failure callback for loading a notebook from the server.
*
* @method load_notebook_error
* @param {jqXHR} xhr jQuery Ajax object
MinRK
uniformity in ajax error handler arguments...
r13858 * @param {String} status Description of response status
* @param {String} error HTTP error message
David Wyde
Add YUIDoc in notebook.js.
r10033 */
MinRK
uniformity in ajax error handler arguments...
r13858 Notebook.prototype.load_notebook_error = function (xhr, status, error) {
$([IPython.events]).trigger('notebook_load_failed.Notebook', [xhr, status, error]);
MinRK
holy crap, semicolons
r15236 var msg;
MinRK
better message when notebook format is not supported...
r11643 if (xhr.status === 400) {
MinRK
holy crap, semicolons
r15236 msg = error;
MinRK
better message when notebook format is not supported...
r11643 } else if (xhr.status === 500) {
MinRK
holy crap, semicolons
r15236 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 " +
"v" + this.nbformat + " or earlier.";
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 }
MinRK
better message when notebook format is not supported...
r11643 IPython.dialog.modal({
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
MinRK
expose notebook checkpoints in html/js...
r10501 /********************* checkpoint-related *********************/
/**
* Save the notebook then immediately create a checkpoint.
*
* @method save_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.
* for use as a callback from checkpoint creation.
*
* @method add_checkpoint
*/
Notebook.prototype.add_checkpoint = function (checkpoint) {
var found = false;
for (var i = 0; i < this.checkpoints.length; i++) {
var existing = this.checkpoints[i];
MinRK
use 'id' for checkpoint ID key...
r13122 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.
*
MinRK
minor checkpoint cleanup...
r12050 * @method list_checkpoints
MinRK
expose notebook checkpoints in html/js...
r10501 */
Notebook.prototype.list_checkpoints = function () {
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
make sure to encode URL components for API requests...
r13693 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name,
'checkpoints'
);
MinRK
expose notebook checkpoints in html/js...
r10501 $.get(url).done(
$.proxy(this.list_checkpoints_success, this)
).fail(
$.proxy(this.list_checkpoints_error, this)
);
};
/**
* Success callback for listing checkpoints.
*
* @method list_checkpoint_success
* @param {Object} data JSON representation of a checkpoint
* @param {String} status Description of response status
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.list_checkpoints_success = function (data, status, xhr) {
MinRK
holy crap, semicolons
r15236 data = $.parseJSON(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;
}
MinRK
restore checkpoints in a sub-list...
r10520 $([IPython.events]).trigger('checkpoints_listed.Notebook', [data]);
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Failure callback for listing a checkpoint.
*
* @method list_checkpoint_error
* @param {jqXHR} xhr jQuery Ajax object
* @param {String} status Description of response status
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.list_checkpoints_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('list_checkpoints_failed.Notebook');
};
/**
* Create a checkpoint of this notebook on the server from the most recent save.
*
* @method create_checkpoint
*/
Notebook.prototype.create_checkpoint = function () {
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
various unicode fixes...
r15234 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name,
'checkpoints'
);
MinRK
expose notebook checkpoints in html/js...
r10501 $.post(url).done(
$.proxy(this.create_checkpoint_success, this)
).fail(
$.proxy(this.create_checkpoint_error, this)
);
};
/**
* Success callback for creating a checkpoint.
*
* @method create_checkpoint_success
* @param {Object} data JSON representation of a checkpoint
* @param {String} status Description of response status
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.create_checkpoint_success = function (data, status, xhr) {
MinRK
holy crap, semicolons
r15236 data = $.parseJSON(data);
MinRK
minor checkpoint cleanup...
r12050 this.add_checkpoint(data);
MinRK
expose notebook checkpoints in html/js...
r10501 $([IPython.events]).trigger('checkpoint_created.Notebook', data);
};
/**
* Failure callback for creating a checkpoint.
*
* @method create_checkpoint_error
* @param {jqXHR} xhr jQuery Ajax object
* @param {String} status Description of response status
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.create_checkpoint_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('checkpoint_failed.Notebook');
};
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 );
MinRK
bootstrap dialogs
r10895 IPython.dialog.modal({
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.
*
* @method restore_checkpoint
* @param {String} checkpoint ID
*/
Notebook.prototype.restore_checkpoint = function (checkpoint) {
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
various unicode fixes...
r15234 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name,
'checkpoints',
checkpoint
);
MinRK
expose notebook checkpoints in html/js...
r10501 $.post(url).done(
$.proxy(this.restore_checkpoint_success, this)
).fail(
$.proxy(this.restore_checkpoint_error, this)
);
};
/**
* Success callback for restoring a notebook to a checkpoint.
*
* @method restore_checkpoint_success
* @param {Object} data (ignored, should be empty)
* @param {String} status Description of response status
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.restore_checkpoint_success = function (data, status, xhr) {
$([IPython.events]).trigger('checkpoint_restored.Notebook');
Zachary Sailer
manual rebase static/notebook/js files
r12986 this.load_notebook(this.notebook_name, this.notebook_path);
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Failure callback for restoring a notebook to a checkpoint.
*
* @method restore_checkpoint_error
* @param {jqXHR} xhr jQuery Ajax object
* @param {String} status Description of response status
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.restore_checkpoint_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('checkpoint_restore_failed.Notebook');
};
/**
* Delete a notebook checkpoint.
*
* @method delete_checkpoint
* @param {String} checkpoint ID
*/
Notebook.prototype.delete_checkpoint = function (checkpoint) {
Zachary Sailer
fixing path redirects, cleaning path logic
r12992 $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
MinRK
make sure to encode URL components for API requests...
r13693 var url = utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
MinRK
various unicode fixes...
r15234 this.notebook_path,
MinRK
add utils.url_path_join...
r13063 this.notebook_name,
'checkpoints',
checkpoint
);
MinRK
expose notebook checkpoints in html/js...
r10501 $.ajax(url, {
type: 'DELETE',
success: $.proxy(this.delete_checkpoint_success, this),
error: $.proxy(this.delete_notebook_error,this)
});
};
/**
* Success callback for deleting a notebook checkpoint
*
* @method delete_checkpoint_success
* @param {Object} data (ignored, should be empty)
* @param {String} status Description of response status
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.delete_checkpoint_success = function (data, status, xhr) {
$([IPython.events]).trigger('checkpoint_deleted.Notebook', data);
Zachary Sailer
manual rebase static/notebook/js files
r12986 this.load_notebook(this.notebook_name, this.notebook_path);
MinRK
expose notebook checkpoints in html/js...
r10501 };
/**
* Failure callback for deleting a notebook checkpoint.
*
* @method delete_checkpoint_error
* @param {jqXHR} xhr jQuery Ajax object
* @param {String} status Description of response status
* @param {String} error_msg HTTP error message
*/
Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) {
$([IPython.events]).trigger('checkpoint_delete_failed.Notebook');
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Notebook = Notebook;
Brian E. Granger
Further work updating JS URL scheme to use data-base-project-url.
r5108
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return IPython;
}(IPython));
Jonathan Frederic
Post in person review...
r15497