@@ -563,14 +563,15 @@ var IPython = (function (IPython) {
563
563
} ;
564
564
565
565
566
- CodeCell . prototype . append_output = function ( json ) {
566
+ CodeCell . prototype . append_output = function ( json , dynamic ) {
567
+ // If dynamic is true, javascript output will be eval'd.
567
568
this . expand ( ) ;
568
569
if ( json . output_type === 'pyout' ) {
569
- this . append_pyout ( json ) ;
570
+ this . append_pyout ( json , dynamic ) ;
570
571
} else if ( json . output_type === 'pyerr' ) {
571
572
this . append_pyerr ( json ) ;
572
573
} else if ( json . output_type === 'display_data' ) {
573
- this . append_display_data ( json ) ;
574
+ this . append_display_data ( json , dynamic ) ;
574
575
} else if ( json . output_type === 'stream' ) {
575
576
this . append_stream ( json ) ;
576
577
} ;
@@ -585,11 +586,11 @@ var IPython = (function (IPython) {
585
586
} ;
586
587
587
588
588
- CodeCell . prototype . append_pyout = function ( json ) {
589
+ CodeCell . prototype . append_pyout = function ( json , dynamic ) {
589
590
n = json . prompt_number || ' ' ;
590
591
var toinsert = this . create_output_area ( ) ;
591
592
toinsert . find ( 'div.prompt' ) . addClass ( 'output_prompt' ) . html ( 'Out[' + n + ']:' ) ;
592
- this . append_mime_type ( json , toinsert ) ;
593
+ this . append_mime_type ( json , toinsert , dynamic ) ;
593
594
this . element . find ( 'div.output' ) . append ( toinsert ) ;
594
595
// If we just output latex, typeset it.
595
596
if ( ( json . latex !== undefined ) || ( json . html !== undefined ) ) {
@@ -641,9 +642,9 @@ var IPython = (function (IPython) {
641
642
} ;
642
643
643
644
644
- CodeCell . prototype . append_display_data = function ( json ) {
645
+ CodeCell . prototype . append_display_data = function ( json , dynamic ) {
645
646
var toinsert = this . create_output_area ( ) ;
646
- this . append_mime_type ( json , toinsert ) ;
647
+ this . append_mime_type ( json , toinsert , dynamic ) ;
647
648
this . element . find ( 'div.output' ) . append ( toinsert ) ;
648
649
// If we just output latex, typeset it.
649
650
if ( ( json . latex !== undefined ) || ( json . html !== undefined ) ) {
@@ -652,8 +653,10 @@ var IPython = (function (IPython) {
652
653
} ;
653
654
654
655
655
- CodeCell . prototype . append_mime_type = function ( json , element ) {
656
- if ( json . html !== undefined ) {
656
+ CodeCell . prototype . append_mime_type = function ( json , element , dynamic ) {
657
+ if ( json . javascript !== undefined && dynamic ) {
658
+ this . append_javascript ( json . javascript , element , dynamic ) ;
659
+ } else if ( json . html !== undefined ) {
657
660
this . append_html ( json . html , element ) ;
658
661
} else if ( json . latex !== undefined ) {
659
662
this . append_latex ( json . latex , element ) ;
@@ -676,6 +679,14 @@ var IPython = (function (IPython) {
676
679
} ;
677
680
678
681
682
+ CodeCell . prototype . append_javascript = function ( js , e ) {
683
+ // We just eval the JS code, element appears in the local scope.
684
+ var element = $ ( "<div/>" ) . addClass ( "box_flex1 output_subarea" ) ;
685
+ e . append ( element ) ;
686
+ eval ( js ) ;
687
+ }
688
+
689
+
679
690
CodeCell . prototype . append_text = function ( data , element , extra_class ) {
680
691
var toinsert = $ ( "<div/>" ) . addClass ( "box_flex1 output_subarea output_text" ) ;
681
692
// escape ANSI & HTML specials in plaintext:
@@ -834,7 +845,8 @@ var IPython = (function (IPython) {
834
845
} ;
835
846
var len = data . outputs . length ;
836
847
for ( var i = 0 ; i < len ; i ++ ) {
837
- this . append_output ( data . outputs [ i ] ) ;
848
+ // append with dynamic=false.
849
+ this . append_output ( data . outputs [ i ] , false ) ;
838
850
} ;
839
851
if ( data . collapsed !== undefined ) {
840
852
if ( data . collapsed ) {
0 commit comments