##// END OF EJS Templates
dblclick to restore size of images
MinRK -
Show More
@@ -1,416 +1,458 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // OutputArea
9 // OutputArea
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13 "use strict";
14
14
15 var utils = IPython.utils;
15 var utils = IPython.utils;
16
16
17 var OutputArea = function (selector, prompt_area) {
17 var OutputArea = function (selector, prompt_area) {
18 this.selector = selector;
18 this.selector = selector;
19 this.element = $(selector);
19 this.element = $(selector);
20 this.outputs = [];
20 this.outputs = [];
21 this.collapsed = false;
21 this.collapsed = false;
22 this.clear_out_timeout = null;
22 this.clear_out_timeout = null;
23 if (prompt_area === undefined) {
23 if (prompt_area === undefined) {
24 this.prompt_area = true;
24 this.prompt_area = true;
25 } else {
25 } else {
26 this.prompt_area = prompt_area;
26 this.prompt_area = prompt_area;
27 };
27 };
28 this.style();
28 this.style();
29 };
29 };
30
30
31
31
32 OutputArea.prototype.style = function () {
32 OutputArea.prototype.style = function () {
33 this.element.addClass('output vbox');
33 this.element.addClass('output vbox');
34 this.collapse();
34 this.collapse();
35 };
35 };
36
36
37
37
38 OutputArea.prototype.collapse = function () {
38 OutputArea.prototype.collapse = function () {
39 if (!this.collapsed) {
39 if (!this.collapsed) {
40 this.element.hide();
40 this.element.hide();
41 this.collapsed = true;
41 this.collapsed = true;
42 };
42 };
43 };
43 };
44
44
45
45
46 OutputArea.prototype.expand = function () {
46 OutputArea.prototype.expand = function () {
47 if (this.collapsed) {
47 if (this.collapsed) {
48 this.element.show();
48 this.element.show();
49 this.collapsed = false;
49 this.collapsed = false;
50 };
50 };
51 };
51 };
52
52
53
53
54 OutputArea.prototype.toggle_output = function () {
54 OutputArea.prototype.toggle_output = function () {
55 if (this.collapsed) {
55 if (this.collapsed) {
56 this.expand();
56 this.expand();
57 } else {
57 } else {
58 this.collapse();
58 this.collapse();
59 };
59 };
60 };
60 };
61
61
62
62
63 // typeset with MathJax if MathJax is available
63 // typeset with MathJax if MathJax is available
64 OutputArea.prototype.typeset = function () {
64 OutputArea.prototype.typeset = function () {
65 if (window.MathJax){
65 if (window.MathJax){
66 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
66 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
67 }
67 }
68 };
68 };
69
69
70
70
71 OutputArea.prototype.handle_output = function (msg_type, content) {
71 OutputArea.prototype.handle_output = function (msg_type, content) {
72 var json = {};
72 var json = {};
73 json.output_type = msg_type;
73 json.output_type = msg_type;
74 if (msg_type === "stream") {
74 if (msg_type === "stream") {
75 json.text = content.data;
75 json.text = content.data;
76 json.stream = content.name;
76 json.stream = content.name;
77 } else if (msg_type === "display_data") {
77 } else if (msg_type === "display_data") {
78 json = this.convert_mime_types(json, content.data);
78 json = this.convert_mime_types(json, content.data);
79 } else if (msg_type === "pyout") {
79 } else if (msg_type === "pyout") {
80 json.prompt_number = content.execution_count;
80 json.prompt_number = content.execution_count;
81 json = this.convert_mime_types(json, content.data);
81 json = this.convert_mime_types(json, content.data);
82 } else if (msg_type === "pyerr") {
82 } else if (msg_type === "pyerr") {
83 json.ename = content.ename;
83 json.ename = content.ename;
84 json.evalue = content.evalue;
84 json.evalue = content.evalue;
85 json.traceback = content.traceback;
85 json.traceback = content.traceback;
86 };
86 };
87 // append with dynamic=true
87 // append with dynamic=true
88 this.append_output(json, true);
88 this.append_output(json, true);
89 };
89 };
90
90
91
91
92 OutputArea.prototype.convert_mime_types = function (json, data) {
92 OutputArea.prototype.convert_mime_types = function (json, data) {
93 if (data['text/plain'] !== undefined) {
93 if (data['text/plain'] !== undefined) {
94 json.text = data['text/plain'];
94 json.text = data['text/plain'];
95 };
95 };
96 if (data['text/html'] !== undefined) {
96 if (data['text/html'] !== undefined) {
97 json.html = data['text/html'];
97 json.html = data['text/html'];
98 };
98 };
99 if (data['image/svg+xml'] !== undefined) {
99 if (data['image/svg+xml'] !== undefined) {
100 json.svg = data['image/svg+xml'];
100 json.svg = data['image/svg+xml'];
101 };
101 };
102 if (data['image/png'] !== undefined) {
102 if (data['image/png'] !== undefined) {
103 json.png = data['image/png'];
103 json.png = data['image/png'];
104 };
104 };
105 if (data['image/jpeg'] !== undefined) {
105 if (data['image/jpeg'] !== undefined) {
106 json.jpeg = data['image/jpeg'];
106 json.jpeg = data['image/jpeg'];
107 };
107 };
108 if (data['text/latex'] !== undefined) {
108 if (data['text/latex'] !== undefined) {
109 json.latex = data['text/latex'];
109 json.latex = data['text/latex'];
110 };
110 };
111 if (data['application/json'] !== undefined) {
111 if (data['application/json'] !== undefined) {
112 json.json = data['application/json'];
112 json.json = data['application/json'];
113 };
113 };
114 if (data['application/javascript'] !== undefined) {
114 if (data['application/javascript'] !== undefined) {
115 json.javascript = data['application/javascript'];
115 json.javascript = data['application/javascript'];
116 }
116 }
117 return json;
117 return json;
118 };
118 };
119
119
120
120
121 OutputArea.prototype.append_output = function (json, dynamic) {
121 OutputArea.prototype.append_output = function (json, dynamic) {
122 // If dynamic is true, javascript output will be eval'd.
122 // If dynamic is true, javascript output will be eval'd.
123 this.expand();
123 this.expand();
124 this.flush_clear_timeout();
124 this.flush_clear_timeout();
125 if (json.output_type === 'pyout') {
125 if (json.output_type === 'pyout') {
126 this.append_pyout(json, dynamic);
126 this.append_pyout(json, dynamic);
127 } else if (json.output_type === 'pyerr') {
127 } else if (json.output_type === 'pyerr') {
128 this.append_pyerr(json);
128 this.append_pyerr(json);
129 } else if (json.output_type === 'display_data') {
129 } else if (json.output_type === 'display_data') {
130 this.append_display_data(json, dynamic);
130 this.append_display_data(json, dynamic);
131 } else if (json.output_type === 'stream') {
131 } else if (json.output_type === 'stream') {
132 this.append_stream(json);
132 this.append_stream(json);
133 };
133 };
134 this.outputs.push(json);
134 this.outputs.push(json);
135 };
135 };
136
136
137
137
138 OutputArea.prototype.create_output_area = function () {
138 OutputArea.prototype.create_output_area = function () {
139 var oa = $("<div/>").addClass("hbox output_area");
139 var oa = $("<div/>").addClass("hbox output_area");
140 if (this.prompt_area) {
140 if (this.prompt_area) {
141 oa.append($('<div/>').addClass('prompt'));
141 oa.append($('<div/>').addClass('prompt'));
142 }
142 }
143 return oa;
143 return oa;
144 };
144 };
145
145
146
146
147 OutputArea.prototype.append_pyout = function (json, dynamic) {
147 OutputArea.prototype.append_pyout = function (json, dynamic) {
148 var n = json.prompt_number || ' ';
148 var n = json.prompt_number || ' ';
149 var toinsert = this.create_output_area();
149 var toinsert = this.create_output_area();
150 if (this.prompt_area) {
150 if (this.prompt_area) {
151 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
151 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
152 }
152 }
153 this.append_mime_type(json, toinsert, dynamic);
153 this.append_mime_type(json, toinsert, dynamic);
154 this.element.append(toinsert);
154 this.element.append(toinsert);
155 // If we just output latex, typeset it.
155 // If we just output latex, typeset it.
156 if ((json.latex !== undefined) || (json.html !== undefined)) {
156 if ((json.latex !== undefined) || (json.html !== undefined)) {
157 this.typeset();
157 this.typeset();
158 };
158 };
159 };
159 };
160
160
161
161
162 OutputArea.prototype.append_pyerr = function (json) {
162 OutputArea.prototype.append_pyerr = function (json) {
163 var tb = json.traceback;
163 var tb = json.traceback;
164 if (tb !== undefined && tb.length > 0) {
164 if (tb !== undefined && tb.length > 0) {
165 var s = '';
165 var s = '';
166 var len = tb.length;
166 var len = tb.length;
167 for (var i=0; i<len; i++) {
167 for (var i=0; i<len; i++) {
168 s = s + tb[i] + '\n';
168 s = s + tb[i] + '\n';
169 }
169 }
170 s = s + '\n';
170 s = s + '\n';
171 var toinsert = this.create_output_area();
171 var toinsert = this.create_output_area();
172 this.append_text(s, toinsert);
172 this.append_text(s, toinsert);
173 this.element.append(toinsert);
173 this.element.append(toinsert);
174 };
174 };
175 };
175 };
176
176
177
177
178 OutputArea.prototype.append_stream = function (json) {
178 OutputArea.prototype.append_stream = function (json) {
179 // temporary fix: if stream undefined (json file written prior to this patch),
179 // temporary fix: if stream undefined (json file written prior to this patch),
180 // default to most likely stdout:
180 // default to most likely stdout:
181 if (json.stream == undefined){
181 if (json.stream == undefined){
182 json.stream = 'stdout';
182 json.stream = 'stdout';
183 }
183 }
184 var text = json.text;
184 var text = json.text;
185 var subclass = "output_"+json.stream;
185 var subclass = "output_"+json.stream;
186 if (this.outputs.length > 0){
186 if (this.outputs.length > 0){
187 // have at least one output to consider
187 // have at least one output to consider
188 var last = this.outputs[this.outputs.length-1];
188 var last = this.outputs[this.outputs.length-1];
189 if (last.output_type == 'stream' && json.stream == last.stream){
189 if (last.output_type == 'stream' && json.stream == last.stream){
190 // latest output was in the same stream,
190 // latest output was in the same stream,
191 // so append directly into its pre tag
191 // so append directly into its pre tag
192 // escape ANSI & HTML specials:
192 // escape ANSI & HTML specials:
193 var pre = this.element.find('div.'+subclass).last().find('pre');
193 var pre = this.element.find('div.'+subclass).last().find('pre');
194 var html = utils.fixCarriageReturn(
194 var html = utils.fixCarriageReturn(
195 pre.html() + utils.fixConsole(text));
195 pre.html() + utils.fixConsole(text));
196 pre.html(html);
196 pre.html(html);
197 return;
197 return;
198 }
198 }
199 }
199 }
200
200
201 if (!text.replace("\r", "")) {
201 if (!text.replace("\r", "")) {
202 // text is nothing (empty string, \r, etc.)
202 // text is nothing (empty string, \r, etc.)
203 // so don't append any elements, which might add undesirable space
203 // so don't append any elements, which might add undesirable space
204 return;
204 return;
205 }
205 }
206
206
207 // If we got here, attach a new div
207 // If we got here, attach a new div
208 var toinsert = this.create_output_area();
208 var toinsert = this.create_output_area();
209 this.append_text(text, toinsert, "output_stream "+subclass);
209 this.append_text(text, toinsert, "output_stream "+subclass);
210 this.element.append(toinsert);
210 this.element.append(toinsert);
211 };
211 };
212
212
213
213
214 OutputArea.prototype.append_display_data = function (json, dynamic) {
214 OutputArea.prototype.append_display_data = function (json, dynamic) {
215 var toinsert = this.create_output_area();
215 var toinsert = this.create_output_area();
216 this.append_mime_type(json, toinsert, dynamic);
216 this.append_mime_type(json, toinsert, dynamic);
217 this.element.append(toinsert);
217 this.element.append(toinsert);
218 // If we just output latex, typeset it.
218 // If we just output latex, typeset it.
219 if ( (json.latex !== undefined) || (json.html !== undefined) ) {
219 if ( (json.latex !== undefined) || (json.html !== undefined) ) {
220 this.typeset();
220 this.typeset();
221 };
221 };
222 };
222 };
223
223
224
224
225 OutputArea.prototype.append_mime_type = function (json, element, dynamic) {
225 OutputArea.prototype.append_mime_type = function (json, element, dynamic) {
226 if (json.javascript !== undefined && dynamic) {
226 if (json.javascript !== undefined && dynamic) {
227 this.append_javascript(json.javascript, element, dynamic);
227 this.append_javascript(json.javascript, element, dynamic);
228 } else if (json.html !== undefined) {
228 } else if (json.html !== undefined) {
229 this.append_html(json.html, element);
229 this.append_html(json.html, element);
230 } else if (json.latex !== undefined) {
230 } else if (json.latex !== undefined) {
231 this.append_latex(json.latex, element);
231 this.append_latex(json.latex, element);
232 } else if (json.svg !== undefined) {
232 } else if (json.svg !== undefined) {
233 this.append_svg(json.svg, element);
233 this.append_svg(json.svg, element);
234 } else if (json.png !== undefined) {
234 } else if (json.png !== undefined) {
235 this.append_png(json.png, element);
235 this.append_png(json.png, element);
236 } else if (json.jpeg !== undefined) {
236 } else if (json.jpeg !== undefined) {
237 this.append_jpeg(json.jpeg, element);
237 this.append_jpeg(json.jpeg, element);
238 } else if (json.text !== undefined) {
238 } else if (json.text !== undefined) {
239 this.append_text(json.text, element);
239 this.append_text(json.text, element);
240 };
240 };
241 };
241 };
242
242
243
243
244 OutputArea.prototype.append_html = function (html, element) {
244 OutputArea.prototype.append_html = function (html, element) {
245 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_html rendered_html");
245 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_html rendered_html");
246 toinsert.append(html);
246 toinsert.append(html);
247 element.append(toinsert);
247 element.append(toinsert);
248 };
248 };
249
249
250
250
251 OutputArea.prototype.append_javascript = function (js, container) {
251 OutputArea.prototype.append_javascript = function (js, container) {
252 // We just eval the JS code, element appears in the local scope.
252 // We just eval the JS code, element appears in the local scope.
253 var element = $("<div/>").addClass("box-flex1 output_subarea");
253 var element = $("<div/>").addClass("box-flex1 output_subarea");
254 container.append(element);
254 container.append(element);
255 // Div for js shouldn't be drawn, as it will add empty height to the area.
255 // Div for js shouldn't be drawn, as it will add empty height to the area.
256 container.hide();
256 container.hide();
257 // If the Javascript appends content to `element` that should be drawn, then
257 // If the Javascript appends content to `element` that should be drawn, then
258 // it must also call `container.show()`.
258 // it must also call `container.show()`.
259 eval(js);
259 eval(js);
260 }
260 }
261
261
262
262
263 OutputArea.prototype.append_text = function (data, element, extra_class) {
263 OutputArea.prototype.append_text = function (data, element, extra_class) {
264 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_text");
264 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_text");
265 // escape ANSI & HTML specials in plaintext:
265 // escape ANSI & HTML specials in plaintext:
266 data = utils.fixConsole(data);
266 data = utils.fixConsole(data);
267 data = utils.fixCarriageReturn(data);
267 data = utils.fixCarriageReturn(data);
268 if (extra_class){
268 if (extra_class){
269 toinsert.addClass(extra_class);
269 toinsert.addClass(extra_class);
270 }
270 }
271 toinsert.append($("<pre/>").html(data));
271 toinsert.append($("<pre/>").html(data));
272 element.append(toinsert);
272 element.append(toinsert);
273 };
273 };
274
274
275
275
276 OutputArea.prototype.append_svg = function (svg, element) {
276 OutputArea.prototype.append_svg = function (svg, element) {
277 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_svg");
277 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_svg");
278 toinsert.append(svg);
278 toinsert.append(svg);
279 element.append(toinsert);
279 element.append(toinsert);
280 };
280 };
281
281
282
282
283 OutputArea.prototype.append_png = function (png, element) {
283 OutputArea.prototype.append_png = function (png, element) {
284 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_png");
284 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_png");
285 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
285 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
286 img.load(function () {
286 setTimeout(function () {
287 $(this).resizable({'aspectRatio': true, 'autoHide': true})
287 img.resizable({
288 });
288 aspectRatio: true,
289 autoHide: true,
290 start: function(evt, ui) {
291 var wrapper = $(evt.target);
292 var original_height = ui.originalSize.height;
293 var original_width = ui.originalSize.width;
294 if (original_height == 0 || original_width == 0) {
295 // protect against weird case of zero size;
296 return;
297 }
298 // only do this once:
299 wrapper.unbind("resizestart");
300 wrapper.dblclick(function () {
301 // resize wrapper & image together for some reason:
302 wrapper.height(original_height);
303 img.height(original_height);
304 wrapper.width(original_width);
305 img.width(original_width);
306 });
307 }
308 });
309 }, 250);
289 toinsert.append(img);
310 toinsert.append(img);
290 element.append(toinsert);
311 element.append(toinsert);
291 };
312 };
292
313
293
314
294 OutputArea.prototype.append_jpeg = function (jpeg, element) {
315 OutputArea.prototype.append_jpeg = function (jpeg, element) {
295 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_jpeg");
316 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_jpeg");
296 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
317 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
297 img.load(function () {
318 setTimeout(function () {
298 $(this).resizable({'aspectRatio': true, 'autoHide': true})
319 img.resizable({
299 });
320 aspectRatio: true,
321 autoHide: true,
322 start: function(evt, ui) {
323 var wrapper = $(evt.target);
324 var original_height = ui.originalSize.height;
325 var original_width = ui.originalSize.width;
326 if (original_height == 0 || original_width == 0) {
327 // protect against weird case of zero size;
328 return;
329 }
330 // only do this once:
331 wrapper.unbind("resizestart");
332 wrapper.dblclick(function () {
333 // resize wrapper & image together for some reason:
334 wrapper.height(original_height);
335 img.height(original_height);
336 wrapper.width(original_width);
337 img.width(original_width);
338 });
339 }
340 });
341 }, 250);
300 toinsert.append(img);
342 toinsert.append(img);
301 element.append(toinsert);
343 element.append(toinsert);
302 };
344 };
303
345
304
346
305 OutputArea.prototype.append_latex = function (latex, element) {
347 OutputArea.prototype.append_latex = function (latex, element) {
306 // This method cannot do the typesetting because the latex first has to
348 // This method cannot do the typesetting because the latex first has to
307 // be on the page.
349 // be on the page.
308 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_latex");
350 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_latex");
309 toinsert.append(latex);
351 toinsert.append(latex);
310 element.append(toinsert);
352 element.append(toinsert);
311 };
353 };
312
354
313
355
314 OutputArea.prototype.handle_clear_output = function (content) {
356 OutputArea.prototype.handle_clear_output = function (content) {
315 this.clear_output(content.stdout, content.stderr, content.other);
357 this.clear_output(content.stdout, content.stderr, content.other);
316 }
358 }
317
359
318
360
319 OutputArea.prototype.clear_output = function (stdout, stderr, other) {
361 OutputArea.prototype.clear_output = function (stdout, stderr, other) {
320 var that = this;
362 var that = this;
321 if (this.clear_out_timeout != null){
363 if (this.clear_out_timeout != null){
322 // fire previous pending clear *immediately*
364 // fire previous pending clear *immediately*
323 clearTimeout(this.clear_out_timeout);
365 clearTimeout(this.clear_out_timeout);
324 this.clear_out_timeout = null;
366 this.clear_out_timeout = null;
325 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
367 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
326 }
368 }
327 // store flags for flushing the timeout
369 // store flags for flushing the timeout
328 this._clear_stdout = stdout;
370 this._clear_stdout = stdout;
329 this._clear_stderr = stderr;
371 this._clear_stderr = stderr;
330 this._clear_other = other;
372 this._clear_other = other;
331 this.clear_out_timeout = setTimeout(function() {
373 this.clear_out_timeout = setTimeout(function() {
332 // really clear timeout only after a short delay
374 // really clear timeout only after a short delay
333 // this reduces flicker in 'clear_output; print' cases
375 // this reduces flicker in 'clear_output; print' cases
334 that.clear_out_timeout = null;
376 that.clear_out_timeout = null;
335 that._clear_stdout = that._clear_stderr = that._clear_other = null;
377 that._clear_stdout = that._clear_stderr = that._clear_other = null;
336 that.clear_output_callback(stdout, stderr, other);
378 that.clear_output_callback(stdout, stderr, other);
337 }, 500
379 }, 500
338 );
380 );
339 };
381 };
340
382
341
383
342 OutputArea.prototype.clear_output_callback = function (stdout, stderr, other) {
384 OutputArea.prototype.clear_output_callback = function (stdout, stderr, other) {
343 var output_div = this.element;
385 var output_div = this.element;
344
386
345 if (stdout && stderr && other){
387 if (stdout && stderr && other){
346 // clear all, no need for logic
388 // clear all, no need for logic
347 output_div.html("");
389 output_div.html("");
348 this.outputs = [];
390 this.outputs = [];
349 return;
391 return;
350 }
392 }
351 // remove html output
393 // remove html output
352 // each output_subarea that has an identifying class is in an output_area
394 // each output_subarea that has an identifying class is in an output_area
353 // which is the element to be removed.
395 // which is the element to be removed.
354 if (stdout) {
396 if (stdout) {
355 output_div.find("div.output_stdout").parent().remove();
397 output_div.find("div.output_stdout").parent().remove();
356 }
398 }
357 if (stderr) {
399 if (stderr) {
358 output_div.find("div.output_stderr").parent().remove();
400 output_div.find("div.output_stderr").parent().remove();
359 }
401 }
360 if (other) {
402 if (other) {
361 output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
403 output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
362 }
404 }
363
405
364 // remove cleared outputs from JSON list:
406 // remove cleared outputs from JSON list:
365 for (var i = this.outputs.length - 1; i >= 0; i--) {
407 for (var i = this.outputs.length - 1; i >= 0; i--) {
366 var out = this.outputs[i];
408 var out = this.outputs[i];
367 var output_type = out.output_type;
409 var output_type = out.output_type;
368 if (output_type == "display_data" && other) {
410 if (output_type == "display_data" && other) {
369 this.outputs.splice(i,1);
411 this.outputs.splice(i,1);
370 } else if (output_type == "stream") {
412 } else if (output_type == "stream") {
371 if (stdout && out.stream == "stdout") {
413 if (stdout && out.stream == "stdout") {
372 this.outputs.splice(i,1);
414 this.outputs.splice(i,1);
373 } else if (stderr && out.stream == "stderr") {
415 } else if (stderr && out.stream == "stderr") {
374 this.outputs.splice(i,1);
416 this.outputs.splice(i,1);
375 }
417 }
376 }
418 }
377 }
419 }
378 };
420 };
379
421
380
422
381 OutputArea.prototype.flush_clear_timeout = function() {
423 OutputArea.prototype.flush_clear_timeout = function() {
382 var output_div = this.element;
424 var output_div = this.element;
383 if (this.clear_out_timeout){
425 if (this.clear_out_timeout){
384 clearTimeout(this.clear_out_timeout);
426 clearTimeout(this.clear_out_timeout);
385 this.clear_out_timeout = null;
427 this.clear_out_timeout = null;
386 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
428 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
387 };
429 };
388 }
430 }
389
431
390
432
391 // JSON serialization
433 // JSON serialization
392
434
393 OutputArea.prototype.fromJSON = function (outputs) {
435 OutputArea.prototype.fromJSON = function (outputs) {
394 var len = outputs.length;
436 var len = outputs.length;
395 for (var i=0; i<len; i++) {
437 for (var i=0; i<len; i++) {
396 // append with dynamic=false.
438 // append with dynamic=false.
397 this.append_output(outputs[i], false);
439 this.append_output(outputs[i], false);
398 };
440 };
399 };
441 };
400
442
401
443
402 OutputArea.prototype.toJSON = function () {
444 OutputArea.prototype.toJSON = function () {
403 var outputs = [];
445 var outputs = [];
404 var len = this.outputs.length;
446 var len = this.outputs.length;
405 for (var i=0; i<len; i++) {
447 for (var i=0; i<len; i++) {
406 outputs[i] = this.outputs[i];
448 outputs[i] = this.outputs[i];
407 };
449 };
408 return outputs;
450 return outputs;
409 };
451 };
410
452
411
453
412 IPython.OutputArea = OutputArea;
454 IPython.OutputArea = OutputArea;
413
455
414 return IPython;
456 return IPython;
415
457
416 }(IPython));
458 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now