##// END OF EJS Templates
Save notebook as script using unicode file handle....
Save notebook as script using unicode file handle. Closes gh-1345

File last commit:

r6000:93bb469d merge
r6030:ddeaebcc
Show More
codecell.js
855 lines | 31.8 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
//============================================================================
// CodeCell
//============================================================================
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var IPython = (function (IPython) {
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var utils = IPython.utils;
var CodeCell = function (notebook) {
this.code_mirror = null;
MinRK
store nonexistent prompt number as null
r5814 this.input_prompt_number = null;
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 this.is_completing = false;
this.completion_cursor = null;
Brian E. Granger
Added saving and loading of output of all types.
r4497 this.outputs = [];
Brian E. Granger
Added collapsed field to the code cell.
r4533 this.collapsed = false;
MinRK
Cleanup some inappropriate javascript...
r5566 this.tooltip_timeout = null;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Cell.apply(this, arguments);
};
CodeCell.prototype = new IPython.Cell();
CodeCell.prototype.create_element = function () {
Brian E. Granger
Pager is working again.
r4361 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox');
Brian E. Granger
Better tabindex support.
r4629 cell.attr('tabindex','2');
Brian E. Granger
More work updating the notebook to use dynamics resizing.
r4360 var input = $('<div></div>').addClass('input hbox');
Brian E. Granger
Updating font-sizing to use the YUI protocol.
r4379 input.append($('<div/>').addClass('prompt input_prompt'));
Brian E. Granger
More work updating the notebook to use dynamics resizing.
r4360 var input_area = $('<div/>').addClass('input_area box-flex1');
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.code_mirror = CodeMirror(input_area.get(0), {
indentUnit : 4,
Brian E. Granger
Updating CodeMirror to v 2.12....
r4504 mode: 'python',
theme: 'ipython',
MinRK
add read-only view for notebooks...
r5200 readOnly: this.read_only,
Brian E. Granger
Fixing execution related things....
r4378 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
input.append(input_area);
Brian E. Granger
More work updating the notebook to use dynamics resizing.
r4360 var output = $('<div></div>').addClass('output vbox');
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 cell.append(input).append(output);
this.element = cell;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.collapse();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Matthias BUSSONNIER
tooltip on <tab>
r5398 //TODO, try to diminish the number of parameters.
MinRK
Cleanup some inappropriate javascript...
r5566 CodeCell.prototype.request_tooltip_after_time = function (pre_cursor,time){
var that = this;
Matthias BUSSONNIER
tooltip on <tab>
r5398 if (pre_cursor === "" || pre_cursor === "(" ) {
// don't do anything if line beggin with '(' or is empty
} else {
// Will set a timer to request tooltip in `time`
that.tooltip_timeout = setTimeout(function(){
IPython.notebook.request_tool_tip(that, pre_cursor)
},time);
}
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Fixing execution related things....
r4378 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 // This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
MinRK
skip codemirror key-event handling when read-only
r5656
if (this.read_only){
return false;
}
fawce
added key handler for control-s to notebook, seems to work pretty well
r5990
Matthias BUSSONNIER
Make the time before activating a tooltip configurable...
r5400 // note that we are comparing and setting the time to wait at each key press.
// a better wqy might be to generate a new function on each time change and
// assign it to CodeCell.prototype.request_tooltip_after_time
tooltip_wait_time = this.notebook.time_before_tooltip;
Matthias BUSSONNIER
Improve tooltip tringgering,make it configurable...
r5399 tooltip_on_tab = this.notebook.tooltip_on_tab;
Matthias BUSSONNIER
tooltip on <tab>
r5398 var that = this;
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 // whatever key is pressed, first, cancel the tooltip request before
// they are sent, and remove tooltip if any
Matthias BUSSONNIER
fix double tooltip...
r5524 if(event.type === 'keydown' ){
MinRK
Cleanup some inappropriate javascript...
r5566 that.remove_and_cancel_tooltip();
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 }
fawce
added key handler for control-s to notebook, seems to work pretty well
r5990
Brian E. Granger
Fixing Ctrl-Enter on Firefox.
r4704 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
Brian E. Granger
Fixing execution related things....
r4378 // Always ignore shift-enter in CodeMirror as we handle it.
return true;
Brian Granger
Fixing bugs that have shown up since updating CM to 2.2.
r5942 } else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) {
Matthias BUSSONNIER
Replace trigering tooltip for cross platform indep...
r5403 // triger aon keypress (!) otherwise inconsistent event.which depending on plateform
// browser and keyboard layout !
Matthias BUSSONNIER
Improve tooltip tringgering,make it configurable...
r5399 // Pressing '(' , request tooltip, don't forget to reappend it
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 var cursor = editor.getCursor();
Matthias BUSSONNIER
Improve tooltip tringgering,make it configurable...
r5399 var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
MinRK
Cleanup some inappropriate javascript...
r5566 that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
Brian Granger
Updating cell logic....
r5944 } else if (event.which === 38) {
// If we are not at the top, let CM handle the up arrow and
// prevent the global keydown handler from handling it.
if (!that.at_top()) {
event.stop();
return false;
} else {
return true;
};
} else if (event.which === 40) {
// If we are not at the bottom, let CM handle the down arrow and
// prevent the global keydown handler from handling it.
if (!that.at_bottom()) {
event.stop();
return false;
} else {
return true;
};
Brian E. Granger
Fixing tab completion edge cases.
r4555 } else if (event.keyCode === 9 && event.type == 'keydown') {
// Tab completion.
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 var cur = editor.getCursor();
Matthias BUSSONNIER
tooltip on <tab>
r5398 //Do not trim here because of tooltip
var pre_cursor = editor.getRange({line:cur.line,ch:0},cur);
if (pre_cursor.trim() === "") {
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 // Don't autocomplete if the part of the line before the cursor
// is empty. In this case, let CodeMirror handle indentation.
Brian E. Granger
Notebook now uses tab for autocompletion.
r4393 return false;
Matthias BUSSONNIER
Improve tooltip tringgering,make it configurable...
r5399 } else if ((pre_cursor.substr(-1) === "("|| pre_cursor.substr(-1) === " ") && tooltip_on_tab ) {
MinRK
Cleanup some inappropriate javascript...
r5566 that.request_tooltip_after_time(pre_cursor,0);
Brian E. Granger
Notebook now uses tab for autocompletion.
r4393 } else {
Matthias BUSSONNIER
tooltip on <tab>
r5398 pre_cursor.trim();
Brian E. Granger
Notebook now uses tab for autocompletion.
r4393 // Autocomplete the current line.
event.stop();
var line = editor.getLine(cur.line);
this.is_completing = true;
this.completion_cursor = cur;
IPython.notebook.complete_cell(this, line, cur.ch);
return true;
}
Brian E. Granger
Autoindentation fixed and enabled by default.
r4529 } else if (event.keyCode === 8 && event.type == 'keydown') {
Brian E. Granger
Implemented smart autoindenting.
r4512 // If backspace and the line ends with 4 spaces, remove them.
var cur = editor.getCursor();
var line = editor.getLine(cur.line);
var ending = line.slice(-4);
if (ending === ' ') {
editor.replaceRange('',
{line: cur.line, ch: cur.ch-4},
{line: cur.line, ch: cur.ch}
);
event.stop();
return true;
} else {
return false;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 }
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 } else if (event.keyCode === 76 && event.ctrlKey && event.shiftKey
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 && event.type == 'keydown') {
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 // toggle line numbers with Ctrl-Shift-L
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 this.toggle_line_numbers();
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 }
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 else {
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 // keypress/keyup also trigger on TAB press, and we don't want to
// use those to disable tab completion.
Brian E. Granger
Fixing tab completion edge cases.
r4555 if (this.is_completing && event.keyCode !== 9) {
var ed_cur = editor.getCursor();
var cc_cur = this.completion_cursor;
if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
this.is_completing = false;
this.completion_cursor = null;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 }
}
Brian E. Granger
Fixing execution related things....
r4378 return false;
};
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 return false;
Brian E. Granger
Fixing execution related things....
r4378 };
MinRK
Cleanup some inappropriate javascript...
r5566 CodeCell.prototype.remove_and_cancel_tooltip = function() {
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 // note that we don't handle closing directly inside the calltip
// as in the completer, because it is not focusable, so won't
// get the event.
MinRK
Cleanup some inappropriate javascript...
r5566 if (this.tooltip_timeout != null){
clearTimeout(this.tooltip_timeout);
$('#tooltip').remove();
this.tooltip_timeout = null;
}
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 }
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 CodeCell.prototype.finish_tooltip = function (reply) {
Bradley M. Froehle
Show class init and call tooltips in notebook....
r5767 // Extract call tip data; the priority is call, init, main.
defstring = reply.call_def;
if (defstring == null) { defstring = reply.init_definition; }
if (defstring == null) { defstring = reply.definition; }
docstring = reply.call_docstring;
if (docstring == null) { docstring = reply.init_docstring; }
if (docstring == null) { docstring = reply.docstring; }
if (docstring == null) { docstring = "<empty docstring>"; }
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 name=reply.name;
Matthias BUSSONNIER
Add Tootip to notebook....
r5397
var that = this;
var tooltip = $('<div/>').attr('id', 'tooltip').addClass('tooltip');
Matthias BUSSONNIER
improve tooltip...
r5405 // remove to have the tooltip not Limited in X and Y
tooltip.addClass('smalltooltip');
var pre=$('<pre/>').html(utils.fixConsole(docstring));
Matthias BUSSONNIER
Change tooltip button to use jquery css
r5407 var expandlink=$('<a/>').attr('href',"#");
expandlink.addClass("ui-corner-all"); //rounded corner
expandlink.attr('role',"button");
//expandlink.addClass('ui-button');
//expandlink.addClass('ui-state-default');
var expandspan=$('<span/>').text('Expand');
expandspan.addClass('ui-icon');
expandspan.addClass('ui-icon-plus');
expandlink.append(expandspan);
expandlink.attr('id','expanbutton');
expandlink.click(function(){
Matthias BUSSONNIER
improve tooltip...
r5405 tooltip.removeClass('smalltooltip');
tooltip.addClass('bigtooltip');
$('#expanbutton').remove();
setTimeout(function(){that.code_mirror.focus();}, 50);
});
Matthias BUSSONNIER
Change tooltip button to use jquery css
r5407 var morelink=$('<a/>').attr('href',"#");
morelink.attr('role',"button");
morelink.addClass('ui-button');
//morelink.addClass("ui-corner-all"); //rounded corner
//morelink.addClass('ui-state-default');
var morespan=$('<span/>').text('Open in Pager');
morespan.addClass('ui-icon');
morespan.addClass('ui-icon-arrowstop-l-n');
morelink.append(morespan);
morelink.click(function(){
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 var msg_id = IPython.notebook.kernel.execute(name+"?");
Matthias BUSSONNIER
forgotten selected_cell -> get_selected_cell...
r5966 IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id;
MinRK
Cleanup some inappropriate javascript...
r5566 that.remove_and_cancel_tooltip();
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 setTimeout(function(){that.code_mirror.focus();}, 50);
});
Matthias BUSSONNIER
Change tooltip button to use jquery css
r5407 var closelink=$('<a/>').attr('href',"#");
closelink.attr('role',"button");
closelink.addClass('ui-button');
//closelink.addClass("ui-corner-all"); //rounded corner
//closelink.adClass('ui-state-default'); // grey background and blue cross
var closespan=$('<span/>').text('Close');
closespan.addClass('ui-icon');
closespan.addClass('ui-icon-close');
closelink.append(closespan);
closelink.click(function(){
MinRK
Cleanup some inappropriate javascript...
r5566 that.remove_and_cancel_tooltip();
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 setTimeout(function(){that.code_mirror.focus();}, 50);
});
Matthias BUSSONNIER
improve tooltip...
r5405 //construct the tooltip
Matthias BUSSONNIER
Change tooltip button to use jquery css
r5407 tooltip.append(closelink);
tooltip.append(expandlink);
tooltip.append(morelink);
Matthias BUSSONNIER
improve tooltip...
r5405 if(defstring){
Matthias BUSSONNIER
Apply pep8 to js
r5636 defstring_html = $('<pre/>').html(utils.fixConsole(defstring));
Matthias BUSSONNIER
improve tooltip...
r5405 tooltip.append(defstring_html);
}
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 tooltip.append(pre);
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 var pos = this.code_mirror.cursorCoords();
tooltip.css('left',pos.x+'px');
tooltip.css('top',pos.yBot+'px');
$('body').append(tooltip);
// issues with cross-closing if multiple tooltip in less than 5sec
// keep it comented for now
MinRK
Cleanup some inappropriate javascript...
r5566 // setTimeout(that.remove_and_cancel_tooltip, 5000);
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 };
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 // As you type completer
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 CodeCell.prototype.finish_completing = function (matched_text, matches) {
Matthias BUSSONNIER
tidy up code
r5523 //return if not completing or nothing to complete
if (!this.is_completing || matches.length === 0) {return;}
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507
Matthias BUSSONNIER
tidy up code
r5523 // for later readability
Matthias BUSSONNIER
tab pick if only one match left
r5522 var key = { tab:9,
Matthias BUSSONNIER
tidy up code
r5523 esc:27,
backspace:8,
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 space:32,
Matthias BUSSONNIER
tab pick if only one match left
r5522 shift:16,
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 enter:13,
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 // _ is 95
Matthias BUSSONNIER
tidy up code
r5523 isCompSymbol : function (code)
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 {
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 return (code > 64 && code <= 90)
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 || (code >= 97 && code <= 122)
|| (code == 95)
},
dismissAndAppend : function (code)
{
Matthias BUSSONNIER
notebook: code Readability. Add dismissing symbols...
r5639 chararr = '()[]+-/\\. ,=*'.split("");
Matthias BUSSONNIER
Apply pep8 to js
r5636 codearr = chararr.map(function(x){return x.charCodeAt(0)});
return jQuery.inArray(code, codearr) != -1;
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 }
Matthias BUSSONNIER
tab pick if only one match left
r5522 }
Matthias BUSSONNIER
tidy up code
r5523
// smart completion, sort kwarg ending with '='
Matthias BUSSONNIER
smart kwarg completion...
r5401 var newm = new Array();
if(this.notebook.smart_completer)
{
kwargs = new Array();
other = new Array();
Matthias BUSSONNIER
Apply pep8 to js
r5636 for(var i = 0 ; i<matches.length ; ++i){
Matthias BUSSONNIER
smart kwarg completion...
r5401 if(matches[i].substr(-1) === '='){
kwargs.push(matches[i]);
}else{other.push(matches[i]);}
}
newm = kwargs.concat(other);
Matthias BUSSONNIER
Apply pep8 to js
r5636 matches = newm;
Matthias BUSSONNIER
smart kwarg completion...
r5401 }
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 // end sort kwargs
Matthias BUSSONNIER
tidy up code
r5523 // give common prefix of a array of string
Matthias BUSSONNIER
tabs fast forward user tab
r5518 function sharedStart(A){
Matthias BUSSONNIER
notebook: fix, only one completion autopick
r5638 if(A.length == 1){return A[0]}
Matthias BUSSONNIER
tabs fast forward user tab
r5518 if(A.length > 1 ){
Matthias BUSSONNIER
Apply pep8 to js
r5636 var tem1, tem2, s, A = A.slice(0).sort();
tem1 = A[0];
s = tem1.length;
tem2 = A.pop();
while(s && tem2.indexOf(tem1) == -1){
tem1 = tem1.substring(0, --s);
Matthias BUSSONNIER
tidy up code
r5523 }
return tem1;
Matthias BUSSONNIER
tabs fast forward user tab
r5518 }
return "";
}
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389
Matthias BUSSONNIER
show tooltip if completer 'fail' afer n attempt...
r5406 //try to check if the user is typing tab at least twice after a word
// and completion is "done"
Matthias BUSSONNIER
Apply pep8 to js
r5636 fallback_on_tooltip_after = 2
if(matches.length == 1 && matched_text === matches[0])
Matthias BUSSONNIER
show tooltip if completer 'fail' afer n attempt...
r5406 {
if(this.npressed >fallback_on_tooltip_after && this.prevmatch==matched_text)
{
MinRK
Cleanup some inappropriate javascript...
r5566 this.request_tooltip_after_time(matched_text+'(',0);
Matthias BUSSONNIER
show tooltip if completer 'fail' afer n attempt...
r5406 return;
}
Matthias BUSSONNIER
Apply pep8 to js
r5636 this.prevmatch = matched_text
this.npressed = this.npressed+1;
Matthias BUSSONNIER
show tooltip if completer 'fail' afer n attempt...
r5406 }
else
{
Matthias BUSSONNIER
Apply pep8 to js
r5636 this.prevmatch = "";
this.npressed = 0;
Matthias BUSSONNIER
show tooltip if completer 'fail' afer n attempt...
r5406 }
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 // end fallback on tooltip
Matthias BUSSONNIER
tidy up code
r5523 //==================================
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 // Real completion logic start here
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 var that = this;
var cur = this.completion_cursor;
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 var done = false;
// call to dismmiss the completer
var close = function () {
if (done) return;
done = true;
Matthias BUSSONNIER
Apply pep8 to js
r5636 if (complete != undefined)
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 {complete.remove();}
that.is_completing = false;
that.completion_cursor = null;
};
Brian E. Granger
A single tab-completion match is now automatically selected.
r4554
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 // update codemirror with the typed text
prev = matched_text
var update = function (inserted_text, event) {
Brian E. Granger
A single tab-completion match is now automatically selected.
r4554 that.code_mirror.replaceRange(
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 inserted_text,
Brian E. Granger
A single tab-completion match is now automatically selected.
r4554 {line: cur.line, ch: (cur.ch-matched_text.length)},
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 {line: cur.line, ch: (cur.ch+prev.length-matched_text.length)}
Brian E. Granger
A single tab-completion match is now automatically selected.
r4554 );
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 prev = inserted_text
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 if(event != null){
event.stopPropagation();
event.preventDefault();
}
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 };
// insert the given text and exit the completer
var insert = function (selected_text, event) {
update(selected_text)
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 close();
setTimeout(function(){that.code_mirror.focus();}, 50);
};
// insert the curent highlited selection and exit
var pick = function () {
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 insert(select.val()[0],null);
Brian E. Granger
A single tab-completion match is now automatically selected.
r4554 };
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507
// Define function to clear the completer, refill it with the new
Matthias BUSSONNIER
tidy up code
r5523 // matches, update the pseuso typing field. autopick insert match if
// only one left, in no matches (anymore) dismiss itself by pasting
// what the user have typed until then
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 var complete_with = function(matches,typed_text,autopick,event)
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 {
Matthias BUSSONNIER
tab pick if only one match left
r5522 // If autopick an only one match, past.
// Used to 'pick' when pressing tab
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 if (matches.length < 1) {
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 insert(typed_text,event);
Matthias BUSSONNIER
Apply pep8 to js
r5636 if(event != null){
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 event.stopPropagation();
event.preventDefault();
}
Matthias BUSSONNIER
Apply pep8 to js
r5636 } else if (autopick && matches.length == 1) {
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 insert(matches[0],event);
Matthias BUSSONNIER
Apply pep8 to js
r5636 if(event != null){
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 event.stopPropagation();
event.preventDefault();
}
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 }
Matthias BUSSONNIER
tab pick if only one match left
r5522 //clear the previous completion if any
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 update(typed_text,event);
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 complete.children().children().remove();
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 $('#asyoutype').html("<b>"+matched_text+"</b>"+typed_text.substr(matched_text.length));
Matthias BUSSONNIER
Apply pep8 to js
r5636 select = $('#asyoutypeselect');
for (var i = 0; i<matches.length; ++i) {
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 select.append($('<option/>').html(matches[i]));
}
select.children().first().attr('selected','true');
}
// create html for completer
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 var complete = $('<div/>').addClass('completions');
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 complete.attr('id','complete');
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 complete.append($('<p/>').attr('id', 'asyoutype').html('<b>fixed part</b>user part'));//pseudo input field
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 var select = $('<select/>').attr('multiple','true');
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 select.attr('id', 'asyoutypeselect')
select.attr('size',Math.min(10,matches.length));
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 var pos = this.code_mirror.cursorCoords();
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507
// TODO: I propose to remove enough horizontal pixel
// to align the text later
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 complete.css('left',pos.x+'px');
complete.css('top',pos.yBot+'px');
complete.append(select);
$('body').append(complete);
Matthias BUSSONNIER
tidy up code
r5523 // So a first actual completion. see if all the completion start wit
// the same letter and complete if necessary
Matthias BUSSONNIER
tab pick if only one match left
r5522 fastForward = sharedStart(matches)
Matthias BUSSONNIER
Apply pep8 to js
r5636 typed_characters = fastForward.substr(matched_text.length);
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 complete_with(matches,matched_text+typed_characters,true,null);
Matthias BUSSONNIER
Apply pep8 to js
r5636 filterd = matches;
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 // Give focus to select, and make it filter the match as the user type
Matthias BUSSONNIER
tidy up code
r5523 // by filtering the previous matches. Called by .keypress and .keydown
Matthias BUSSONNIER
Handle lower and uppercase
r5509 var downandpress = function (event,press_or_down) {
Matthias BUSSONNIER
tab pick if only one match left
r5522 var code = event.which;
var autopick = false; // auto 'pick' if only one match
Matthias BUSSONNIER
Handle lower and uppercase
r5509 if (press_or_down === 0){
Matthias BUSSONNIER
Apply pep8 to js
r5636 press = true; down = false; //Are we called from keypress or keydown
Matthias BUSSONNIER
Handle lower and uppercase
r5509 } else if (press_or_down == 1){
Matthias BUSSONNIER
Apply pep8 to js
r5636 press = false; down = true;
Matthias BUSSONNIER
Handle lower and uppercase
r5509 }
Matthias BUSSONNIER
tab pick if only one match left
r5522 if (code === key.shift) {
Matthias BUSSONNIER
protect shift extend on Uppercase
r5508 // nothing on Shift
return;
}
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 if (key.dismissAndAppend(code) && press) {
var newchar = String.fromCharCode(code);
Matthias BUSSONNIER
Apply pep8 to js
r5636 typed_characters = typed_characters+newchar;
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 insert(matched_text+typed_characters,event);
return
}
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 if (code === key.enter) {
// Pressing ENTER will cause a pick
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 event.stopPropagation();
event.preventDefault();
pick();
} else if (code === 38 || code === 40) {
// We don't want the document keydown handler to handle UP/DOWN,
// but we want the default action.
event.stopPropagation();
Matthias BUSSONNIER
Apply pep8 to js
r5636 } else if ( (code == key.backspace)||(code == key.tab && down) || press || key.isCompSymbol(code)){
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 if( key.isCompSymbol(code) && press)
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 {
Matthias BUSSONNIER
Handle lower and uppercase
r5509 var newchar = String.fromCharCode(code);
Matthias BUSSONNIER
Apply pep8 to js
r5636 typed_characters = typed_characters+newchar;
Matthias BUSSONNIER
tab pick if only one match left
r5522 } else if (code == key.tab) {
Matthias BUSSONNIER
tabs fast forward user tab
r5518 fastForward = sharedStart(filterd)
ffsub = fastForward.substr(matched_text.length+typed_characters.length);
Matthias BUSSONNIER
Apply pep8 to js
r5636 typed_characters = typed_characters+ffsub;
autopick = true;
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 } else if (code == key.backspace && down) {
Matthias BUSSONNIER
tidy up code
r5523 // cancel if user have erase everything, otherwise decrease
// what we filter with
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 event.preventDefault();
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 if (typed_characters.length <= 0)
{
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 insert(matched_text,event)
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 return
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 }
Matthias BUSSONNIER
Apply pep8 to js
r5636 typed_characters = typed_characters.substr(0,typed_characters.length-1);
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 } else if (press && code != key.backspace && code != key.tab && code != 0){
insert(matched_text+typed_characters,event);
return
} else {
Matthias BUSSONNIER
Apply pep8 to js
r5636 return
Matthias BUSSONNIER
usability and cross browser compat for completer...
r5635 }
Matthias BUSSONNIER
Handle lower and uppercase
r5509 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
Matthias BUSSONNIER
tidy up code
r5523 filterd = matches.filter(function(x){return re.test(x)});
Matthias BUSSONNIER
as you type Completer, propagate event by hand...
r5531 complete_with(filterd,matched_text+typed_characters,autopick,event);
Brian Granger
Finishing work on "Make a Copy" functionality.
r5861 } else if (code == key.esc) {
Matthias BUSSONNIER
completer update code-miror on the fly...
r5637 // dismiss the completer and go back to before invoking it
insert(matched_text,event);
Brian Granger
Finishing work on "Make a Copy" functionality.
r5861 } else if (press) { // abort only on .keypress or esc
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 }
Matthias BUSSONNIER
Handle lower and uppercase
r5509 }
select.keydown(function (event) {
downandpress(event,1)
});
select.keypress(function (event) {
downandpress(event,0)
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 });
// Double click also causes a pick.
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 // and bind the last actions.
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 select.dblclick(pick);
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507 select.blur(close);
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 select.focus();
};
Brian Granger
Fixing bugs that have shown up since updating CM to 2.2.
r5942
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 CodeCell.prototype.toggle_line_numbers = function () {
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 if (this.code_mirror.getOption('lineNumbers') == false) {
this.code_mirror.setOption('lineNumbers', true);
} else {
this.code_mirror.setOption('lineNumbers', false);
}
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.code_mirror.refresh();
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 };
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389
Brian Granger
Fixing bugs that have shown up since updating CM to 2.2.
r5942
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.select = function () {
IPython.Cell.prototype.select.apply(this);
Brian Granger
Fixing bugs that have shown up since updating CM to 2.2.
r5942 this.code_mirror.refresh();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.code_mirror.focus();
Brian Granger
Removing extra refresh that is no longer needed because of CM fix.
r5971 // We used to need an additional refresh() after the focus, but
// it appears that this has been fixed in CM. This bug would show
// up on FF when a newly loaded markdown cell was edited.
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Ctrl-Enter now does not delete input, but selects it.
r4675 CodeCell.prototype.select_all = function () {
var start = {line: 0, ch: 0};
var nlines = this.code_mirror.lineCount();
var last_line = this.code_mirror.getLine(nlines-1);
var end = {line: nlines-1, ch: last_line.length};
this.code_mirror.setSelection(start, end);
};
Brian E. Granger
Added saving and loading of output of all types.
r4497 CodeCell.prototype.append_output = function (json) {
this.expand();
if (json.output_type === 'pyout') {
this.append_pyout(json);
} else if (json.output_type === 'pyerr') {
this.append_pyerr(json);
} else if (json.output_type === 'display_data') {
this.append_display_data(json);
} else if (json.output_type === 'stream') {
this.append_stream(json);
};
this.outputs.push(json);
};
Brian E. Granger
All output types are not indented.
r4642 CodeCell.prototype.create_output_area = function () {
var oa = $("<div/>").addClass("hbox output_area");
oa.append($('<div/>').addClass('prompt'));
return oa;
};
Brian E. Granger
Added saving and loading of output of all types.
r4497 CodeCell.prototype.append_pyout = function (json) {
n = json.prompt_number || ' ';
Brian E. Granger
All output types are not indented.
r4642 var toinsert = this.create_output_area();
toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
Brian E. Granger
Adding page break logic to the print css....
r4625 this.append_mime_type(json, toinsert);
Brian E. Granger
All output types are not indented.
r4642 this.element.find('div.output').append(toinsert);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // If we just output latex, typeset it.
Pablo Winant
Latexify formulas contained in html text....
r5306 if ((json.latex !== undefined) || (json.html !== undefined)) {
MinRK
allow the notebook to run without MathJax...
r5547 this.typeset();
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
};
Brian E. Granger
Added saving and loading of output of all types.
r4497 CodeCell.prototype.append_pyerr = function (json) {
var tb = json.traceback;
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 if (tb !== undefined && tb.length > 0) {
Brian E. Granger
Finishing display system work....
r4528 var s = '';
var len = tb.length;
for (var i=0; i<len; i++) {
s = s + tb[i] + '\n';
}
s = s + '\n';
Brian E. Granger
All output types are not indented.
r4642 var toinsert = this.create_output_area();
this.append_text(s, toinsert);
this.element.find('div.output').append(toinsert);
Brian E. Granger
Finishing display system work....
r4528 };
Brian E. Granger
Added saving and loading of output of all types.
r4497 };
CodeCell.prototype.append_stream = function (json) {
MinRK
support contiguous stream output in notebook...
r4864 // temporary fix: if stream undefined (json file written prior to this patch),
// default to most likely stdout:
if (json.stream == undefined){
json.stream = 'stdout';
}
MinRK
allow stdout/stderr to have distinct css...
r4865 var subclass = "output_"+json.stream;
MinRK
support contiguous stream output in notebook...
r4864 if (this.outputs.length > 0){
// have at least one output to consider
var last = this.outputs[this.outputs.length-1];
if (last.output_type == 'stream' && json.stream == last.stream){
// latest output was in the same stream,
// so append directly into its pre tag
MinRK
don't preserve fixConsole output in json
r5813 // escape ANSI & HTML specials:
var text = utils.fixConsole(json.text);
this.element.find('div.'+subclass).last().find('pre').append(text);
MinRK
support contiguous stream output in notebook...
r4864 return;
}
}
// If we got here, attach a new div
Brian E. Granger
All output types are not indented.
r4642 var toinsert = this.create_output_area();
MinRK
small CSS adjustments in notebook...
r4883 this.append_text(json.text, toinsert, "output_stream "+subclass);
Brian E. Granger
All output types are not indented.
r4642 this.element.find('div.output').append(toinsert);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Added saving and loading of output of all types.
r4497 CodeCell.prototype.append_display_data = function (json) {
Brian E. Granger
All output types are not indented.
r4642 var toinsert = this.create_output_area();
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.append_mime_type(json, toinsert);
Brian E. Granger
All output types are not indented.
r4642 this.element.find('div.output').append(toinsert);
Brian E. Granger
Fixing latex rendering bug.
r4553 // If we just output latex, typeset it.
Pablo Winant
Latexify formulas contained in html text....
r5306 if ( (json.latex !== undefined) || (json.html !== undefined) ) {
MinRK
allow the notebook to run without MathJax...
r5547 this.typeset();
Brian E. Granger
Fixing latex rendering bug.
r4553 };
Brian E. Granger
Added saving and loading of output of all types.
r4497 };
CodeCell.prototype.append_mime_type = function (json, element) {
if (json.html !== undefined) {
Brian E. Granger
All output types are not indented.
r4642 this.append_html(json.html, element);
Brian E. Granger
Added saving and loading of output of all types.
r4497 } else if (json.latex !== undefined) {
Brian E. Granger
All output types are not indented.
r4642 this.append_latex(json.latex, element);
Brian E. Granger
Added saving and loading of output of all types.
r4497 } else if (json.svg !== undefined) {
Brian E. Granger
All output types are not indented.
r4642 this.append_svg(json.svg, element);
Brian E. Granger
Added saving and loading of output of all types.
r4497 } else if (json.png !== undefined) {
Brian E. Granger
All output types are not indented.
r4642 this.append_png(json.png, element);
Brian E. Granger
Finishing display system work....
r4528 } else if (json.jpeg !== undefined) {
Brian E. Granger
All output types are not indented.
r4642 this.append_jpeg(json.jpeg, element);
Brian E. Granger
Added saving and loading of output of all types.
r4497 } else if (json.text !== undefined) {
Brian E. Granger
All output types are not indented.
r4642 this.append_text(json.text, element);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
MinRK
support html representations in the notebook frontend...
r4403 CodeCell.prototype.append_html = function (html, element) {
Brian E. Granger
All output types are not indented.
r4642 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_html rendered_html");
MinRK
support html representations in the notebook frontend...
r4403 toinsert.append(html);
element.append(toinsert);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
MinRK
support html representations in the notebook frontend...
r4403
MinRK
allow stdout/stderr to have distinct css...
r4865 CodeCell.prototype.append_text = function (data, element, extra_class) {
MinRK
small CSS adjustments in notebook...
r4883 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
MinRK
don't preserve fixConsole output in json
r5813 // escape ANSI & HTML specials in plaintext:
data = utils.fixConsole(data);
MinRK
allow stdout/stderr to have distinct css...
r4865 if (extra_class){
toinsert.addClass(extra_class);
}
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 toinsert.append($("<pre/>").html(data));
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 element.append(toinsert);
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.append_svg = function (svg, element) {
Brian E. Granger
All output types are not indented.
r4642 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_svg");
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 toinsert.append(svg);
element.append(toinsert);
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.append_png = function (png, element) {
Brian E. Granger
All output types are not indented.
r4642 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_png");
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
element.append(toinsert);
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Finishing display system work....
r4528 CodeCell.prototype.append_jpeg = function (jpeg, element) {
Brian E. Granger
All output types are not indented.
r4642 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_jpeg");
Brian E. Granger
Finishing display system work....
r4528 toinsert.append($("<img/>").attr('src','data:image/jpeg;base64,'+jpeg));
element.append(toinsert);
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.append_latex = function (latex, element) {
// This method cannot do the typesetting because the latex first has to
// be on the page.
Brian E. Granger
All output types are not indented.
r4642 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_latex");
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 toinsert.append(latex);
element.append(toinsert);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
MinRK
add channel-selection to clear_output...
r5085 CodeCell.prototype.clear_output = function (stdout, stderr, other) {
var output_div = this.element.find("div.output");
if (stdout && stderr && other){
// clear all, no need for logic
output_div.html("");
this.outputs = [];
return;
}
// remove html output
// each output_subarea that has an identifying class is in an output_area
// which is the element to be removed.
if (stdout){
output_div.find("div.output_stdout").parent().remove();
}
if (stderr){
output_div.find("div.output_stderr").parent().remove();
}
if (other){
output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
}
// remove cleared outputs from JSON list:
for (var i = this.outputs.length - 1; i >= 0; i--){
var out = this.outputs[i];
var output_type = out.output_type;
if (output_type == "display_data" && other){
this.outputs.splice(i,1);
}else if (output_type == "stream"){
if (stdout && out.stream == "stdout"){
this.outputs.splice(i,1);
}else if (stderr && out.stream == "stderr"){
this.outputs.splice(i,1);
}
}
}
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
CTRL-ENTER now runs a cell in "terminal mode"...
r4390 CodeCell.prototype.clear_input = function () {
this.code_mirror.setValue('');
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.collapse = function () {
Brian E. Granger
Added collapsed field to the code cell.
r4533 if (!this.collapsed) {
this.element.find('div.output').hide();
this.collapsed = true;
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.expand = function () {
Brian E. Granger
Added collapsed field to the code cell.
r4533 if (this.collapsed) {
this.element.find('div.output').show();
this.collapsed = false;
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Cell collapse/expand is not called "Toggle".
r4639 CodeCell.prototype.toggle_output = function () {
if (this.collapsed) {
this.expand();
} else {
this.collapse();
};
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.set_input_prompt = function (number) {
MinRK
store nonexistent prompt number as null
r5814 this.input_prompt_number = number;
var ns = number || "&nbsp;";
this.element.find('div.input_prompt').html('In&nbsp;[' + ns + ']:');
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Work on the base Cell API....
r5943 CodeCell.prototype.get_text = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this.code_mirror.getValue();
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Work on the base Cell API....
r5943 CodeCell.prototype.set_text = function (code) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this.code_mirror.setValue(code);
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.at_top = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === 0) {
return true;
} else {
return false;
}
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.at_bottom = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === (this.code_mirror.lineCount()-1)) {
return true;
} else {
return false;
}
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.fromJSON = function (data) {
if (data.cell_type === 'code') {
Brian E. Granger
Massive work on the notebook document format....
r4484 if (data.input !== undefined) {
Brian Granger
Work on the base Cell API....
r5943 this.set_text(data.input);
Brian E. Granger
Massive work on the notebook document format....
r4484 }
if (data.prompt_number !== undefined) {
this.set_input_prompt(data.prompt_number);
} else {
this.set_input_prompt();
};
Brian E. Granger
Added saving and loading of output of all types.
r4497 var len = data.outputs.length;
for (var i=0; i<len; i++) {
this.append_output(data.outputs[i]);
};
Brian E. Granger
Added collapsed field to the code cell.
r4533 if (data.collapsed !== undefined) {
if (data.collapsed) {
this.collapse();
};
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
};
CodeCell.prototype.toJSON = function () {
Brian E. Granger
Added saving and loading of output of all types.
r4497 var data = {};
Brian Granger
Work on the base Cell API....
r5943 data.input = this.get_text();
Brian E. Granger
Massive work on the notebook document format....
r4484 data.cell_type = 'code';
MinRK
store nonexistent prompt number as null
r5814 if (this.input_prompt_number) {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 data.prompt_number = this.input_prompt_number;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Added saving and loading of output of all types.
r4497 var outputs = [];
var len = this.outputs.length;
for (var i=0; i<len; i++) {
outputs[i] = this.outputs[i];
};
data.outputs = outputs;
Brian E. Granger
Massive work on the notebook document format....
r4484 data.language = 'python';
Brian E. Granger
Added collapsed field to the code cell.
r4533 data.collapsed = this.collapsed;
Brian E. Granger
Massive work on the notebook document format....
r4484 return data;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Added saving and loading of output of all types.
r4497
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.CodeCell = CodeCell;
return IPython;
}(IPython));