##// END OF EJS Templates
fix typo that->this
fix typo that->this

File last commit:

r7160:df016497
r7165:12a38888
Show More
codecell.js
532 lines | 18.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) {
Matthias BUSSONNIER
use strict and clean a little....
r7132 "use strict";
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var utils = IPython.utils;
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 var key = IPython.utils.keycodes;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
var CodeCell = function (notebook) {
this.code_mirror = null;
MinRK
store nonexistent prompt number as null
r5814 this.input_prompt_number = 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
[notebook] clear_output is handled after a delay...
r6423 this.clear_out_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,
Matthias BUSSONNIER
use strict and clean a little....
r7132 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();
Matthias BUSSONNIER
use strict and clean a little....
r7132
// construct a completer
Matthias BUSSONNIER
clean code, remove duplicate unused lines
r7142 this.completer = new IPython.Completer(this);
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
use strict and clean a little....
r7132 var 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
Matthias BUSSONNIER
multiple tooltip action...
r7160 // they are sent, and remove tooltip if any, except for tab again
if(event.type === 'keydown' && event.which != key.tab ) {
Matthias Bussonnier
fix scrolltop
r7151 IPython.tooltip.remove_and_cancel_tooltip();
Brian Granger
Making keyboard shortcut for showing line numbers consistent.
r6059 };
Matthias BUSSONNIER
add ctrlKey.which to utils...
r7139 if (event.keyCode === key.enter && (event.shiftKey || event.ctrlKey)) {
Brian E. Granger
Fixing execution related things....
r4378 // Always ignore shift-enter in CodeMirror as we handle it.
return true;
Matthias BUSSONNIER
multiple tooltip action...
r7160 } else if (event.which === 40 && event.type === 'keypress' && this.notebook.time_before_tooltip >= 0) {
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
Matthias BUSSONNIER
Replace trigering tooltip for cross platform indep...
r5403 // browser and keyboard layout !
Matthias BUSSONNIER
Improve tooltip tringgering,make it configurable...
r5399 // Pressing '(' , request tooltip, don't forget to reappend it
Matthias BUSSONNIER
multiple tooltip action...
r7160 IPython.tooltip.pending(that);
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 } else if (event.which === key.upArrow) {
Brian Granger
Updating cell logic....
r5944 // 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;
};
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 } else if (event.which === key.downArrow) {
Brian Granger
Updating cell logic....
r5944 // 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;
};
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 } else if (event.keyCode === key.tab && event.type == 'keydown') {
Brian E. Granger
Fixing tab completion edge cases.
r4555 // 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 ) {
Matthias BUSSONNIER
multiple tooltip action...
r7160 IPython.tooltip.request(that);
Brian Granger
Fixing #1337. Tooltip stops TAB from being handled by others....
r6052 // Prevent the event from bubbling up.
event.stop();
// Prevent CodeMirror from handling the tab.
return true;
Brian E. Granger
Notebook now uses tab for autocompletion.
r4393 } else {
event.stop();
Matthias BUSSONNIER
use strict and clean a little....
r7132 this.completer.startCompletion();
Brian E. Granger
Notebook now uses tab for autocompletion.
r4393 return true;
Brian Granger
Making keyboard shortcut for showing line numbers consistent.
r6059 };
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 } else if (event.keyCode === key.backspace && 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;
Brian Granger
Making keyboard shortcut for showing line numbers consistent.
r6059 };
} 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 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 };
Matthias BUSSONNIER
add 'more...' and 'close' button to the pager...
r5404 CodeCell.prototype.finish_tooltip = function (reply) {
Matthias BUSSONNIER
call tooltip by cell reference
r7156 IPython.tooltip.show(reply, this);
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 };
Matthias BUSSONNIER
Base of an as you type conpleter....
r5507
Matthias BUSSONNIER
more cleaning
r7143 // called when completion came back from the kernel. just forward
Matthias BUSSONNIER
implement the completer in a separate class...
r7131 CodeCell.prototype.finish_completing = function (matched_text, matches) {
Matthias BUSSONNIER
move more code into the completer itself
r7141 this.completer.finish_completing(matched_text,matches);
}
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 Granger
Javascript output is not run on notebook loading and paste's.
r6084 CodeCell.prototype.append_output = function (json, dynamic) {
// If dynamic is true, javascript output will be eval'd.
Brian E. Granger
Added saving and loading of output of all types.
r4497 this.expand();
MinRK
[notebook] clear_output is handled after a delay...
r6423 this.flush_clear_timeout();
Brian E. Granger
Added saving and loading of output of all types.
r4497 if (json.output_type === 'pyout') {
Brian Granger
Javascript output is not run on notebook loading and paste's.
r6084 this.append_pyout(json, dynamic);
Brian E. Granger
Added saving and loading of output of all types.
r4497 } else if (json.output_type === 'pyerr') {
this.append_pyerr(json);
} else if (json.output_type === 'display_data') {
Brian Granger
Javascript output is not run on notebook loading and paste's.
r6084 this.append_display_data(json, dynamic);
Brian E. Granger
Added saving and loading of output of all types.
r4497 } 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 Granger
Javascript output is not run on notebook loading and paste's.
r6084 CodeCell.prototype.append_pyout = function (json, dynamic) {
Matthias BUSSONNIER
use strict and clean a little....
r7132 var 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 Granger
Javascript output is not run on notebook loading and paste's.
r6084 this.append_mime_type(json, toinsert, dynamic);
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
revert PR #1659...
r6676 if (!utils.fixConsole(json.text)){
// fixConsole gives nothing (empty string, \r, etc.)
// so don't append any elements, which might add undesirable space
return;
}
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:
MinRK
revert PR #1659...
r6676 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;
}
}
MinRK
revert PR #1659...
r6676
MinRK
support contiguous stream output in notebook...
r4864 // 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
revert PR #1659...
r6676 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 Granger
Javascript output is not run on notebook loading and paste's.
r6084 CodeCell.prototype.append_display_data = function (json, dynamic) {
Brian E. Granger
All output types are not indented.
r4642 var toinsert = this.create_output_area();
Brian Granger
Javascript output is not run on notebook loading and paste's.
r6084 this.append_mime_type(json, toinsert, dynamic);
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 };
Brian Granger
Javascript output is not run on notebook loading and paste's.
r6084 CodeCell.prototype.append_mime_type = function (json, element, dynamic) {
if (json.javascript !== undefined && dynamic) {
this.append_javascript(json.javascript, element, dynamic);
} else 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
document initially hidden javascript container
r6425 CodeCell.prototype.append_javascript = function (js, container) {
Brian Granger
Wired up the javascript display protocol using eval.
r6083 // We just eval the JS code, element appears in the local scope.
Brian Granger
Javascript output is not run on notebook loading and paste's.
r6084 var element = $("<div/>").addClass("box_flex1 output_subarea");
MinRK
document initially hidden javascript container
r6425 container.append(element);
MinRK
hide output_area for js...
r6424 // Div for js shouldn't be drawn, as it will add empty height to the area.
MinRK
document initially hidden javascript container
r6425 container.hide();
// If the Javascript appends content to `element` that should be drawn, then
// it must also call `container.show()`.
Brian Granger
Wired up the javascript display protocol using eval.
r6083 eval(js);
}
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) {
MinRK
[notebook] clear_output is handled after a delay...
r6423 var that = this;
if (this.clear_out_timeout != null){
// fire previous pending clear *immediately*
clearTimeout(this.clear_out_timeout);
this.clear_out_timeout = null;
this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
}
// store flags for flushing the timeout
this._clear_stdout = stdout;
this._clear_stderr = stderr;
this._clear_other = other;
this.clear_out_timeout = setTimeout(function(){
// really clear timeout only after a short delay
// this reduces flicker in 'clear_output; print' cases
that.clear_out_timeout = null;
that._clear_stdout = that._clear_stderr = that._clear_other = null;
that.clear_output_callback(stdout, stderr, other);
}, 500
);
};
CodeCell.prototype.clear_output_callback = function (stdout, stderr, other) {
MinRK
add channel-selection to clear_output...
r5085 var output_div = this.element.find("div.output");
MinRK
[notebook] clear_output is handled after a delay...
r6423
MinRK
add channel-selection to clear_output...
r5085 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('');
};
MinRK
[notebook] clear_output is handled after a delay...
r6423
CodeCell.prototype.flush_clear_timeout = function() {
var output_div = this.element.find('div.output');
if (this.clear_out_timeout){
clearTimeout(this.clear_out_timeout);
this.clear_out_timeout = null;
this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
};
}
Brian E. Granger
CTRL-ENTER now runs a cell in "terminal mode"...
r4390
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++) {
Brian Granger
Javascript output is not run on notebook loading and paste's.
r6084 // append with dynamic=false.
this.append_output(data.outputs[i], false);
Brian E. Granger
Added saving and loading of output of all types.
r4497 };
Brian E. Granger
Added collapsed field to the code cell.
r4533 if (data.collapsed !== undefined) {
if (data.collapsed) {
this.collapse();
Brian Granger
Fixing minor bugs in nbformat and saving....
r6032 } else {
this.expand();
Brian E. Granger
Added collapsed field to the code cell.
r4533 };
};
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));