##// END OF EJS Templates
Handle widget hide/show logic...
Jonathan Frederic -
Show More
@@ -19,9 +19,11
19 19 // require(['components/underscore/underscore-min.js',
20 20 // 'components/backbone/backbone-min.js'],
21 21
22 var IPython = (function (IPython) {
23 22 "use strict";
24 23
24 // Only run once on a notebook.
25 if (IPython.notebook.widget_manager == undefined) {
26
25 27 //-----------------------------------------------------------------------
26 28 // WidgetModel class
27 29 //-----------------------------------------------------------------------
@@ -148,9 +150,24 var IPython = (function (IPython) {
148 150 widget_view.render();
149 151 widget_model.views.push(widget_view);
150 152
153 // Handle when the view element is remove from the page.
154 widget_view.$el.on("remove", function(){
155 var index = widget_model.views.indexOf(widget_view);
156 if (index > -1) {
157 widget_model.views.splice(index, 1);
158 }
159 widget_view.remove(); // Clean-up view
160
161 // Close the comm if there are no views left.
162 if (widget_model.views.length()==0) {
163 widget_model.comm.close();
164 }
165 });
166
151 167 // Add the view's element to cell's widget div.
152 168 widget_area
153 .append($("<div />").append(widget_view.$el));
169 .append($("<div />").append(widget_view.$el))
170 .parent().show(); // Show the widget_area (parent of widget_subarea)
154 171
155 172 // Update the view based on the model contents.
156 173 widget_view.refresh();
@@ -235,7 +252,6 var IPython = (function (IPython) {
235 252 IPython.WidgetModel = WidgetModel;
236 253 IPython.WidgetView = WidgetView;
237 254
255 IPython.notebook.widget_manager = new WidgetManager(IPython.notebook.kernel.comm_manager);
238 256
239 return IPython;
240
241 }(IPython));
257 }
General Comments 0
You need to be logged in to leave comments. Login now