##// END OF EJS Templates
passthrough unrecognized output mime-types...
MinRK -
Show More
@@ -1,759 +1,741 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // OutputArea
10 10 //============================================================================
11 11
12 12 /**
13 13 * @module IPython
14 14 * @namespace IPython
15 15 * @submodule OutputArea
16 16 */
17 17 var IPython = (function (IPython) {
18 18 "use strict";
19 19
20 20 var utils = IPython.utils;
21 21
22 22 /**
23 23 * @class OutputArea
24 24 *
25 25 * @constructor
26 26 */
27 27
28 28 var OutputArea = function (selector, prompt_area) {
29 29 this.selector = selector;
30 30 this.wrapper = $(selector);
31 31 this.outputs = [];
32 32 this.collapsed = false;
33 33 this.scrolled = false;
34 34 this.clear_queued = null;
35 35 if (prompt_area === undefined) {
36 36 this.prompt_area = true;
37 37 } else {
38 38 this.prompt_area = prompt_area;
39 39 }
40 40 this.create_elements();
41 41 this.style();
42 42 this.bind_events();
43 43 };
44 44
45 45 OutputArea.prototype.create_elements = function () {
46 46 this.element = $("<div/>");
47 47 this.collapse_button = $("<div/>");
48 48 this.prompt_overlay = $("<div/>");
49 49 this.wrapper.append(this.prompt_overlay);
50 50 this.wrapper.append(this.element);
51 51 this.wrapper.append(this.collapse_button);
52 52 };
53 53
54 54
55 55 OutputArea.prototype.style = function () {
56 56 this.collapse_button.hide();
57 57 this.prompt_overlay.hide();
58 58
59 59 this.wrapper.addClass('output_wrapper');
60 60 this.element.addClass('output');
61 61
62 62 this.collapse_button.addClass("btn output_collapsed");
63 63 this.collapse_button.attr('title', 'click to expand output');
64 64 this.collapse_button.html('. . .');
65 65
66 66 this.prompt_overlay.addClass('out_prompt_overlay prompt');
67 67 this.prompt_overlay.attr('title', 'click to expand output; double click to hide output');
68 68
69 69 this.collapse();
70 70 };
71 71
72 72 /**
73 73 * Should the OutputArea scroll?
74 74 * Returns whether the height (in lines) exceeds a threshold.
75 75 *
76 76 * @private
77 77 * @method _should_scroll
78 78 * @param [lines=100]{Integer}
79 79 * @return {Bool}
80 80 *
81 81 */
82 82 OutputArea.prototype._should_scroll = function (lines) {
83 83 if (lines <=0 ){ return }
84 84 if (!lines) {
85 85 lines = 100;
86 86 }
87 87 // line-height from http://stackoverflow.com/questions/1185151
88 88 var fontSize = this.element.css('font-size');
89 89 var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5);
90 90
91 91 return (this.element.height() > lines * lineHeight);
92 92 };
93 93
94 94
95 95 OutputArea.prototype.bind_events = function () {
96 96 var that = this;
97 97 this.prompt_overlay.dblclick(function () { that.toggle_output(); });
98 98 this.prompt_overlay.click(function () { that.toggle_scroll(); });
99 99
100 100 this.element.resize(function () {
101 101 // FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled
102 102 if ( IPython.utils.browser[0] === "Firefox" ) {
103 103 return;
104 104 }
105 105 // maybe scroll output,
106 106 // if it's grown large enough and hasn't already been scrolled.
107 107 if ( !that.scrolled && that._should_scroll(OutputArea.auto_scroll_threshold)) {
108 108 that.scroll_area();
109 109 }
110 110 });
111 111 this.collapse_button.click(function () {
112 112 that.expand();
113 113 });
114 114 };
115 115
116 116
117 117 OutputArea.prototype.collapse = function () {
118 118 if (!this.collapsed) {
119 119 this.element.hide();
120 120 this.prompt_overlay.hide();
121 121 if (this.element.html()){
122 122 this.collapse_button.show();
123 123 }
124 124 this.collapsed = true;
125 125 }
126 126 };
127 127
128 128
129 129 OutputArea.prototype.expand = function () {
130 130 if (this.collapsed) {
131 131 this.collapse_button.hide();
132 132 this.element.show();
133 133 this.prompt_overlay.show();
134 134 this.collapsed = false;
135 135 }
136 136 };
137 137
138 138
139 139 OutputArea.prototype.toggle_output = function () {
140 140 if (this.collapsed) {
141 141 this.expand();
142 142 } else {
143 143 this.collapse();
144 144 }
145 145 };
146 146
147 147
148 148 OutputArea.prototype.scroll_area = function () {
149 149 this.element.addClass('output_scroll');
150 150 this.prompt_overlay.attr('title', 'click to unscroll output; double click to hide');
151 151 this.scrolled = true;
152 152 };
153 153
154 154
155 155 OutputArea.prototype.unscroll_area = function () {
156 156 this.element.removeClass('output_scroll');
157 157 this.prompt_overlay.attr('title', 'click to scroll output; double click to hide');
158 158 this.scrolled = false;
159 159 };
160 160
161 161 /**
162 162 * Threshold to trigger autoscroll when the OutputArea is resized,
163 163 * typically when new outputs are added.
164 164 *
165 165 * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold,
166 166 * unless it is < 0, in which case autoscroll will never be triggered
167 167 *
168 168 * @property auto_scroll_threshold
169 169 * @type Number
170 170 * @default 100
171 171 *
172 172 **/
173 173 OutputArea.auto_scroll_threshold = 100;
174 174
175 175
176 176 /**
177 177 * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas
178 178 * shorter than this are never scrolled.
179 179 *
180 180 * @property minimum_scroll_threshold
181 181 * @type Number
182 182 * @default 20
183 183 *
184 184 **/
185 185 OutputArea.minimum_scroll_threshold = 20;
186 186
187 187
188 188 /**
189 189 *
190 190 * Scroll OutputArea if height supperior than a threshold (in lines).
191 191 *
192 192 * Threshold is a maximum number of lines. If unspecified, defaults to
193 193 * OutputArea.minimum_scroll_threshold.
194 194 *
195 195 * Negative threshold will prevent the OutputArea from ever scrolling.
196 196 *
197 197 * @method scroll_if_long
198 198 *
199 199 * @param [lines=20]{Number} Default to 20 if not set,
200 200 * behavior undefined for value of `0`.
201 201 *
202 202 **/
203 203 OutputArea.prototype.scroll_if_long = function (lines) {
204 204 var n = lines | OutputArea.minimum_scroll_threshold;
205 205 if(n <= 0){
206 206 return
207 207 }
208 208
209 209 if (this._should_scroll(n)) {
210 210 // only allow scrolling long-enough output
211 211 this.scroll_area();
212 212 }
213 213 };
214 214
215 215
216 216 OutputArea.prototype.toggle_scroll = function () {
217 217 if (this.scrolled) {
218 218 this.unscroll_area();
219 219 } else {
220 220 // only allow scrolling long-enough output
221 221 this.scroll_if_long();
222 222 }
223 223 };
224 224
225 225
226 226 // typeset with MathJax if MathJax is available
227 227 OutputArea.prototype.typeset = function () {
228 228 if (window.MathJax){
229 229 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
230 230 }
231 231 };
232 232
233 233
234 234 OutputArea.prototype.handle_output = function (msg) {
235 235 var json = {};
236 236 var msg_type = json.output_type = msg.header.msg_type;
237 237 var content = msg.content;
238 238 if (msg_type === "stream") {
239 239 json.text = content.data;
240 240 json.stream = content.name;
241 241 } else if (msg_type === "display_data") {
242 242 json = this.convert_mime_types(json, content.data);
243 243 json.metadata = this.convert_mime_types({}, content.metadata);
244 244 } else if (msg_type === "pyout") {
245 245 json.prompt_number = content.execution_count;
246 246 json = this.convert_mime_types(json, content.data);
247 247 json.metadata = this.convert_mime_types({}, content.metadata);
248 248 } else if (msg_type === "pyerr") {
249 249 json.ename = content.ename;
250 250 json.evalue = content.evalue;
251 251 json.traceback = content.traceback;
252 252 }
253 253 // append with dynamic=true
254 254 this.append_output(json, true);
255 255 };
256 256
257 var mime_types = ['application/javascript', 'application/json',
258 'image/jpeg', 'image/png', 'image/svg+xml', 'text/html',
259 'text/latex', 'text/plain'];
257 OutputArea.mime_map = {
258 "text/plain" : "text",
259 "text/html" : "html",
260 "image/svg+xml" : "svg",
261 "image/png" : "png",
262 "image/jpeg" : "jpeg",
263 "text/latex" : "latex",
264 "application/json" : "json",
265 "application/javascript" : "javascript",
266 };
260 267
261 268 OutputArea.prototype.convert_mime_types = function (json, data) {
262 if (data === undefined) {
269 if (!data) {
263 270 return json;
264 271 }
265 if (data['text/plain'] !== undefined) {
266 json.text = data['text/plain'];
267 }
268 if (data['text/html'] !== undefined) {
269 json.html = data['text/html'];
270 }
271 if (data['image/svg+xml'] !== undefined) {
272 json.svg = data['image/svg+xml'];
273 }
274 if (data['image/png'] !== undefined) {
275 json.png = data['image/png'];
276 }
277 if (data['image/jpeg'] !== undefined) {
278 json.jpeg = data['image/jpeg'];
279 }
280 if (data['text/latex'] !== undefined) {
281 json.latex = data['text/latex'];
282 }
283 if (data['application/json'] !== undefined) {
284 json.json = data['application/json'];
285 }
286 if (data['application/javascript'] !== undefined) {
287 json.javascript = data['application/javascript'];
288 }
289 272 // non-mimetype-keyed metadata used to get dropped here, this code
290 273 // re-injects it into the json.
291 for (x in data){
292 if( !(x in mime_types) ) {
293 json[x] = data[x];
294 }
274 for (var key in data) {
275 var json_key = OutputArea.mime_map[key] || key;
276 json[json_key] = data[key];
295 277 }
296 278 return json;
297 279 };
298 280
299 281
300 282 OutputArea.prototype.append_output = function (json, dynamic) {
301 283 // If dynamic is true, javascript output will be eval'd.
302 284 this.expand();
303 285 // Clear the output if clear is queued.
304 286 var needs_height_reset = false;
305 287 if (this.clear_queued) {
306 288 this.clear_output(false);
307 289 needs_height_reset = true;
308 290 }
309 291
310 292 if (json.output_type === 'pyout') {
311 293 this.append_pyout(json, dynamic);
312 294 } else if (json.output_type === 'pyerr') {
313 295 this.append_pyerr(json);
314 296 } else if (json.output_type === 'display_data') {
315 297 this.append_display_data(json, dynamic);
316 298 } else if (json.output_type === 'stream') {
317 299 this.append_stream(json);
318 300 }
319 301 this.outputs.push(json);
320 302
321 303 // Only reset the height to automatic if the height is currently
322 304 // fixed (done by wait=True flag on clear_output).
323 305 if (needs_height_reset) {
324 306 this.element.height('');
325 307 }
326 308
327 309 var that = this;
328 310 setTimeout(function(){that.element.trigger('resize');}, 100);
329 311 };
330 312
331 313
332 314 OutputArea.prototype.create_output_area = function () {
333 315 var oa = $("<div/>").addClass("output_area");
334 316 if (this.prompt_area) {
335 317 oa.append($('<div/>').addClass('prompt'));
336 318 }
337 319 return oa;
338 320 };
339 321
340 322
341 323 OutputArea.prototype.create_output_subarea = function(md, classes) {
342 324 var subarea = $('<div/>').addClass('output_subarea').addClass(classes);
343 325 if (md['isolated']) {
344 326 // Create an iframe to isolate the subarea from the rest of the
345 327 // document
346 328 var iframe = $('<iframe/>').addClass('box-flex1');
347 329 iframe.css({'height':1, 'width':'100%', 'display':'block'});
348 330 iframe.attr('frameborder', 0);
349 331 iframe.attr('scrolling', 'auto');
350 332
351 333 // Once the iframe is loaded, the subarea is dynamically inserted
352 334 iframe.on('load', function() {
353 335 // Workaround needed by Firefox, to properly render svg inside
354 336 // iframes, see http://stackoverflow.com/questions/10177190/
355 337 // svg-dynamically-added-to-iframe-does-not-render-correctly
356 338 this.contentDocument.open();
357 339
358 340 // Insert the subarea into the iframe
359 341 // We must directly write the html. When using Jquery's append
360 342 // method, javascript is evaluated in the parent document and
361 343 // not in the iframe document.
362 344 this.contentDocument.write(subarea.html());
363 345
364 346 this.contentDocument.close();
365 347
366 348 var body = this.contentDocument.body;
367 349 // Adjust the iframe height automatically
368 350 iframe.height(body.scrollHeight + 'px');
369 351 });
370 352
371 353 // Elements should be appended to the inner subarea and not to the
372 354 // iframe
373 355 iframe.append = function(that) {
374 356 subarea.append(that);
375 357 };
376 358
377 359 return iframe;
378 360 } else {
379 361 return subarea;
380 362 }
381 363 }
382 364
383 365
384 366 OutputArea.prototype._append_javascript_error = function (err, element) {
385 367 // display a message when a javascript error occurs in display output
386 368 var msg = "Javascript error adding output!"
387 369 if ( element === undefined ) return;
388 370 element.append(
389 371 $('<div/>').html(msg + "<br/>" +
390 372 err.toString() +
391 373 '<br/>See your browser Javascript console for more details.'
392 374 ).addClass('js-error')
393 375 );
394 376 };
395 377
396 378 OutputArea.prototype._safe_append = function (toinsert) {
397 379 // safely append an item to the document
398 380 // this is an object created by user code,
399 381 // and may have errors, which should not be raised
400 382 // under any circumstances.
401 383 try {
402 384 this.element.append(toinsert);
403 385 } catch(err) {
404 386 console.log(err);
405 387 // Create an actual output_area and output_subarea, which creates
406 388 // the prompt area and the proper indentation.
407 389 var toinsert = this.create_output_area();
408 390 var subarea = $('<div/>').addClass('output_subarea');
409 391 toinsert.append(subarea);
410 392 this._append_javascript_error(err, subarea);
411 393 this.element.append(toinsert);
412 394 }
413 395 };
414 396
415 397
416 398 OutputArea.prototype.append_pyout = function (json, dynamic) {
417 399 var n = json.prompt_number || ' ';
418 400 var toinsert = this.create_output_area();
419 401 if (this.prompt_area) {
420 402 toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
421 403 }
422 404 this.append_mime_type(json, toinsert, dynamic);
423 405 this._safe_append(toinsert);
424 406 // If we just output latex, typeset it.
425 407 if ((json.latex !== undefined) || (json.html !== undefined)) {
426 408 this.typeset();
427 409 }
428 410 };
429 411
430 412
431 413 OutputArea.prototype.append_pyerr = function (json) {
432 414 var tb = json.traceback;
433 415 if (tb !== undefined && tb.length > 0) {
434 416 var s = '';
435 417 var len = tb.length;
436 418 for (var i=0; i<len; i++) {
437 419 s = s + tb[i] + '\n';
438 420 }
439 421 s = s + '\n';
440 422 var toinsert = this.create_output_area();
441 423 this.append_text(s, {}, toinsert);
442 424 this._safe_append(toinsert);
443 425 }
444 426 };
445 427
446 428
447 429 OutputArea.prototype.append_stream = function (json) {
448 430 // temporary fix: if stream undefined (json file written prior to this patch),
449 431 // default to most likely stdout:
450 432 if (json.stream == undefined){
451 433 json.stream = 'stdout';
452 434 }
453 435 var text = json.text;
454 436 var subclass = "output_"+json.stream;
455 437 if (this.outputs.length > 0){
456 438 // have at least one output to consider
457 439 var last = this.outputs[this.outputs.length-1];
458 440 if (last.output_type == 'stream' && json.stream == last.stream){
459 441 // latest output was in the same stream,
460 442 // so append directly into its pre tag
461 443 // escape ANSI & HTML specials:
462 444 var pre = this.element.find('div.'+subclass).last().find('pre');
463 445 var html = utils.fixCarriageReturn(
464 446 pre.html() + utils.fixConsole(text));
465 447 pre.html(html);
466 448 return;
467 449 }
468 450 }
469 451
470 452 if (!text.replace("\r", "")) {
471 453 // text is nothing (empty string, \r, etc.)
472 454 // so don't append any elements, which might add undesirable space
473 455 return;
474 456 }
475 457
476 458 // If we got here, attach a new div
477 459 var toinsert = this.create_output_area();
478 460 this.append_text(text, {}, toinsert, "output_stream "+subclass);
479 461 this._safe_append(toinsert);
480 462 };
481 463
482 464
483 465 OutputArea.prototype.append_display_data = function (json, dynamic) {
484 466 var toinsert = this.create_output_area();
485 467 if (this.append_mime_type(json, toinsert, dynamic)) {
486 468 this._safe_append(toinsert);
487 469 // If we just output latex, typeset it.
488 470 if ( (json.latex !== undefined) || (json.html !== undefined) ) {
489 471 this.typeset();
490 472 }
491 473 }
492 474 };
493 475
494 476 OutputArea.display_order = ['javascript','html','latex','svg','png','jpeg','text'];
495 477
496 478 OutputArea.prototype.append_mime_type = function (json, element, dynamic) {
497 479 for(var type_i in OutputArea.display_order){
498 480 var type = OutputArea.display_order[type_i];
499 481 if(json[type] != undefined ){
500 482 var md = {};
501 483 if (json.metadata) {
502 484 md = json.metadata;
503 485 if (json.metadata[type]) {
504 486 // XXX: need some sort of dict.update, style here if
505 487 // we want to support the merging of the overall
506 488 // metadata with the mimetype specific metadata. For
507 489 // now, they are mutually exclusive - if the
508 490 // mimetype-keyed metadata exists, *it* is used,
509 491 // otherwise, only the message-wide metadata is
510 492 // available.
511 493 md = json.metadata[type];
512 494 }
513 495 }
514 496 if(type == 'javascript'){
515 497 if (dynamic) {
516 498 this.append_javascript(json.javascript, md, element, dynamic);
517 499 return true;
518 500 }
519 501 } else {
520 502 this['append_'+type](json[type], md, element);
521 503 return true;
522 504 }
523 505 return false;
524 506 }
525 507 }
526 508 return false;
527 509 };
528 510
529 511
530 512 OutputArea.prototype.append_html = function (html, md, element) {
531 513 var toinsert = this.create_output_subarea(md, "output_html rendered_html");
532 514 IPython.keyboard_manager.register_events(toinsert);
533 515 toinsert.append(html);
534 516 element.append(toinsert);
535 517 };
536 518
537 519
538 520 OutputArea.prototype.append_javascript = function (js, md, container) {
539 521 // We just eval the JS code, element appears in the local scope.
540 522 var element = this.create_output_subarea(md, "output_javascript");
541 523 IPython.keyboard_manager.register_events(element);
542 524 container.append(element);
543 525 try {
544 526 eval(js);
545 527 } catch(err) {
546 528 console.log(err);
547 529 this._append_javascript_error(err, element);
548 530 }
549 531 };
550 532
551 533
552 534 OutputArea.prototype.append_text = function (data, md, element, extra_class) {
553 535 var toinsert = this.create_output_subarea(md, "output_text");
554 536 // escape ANSI & HTML specials in plaintext:
555 537 data = utils.fixConsole(data);
556 538 data = utils.fixCarriageReturn(data);
557 539 data = utils.autoLinkUrls(data);
558 540 if (extra_class){
559 541 toinsert.addClass(extra_class);
560 542 }
561 543 toinsert.append($("<pre/>").html(data));
562 544 element.append(toinsert);
563 545 };
564 546
565 547
566 548 OutputArea.prototype.append_svg = function (svg, md, element) {
567 549 var toinsert = this.create_output_subarea(md, "output_svg");
568 550 toinsert.append(svg);
569 551 element.append(toinsert);
570 552 };
571 553
572 554
573 555 OutputArea.prototype._dblclick_to_reset_size = function (img) {
574 556 // schedule wrapping image in resizable after a delay,
575 557 // so we don't end up calling resize on a zero-size object
576 558 var that = this;
577 559 setTimeout(function () {
578 560 var h0 = img.height();
579 561 var w0 = img.width();
580 562 if (!(h0 && w0)) {
581 563 // zero size, schedule another timeout
582 564 that._dblclick_to_reset_size(img);
583 565 return;
584 566 }
585 567 img.resizable({
586 568 aspectRatio: true,
587 569 autoHide: true
588 570 });
589 571 img.dblclick(function () {
590 572 // resize wrapper & image together for some reason:
591 573 img.parent().height(h0);
592 574 img.height(h0);
593 575 img.parent().width(w0);
594 576 img.width(w0);
595 577 });
596 578 }, 250);
597 579 };
598 580
599 581
600 582 OutputArea.prototype.append_png = function (png, md, element) {
601 583 var toinsert = this.create_output_subarea(md, "output_png");
602 584 var img = $("<img/>");
603 585 img[0].setAttribute('src','data:image/png;base64,'+png);
604 586 if (md['height']) {
605 587 img[0].setAttribute('height', md['height']);
606 588 }
607 589 if (md['width']) {
608 590 img[0].setAttribute('width', md['width']);
609 591 }
610 592 this._dblclick_to_reset_size(img);
611 593 toinsert.append(img);
612 594 element.append(toinsert);
613 595 };
614 596
615 597
616 598 OutputArea.prototype.append_jpeg = function (jpeg, md, element) {
617 599 var toinsert = this.create_output_subarea(md, "output_jpeg");
618 600 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
619 601 if (md['height']) {
620 602 img.attr('height', md['height']);
621 603 }
622 604 if (md['width']) {
623 605 img.attr('width', md['width']);
624 606 }
625 607 this._dblclick_to_reset_size(img);
626 608 toinsert.append(img);
627 609 element.append(toinsert);
628 610 };
629 611
630 612
631 613 OutputArea.prototype.append_latex = function (latex, md, element) {
632 614 // This method cannot do the typesetting because the latex first has to
633 615 // be on the page.
634 616 var toinsert = this.create_output_subarea(md, "output_latex");
635 617 toinsert.append(latex);
636 618 element.append(toinsert);
637 619 };
638 620
639 621 OutputArea.prototype.append_raw_input = function (msg) {
640 622 var that = this;
641 623 this.expand();
642 624 var content = msg.content;
643 625 var area = this.create_output_area();
644 626
645 627 // disable any other raw_inputs, if they are left around
646 628 $("div.output_subarea.raw_input").remove();
647 629
648 630 area.append(
649 631 $("<div/>")
650 632 .addClass("box-flex1 output_subarea raw_input")
651 633 .append(
652 634 $("<span/>")
653 635 .addClass("input_prompt")
654 636 .text(content.prompt)
655 637 )
656 638 .append(
657 639 $("<input/>")
658 640 .addClass("raw_input")
659 641 .attr('type', 'text')
660 642 .attr("size", 47)
661 643 .keydown(function (event, ui) {
662 644 // make sure we submit on enter,
663 645 // and don't re-execute the *cell* on shift-enter
664 646 if (event.which === utils.keycodes.ENTER) {
665 647 that._submit_raw_input();
666 648 return false;
667 649 }
668 650 })
669 651 )
670 652 );
671 653
672 654 this.element.append(area);
673 655 var raw_input = area.find('input.raw_input');
674 656 // Register events that enable/disable the keyboard manager while raw
675 657 // input is focused.
676 658 IPython.keyboard_manager.register_events(raw_input);
677 659 // Note, the following line used to read raw_input.focus().focus().
678 660 // This seemed to be needed otherwise only the cell would be focused.
679 661 // But with the modal UI, this seems to work fine with one call to focus().
680 662 raw_input.focus();
681 663 }
682 664
683 665 OutputArea.prototype._submit_raw_input = function (evt) {
684 666 var container = this.element.find("div.raw_input");
685 667 var theprompt = container.find("span.input_prompt");
686 668 var theinput = container.find("input.raw_input");
687 669 var value = theinput.val();
688 670 var content = {
689 671 output_type : 'stream',
690 672 name : 'stdout',
691 673 text : theprompt.text() + value + '\n'
692 674 }
693 675 // remove form container
694 676 container.parent().remove();
695 677 // replace with plaintext version in stdout
696 678 this.append_output(content, false);
697 679 $([IPython.events]).trigger('send_input_reply.Kernel', value);
698 680 }
699 681
700 682
701 683 OutputArea.prototype.handle_clear_output = function (msg) {
702 684 this.clear_output(msg.content.wait);
703 685 };
704 686
705 687
706 688 OutputArea.prototype.clear_output = function(wait) {
707 689 if (wait) {
708 690
709 691 // If a clear is queued, clear before adding another to the queue.
710 692 if (this.clear_queued) {
711 693 this.clear_output(false);
712 694 };
713 695
714 696 this.clear_queued = true;
715 697 } else {
716 698
717 699 // Fix the output div's height if the clear_output is waiting for
718 700 // new output (it is being used in an animation).
719 701 if (this.clear_queued) {
720 702 var height = this.element.height();
721 703 this.element.height(height);
722 704 this.clear_queued = false;
723 705 }
724 706
725 707 // clear all, no need for logic
726 708 this.element.html("");
727 709 this.outputs = [];
728 710 this.unscroll_area();
729 711 return;
730 712 };
731 713 };
732 714
733 715
734 716 // JSON serialization
735 717
736 718 OutputArea.prototype.fromJSON = function (outputs) {
737 719 var len = outputs.length;
738 720 for (var i=0; i<len; i++) {
739 721 // append with dynamic=false.
740 722 this.append_output(outputs[i], false);
741 723 }
742 724 };
743 725
744 726
745 727 OutputArea.prototype.toJSON = function () {
746 728 var outputs = [];
747 729 var len = this.outputs.length;
748 730 for (var i=0; i<len; i++) {
749 731 outputs[i] = this.outputs[i];
750 732 }
751 733 return outputs;
752 734 };
753 735
754 736
755 737 IPython.OutputArea = OutputArea;
756 738
757 739 return IPython;
758 740
759 741 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now