##// END OF EJS Templates
Make svg, jpeg and png images resizable in notebook.
Brian Granger -
Show More
@@ -1,408 +1,422
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 var img = $('<div/>');
279 img.append(svg);
280 var h = img.find('svg').attr('height');
281 var w = img.find('svg').attr('width');
282 img.width(w).height(h);
283 img.resizable({'aspectRatio': true});
284 toinsert.append(img);
279 element.append(toinsert);
285 element.append(toinsert);
280 };
286 };
281
287
282
288
283 OutputArea.prototype.append_png = function (png, element) {
289 OutputArea.prototype.append_png = function (png, element) {
284 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_png");
290 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_png");
285 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
291 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
292 img.load(function () {
293 $(this).resizable({'aspectRatio': true})
294 });
295 toinsert.append(img);
286 element.append(toinsert);
296 element.append(toinsert);
287 };
297 };
288
298
289
299
290 OutputArea.prototype.append_jpeg = function (jpeg, element) {
300 OutputArea.prototype.append_jpeg = function (jpeg, element) {
291 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_jpeg");
301 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_jpeg");
292 toinsert.append($("<img/>").attr('src','data:image/jpeg;base64,'+jpeg));
302 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
303 img.load(function () {
304 $(this).resizable({'aspectRatio': true})
305 });
306 toinsert.append(img);
293 element.append(toinsert);
307 element.append(toinsert);
294 };
308 };
295
309
296
310
297 OutputArea.prototype.append_latex = function (latex, element) {
311 OutputArea.prototype.append_latex = function (latex, element) {
298 // This method cannot do the typesetting because the latex first has to
312 // This method cannot do the typesetting because the latex first has to
299 // be on the page.
313 // be on the page.
300 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_latex");
314 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_latex");
301 toinsert.append(latex);
315 toinsert.append(latex);
302 element.append(toinsert);
316 element.append(toinsert);
303 };
317 };
304
318
305
319
306 OutputArea.prototype.handle_clear_output = function (content) {
320 OutputArea.prototype.handle_clear_output = function (content) {
307 this.clear_output(content.stdout, content.stderr, content.other);
321 this.clear_output(content.stdout, content.stderr, content.other);
308 }
322 }
309
323
310
324
311 OutputArea.prototype.clear_output = function (stdout, stderr, other) {
325 OutputArea.prototype.clear_output = function (stdout, stderr, other) {
312 var that = this;
326 var that = this;
313 if (this.clear_out_timeout != null){
327 if (this.clear_out_timeout != null){
314 // fire previous pending clear *immediately*
328 // fire previous pending clear *immediately*
315 clearTimeout(this.clear_out_timeout);
329 clearTimeout(this.clear_out_timeout);
316 this.clear_out_timeout = null;
330 this.clear_out_timeout = null;
317 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
331 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
318 }
332 }
319 // store flags for flushing the timeout
333 // store flags for flushing the timeout
320 this._clear_stdout = stdout;
334 this._clear_stdout = stdout;
321 this._clear_stderr = stderr;
335 this._clear_stderr = stderr;
322 this._clear_other = other;
336 this._clear_other = other;
323 this.clear_out_timeout = setTimeout(function() {
337 this.clear_out_timeout = setTimeout(function() {
324 // really clear timeout only after a short delay
338 // really clear timeout only after a short delay
325 // this reduces flicker in 'clear_output; print' cases
339 // this reduces flicker in 'clear_output; print' cases
326 that.clear_out_timeout = null;
340 that.clear_out_timeout = null;
327 that._clear_stdout = that._clear_stderr = that._clear_other = null;
341 that._clear_stdout = that._clear_stderr = that._clear_other = null;
328 that.clear_output_callback(stdout, stderr, other);
342 that.clear_output_callback(stdout, stderr, other);
329 }, 500
343 }, 500
330 );
344 );
331 };
345 };
332
346
333
347
334 OutputArea.prototype.clear_output_callback = function (stdout, stderr, other) {
348 OutputArea.prototype.clear_output_callback = function (stdout, stderr, other) {
335 var output_div = this.element;
349 var output_div = this.element;
336
350
337 if (stdout && stderr && other){
351 if (stdout && stderr && other){
338 // clear all, no need for logic
352 // clear all, no need for logic
339 output_div.html("");
353 output_div.html("");
340 this.outputs = [];
354 this.outputs = [];
341 return;
355 return;
342 }
356 }
343 // remove html output
357 // remove html output
344 // each output_subarea that has an identifying class is in an output_area
358 // each output_subarea that has an identifying class is in an output_area
345 // which is the element to be removed.
359 // which is the element to be removed.
346 if (stdout) {
360 if (stdout) {
347 output_div.find("div.output_stdout").parent().remove();
361 output_div.find("div.output_stdout").parent().remove();
348 }
362 }
349 if (stderr) {
363 if (stderr) {
350 output_div.find("div.output_stderr").parent().remove();
364 output_div.find("div.output_stderr").parent().remove();
351 }
365 }
352 if (other) {
366 if (other) {
353 output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
367 output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
354 }
368 }
355
369
356 // remove cleared outputs from JSON list:
370 // remove cleared outputs from JSON list:
357 for (var i = this.outputs.length - 1; i >= 0; i--) {
371 for (var i = this.outputs.length - 1; i >= 0; i--) {
358 var out = this.outputs[i];
372 var out = this.outputs[i];
359 var output_type = out.output_type;
373 var output_type = out.output_type;
360 if (output_type == "display_data" && other) {
374 if (output_type == "display_data" && other) {
361 this.outputs.splice(i,1);
375 this.outputs.splice(i,1);
362 } else if (output_type == "stream") {
376 } else if (output_type == "stream") {
363 if (stdout && out.stream == "stdout") {
377 if (stdout && out.stream == "stdout") {
364 this.outputs.splice(i,1);
378 this.outputs.splice(i,1);
365 } else if (stderr && out.stream == "stderr") {
379 } else if (stderr && out.stream == "stderr") {
366 this.outputs.splice(i,1);
380 this.outputs.splice(i,1);
367 }
381 }
368 }
382 }
369 }
383 }
370 };
384 };
371
385
372
386
373 OutputArea.prototype.flush_clear_timeout = function() {
387 OutputArea.prototype.flush_clear_timeout = function() {
374 var output_div = this.element;
388 var output_div = this.element;
375 if (this.clear_out_timeout){
389 if (this.clear_out_timeout){
376 clearTimeout(this.clear_out_timeout);
390 clearTimeout(this.clear_out_timeout);
377 this.clear_out_timeout = null;
391 this.clear_out_timeout = null;
378 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
392 this.clear_output_callback(this._clear_stdout, this._clear_stderr, this._clear_other);
379 };
393 };
380 }
394 }
381
395
382
396
383 // JSON serialization
397 // JSON serialization
384
398
385 OutputArea.prototype.fromJSON = function (outputs) {
399 OutputArea.prototype.fromJSON = function (outputs) {
386 var len = outputs.length;
400 var len = outputs.length;
387 for (var i=0; i<len; i++) {
401 for (var i=0; i<len; i++) {
388 // append with dynamic=false.
402 // append with dynamic=false.
389 this.append_output(outputs[i], false);
403 this.append_output(outputs[i], false);
390 };
404 };
391 };
405 };
392
406
393
407
394 OutputArea.prototype.toJSON = function () {
408 OutputArea.prototype.toJSON = function () {
395 var outputs = [];
409 var outputs = [];
396 var len = this.outputs.length;
410 var len = this.outputs.length;
397 for (var i=0; i<len; i++) {
411 for (var i=0; i<len; i++) {
398 outputs[i] = this.outputs[i];
412 outputs[i] = this.outputs[i];
399 };
413 };
400 return outputs;
414 return outputs;
401 };
415 };
402
416
403
417
404 IPython.OutputArea = OutputArea;
418 IPython.OutputArea = OutputArea;
405
419
406 return IPython;
420 return IPython;
407
421
408 }(IPython));
422 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now