From 24d37b6bccb97531742f23799cbb4e08f3f55018 Mon Sep 17 00:00:00 2001 From: MinRK Date: Mon, 17 Oct 2011 18:37:08 -0700 Subject: [PATCH] add channel-selection to clear_output example notebook updated accordingly --- .../html/notebook/static/js/codecell.js | 38 +++++++++++++++++-- .../html/notebook/static/js/notebook.js | 6 +-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 83ebd3744..b557e29ab 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -364,9 +364,41 @@ var IPython = (function (IPython) { } - CodeCell.prototype.clear_output = function () { - this.element.find("div.output").html(""); - this.outputs = []; + 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); + } + } + } }; diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 29b7487b3..0cc2e2080 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -627,7 +627,7 @@ var IPython = (function (IPython) { var cells = this.cells(); for (var i=0; i