##// END OF EJS Templates
Use .load() to resize
jon -
Show More
@@ -278,6 +278,20 var IPython = (function (IPython) {
278 needs_height_reset = true;
278 needs_height_reset = true;
279 }
279 }
280
280
281 // We must release the animation fixed height in a callback since Gecko
282 // (FireFox) doesn't render the image immediately as the data is
283 // available.
284 var that = this;
285 var handle_appended = function () {
286 // Only reset the height to automatic if the height is currently
287 // fixed (done by wait=True flag on clear_output).
288 console.log('appended');
289 if (needs_height_reset) {
290 that.element.height('');
291 }
292 that.element.trigger('resize');
293 };
294
281 // validate output data types
295 // validate output data types
282 json = this.validate_output(json);
296 json = this.validate_output(json);
283
297
@@ -285,26 +299,18 var IPython = (function (IPython) {
285 this.append_pyout(json);
299 this.append_pyout(json);
286 } else if (json.output_type === 'pyerr') {
300 } else if (json.output_type === 'pyerr') {
287 this.append_pyerr(json);
301 this.append_pyerr(json);
288 } else if (json.output_type === 'display_data') {
289 this.append_display_data(json);
290 } else if (json.output_type === 'stream') {
302 } else if (json.output_type === 'stream') {
291 this.append_stream(json);
303 this.append_stream(json);
292 }
304 }
305
306 if (json.output_type === 'display_data') {
307 this.append_display_data(json, handle_appended);
308 } else {
309 handle_appended();
310 }
293
311
294 this.outputs.push(json);
312 this.outputs.push(json);
295
313
296 // We must release the animation fixed height in a timeout since Gecko
297 // (FireFox) doesn't render the image immediately as the data is
298 // available.
299 var that = this;
300 setTimeout(function(){
301 // Only reset the height to automatic if the height is currently
302 // fixed (done by wait=True flag on clear_output).
303 if (needs_height_reset) {
304 that.element.height('');
305 }
306 that.element.trigger('resize');
307 }, 250);
308 };
314 };
309
315
310
316
@@ -479,9 +485,9 var IPython = (function (IPython) {
479 };
485 };
480
486
481
487
482 OutputArea.prototype.append_display_data = function (json) {
488 OutputArea.prototype.append_display_data = function (json, handle_inserted) {
483 var toinsert = this.create_output_area();
489 var toinsert = this.create_output_area();
484 if (this.append_mime_type(json, toinsert)) {
490 if (this.append_mime_type(json, toinsert, handle_inserted)) {
485 this._safe_append(toinsert);
491 this._safe_append(toinsert);
486 // If we just output latex, typeset it.
492 // If we just output latex, typeset it.
487 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
493 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
@@ -498,7 +504,7 var IPython = (function (IPython) {
498 'image/jpeg' : true
504 'image/jpeg' : true
499 };
505 };
500
506
501 OutputArea.prototype.append_mime_type = function (json, element) {
507 OutputArea.prototype.append_mime_type = function (json, element, handle_inserted) {
502 for (var type_i in OutputArea.display_order) {
508 for (var type_i in OutputArea.display_order) {
503 var type = OutputArea.display_order[type_i];
509 var type = OutputArea.display_order[type_i];
504 var append = OutputArea.append_map[type];
510 var append = OutputArea.append_map[type];
@@ -515,7 +521,14 var IPython = (function (IPython) {
515 }
521 }
516 }
522 }
517 var md = json.metadata || {};
523 var md = json.metadata || {};
518 var toinsert = append.apply(this, [value, md, element]);
524 var toinsert = append.apply(this, [value, md, element, handle_inserted]);
525 // Since only the png and jpeg mime types call the inserted
526 // callback, if the mim type is something other we must call the
527 // inserted callback only when the element is actually inserted
528 // into the DOM. Use a timeout of 0 to do this.
529 if (['image/png', 'image/jpeg'].indexOf() < 0 && handle_inserted !== undefined) {
530 setTimeout(handle_inserted, 0);
531 }
519 $([IPython.events]).trigger('output_appended.OutputArea', [type, value, md, toinsert]);
532 $([IPython.events]).trigger('output_appended.OutputArea', [type, value, md, toinsert]);
520 return toinsert;
533 return toinsert;
521 }
534 }
@@ -615,10 +628,13 var IPython = (function (IPython) {
615 if (width !== undefined) img.attr('width', width);
628 if (width !== undefined) img.attr('width', width);
616 };
629 };
617
630
618 var append_png = function (png, md, element) {
631 var append_png = function (png, md, element, handle_inserted) {
619 var type = 'image/png';
632 var type = 'image/png';
620 var toinsert = this.create_output_subarea(md, "output_png", type);
633 var toinsert = this.create_output_subarea(md, "output_png", type);
621 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
634 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
635 if (handle_inserted !== undefined) {
636 img.load(handle_inserted);
637 }
622 set_width_height(img, md, 'image/png');
638 set_width_height(img, md, 'image/png');
623 this._dblclick_to_reset_size(img);
639 this._dblclick_to_reset_size(img);
624 toinsert.append(img);
640 toinsert.append(img);
@@ -627,10 +643,13 var IPython = (function (IPython) {
627 };
643 };
628
644
629
645
630 var append_jpeg = function (jpeg, md, element) {
646 var append_jpeg = function (jpeg, md, element, handle_inserted) {
631 var type = 'image/jpeg';
647 var type = 'image/jpeg';
632 var toinsert = this.create_output_subarea(md, "output_jpeg", type);
648 var toinsert = this.create_output_subarea(md, "output_jpeg", type);
633 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
649 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
650 if (handle_inserted !== undefined) {
651 img.load(handle_inserted);
652 }
634 set_width_height(img, md, 'image/jpeg');
653 set_width_height(img, md, 'image/jpeg');
635 this._dblclick_to_reset_size(img);
654 this._dblclick_to_reset_size(img);
636 toinsert.append(img);
655 toinsert.append(img);
General Comments 0
You need to be logged in to leave comments. Login now