@@ -48,11 +48,19 @@ mpl.mpl_figure_comm = function (comm, msg) {
4848 console . error ( 'Failed to find cell for figure' , id , fig ) ;
4949 return ;
5050 }
51+ fig . cell_info [ 0 ] . output_area . element . one (
52+ 'cleared' ,
53+ { fig : fig } ,
54+ fig . _remove_fig_handler
55+ ) ;
5156} ;
5257
5358mpl . figure . prototype . handle_close = function ( fig , msg ) {
5459 var width = fig . canvas . width / fig . ratio ;
55- fig . root . removeEventListener ( 'remove' , this . _remove_fig_handler ) ;
60+ fig . cell_info [ 0 ] . output_area . element . off (
61+ 'cleared' ,
62+ fig . _remove_fig_handler
63+ ) ;
5664
5765 // Update the output cell to use the data from the current canvas.
5866 fig . push_to_output ( ) ;
@@ -171,13 +179,13 @@ mpl.figure.prototype._init_toolbar = function () {
171179 titlebar . insertBefore ( buttongrp , titlebar . firstChild ) ;
172180} ;
173181
174- mpl . figure . prototype . _remove_fig_handler = function ( ) {
175- this . close_ws ( this , { } ) ;
182+ mpl . figure . prototype . _remove_fig_handler = function ( event ) {
183+ var fig = event . data . fig ;
184+ fig . close_ws ( fig , { } ) ;
176185} ;
177186
178187mpl . figure . prototype . _root_extra_style = function ( el ) {
179188 el . style . boxSizing = 'content-box' ; // override notebook setting of border-box.
180- el . addEventListener ( 'remove' , this . _remove_fig_handler ) ;
181189} ;
182190
183191mpl . figure . prototype . _canvas_extra_style = function ( el ) {
0 commit comments