##// END OF EJS Templates
Handle widget hide/show logic...
Jonathan Frederic -
Show More
@@ -19,9 +19,11
19 // require(['components/underscore/underscore-min.js',
19 // require(['components/underscore/underscore-min.js',
20 // 'components/backbone/backbone-min.js'],
20 // 'components/backbone/backbone-min.js'],
21
21
22 var IPython = (function (IPython) {
23 "use strict";
22 "use strict";
24
23
24 // Only run once on a notebook.
25 if (IPython.notebook.widget_manager == undefined) {
26
25 //-----------------------------------------------------------------------
27 //-----------------------------------------------------------------------
26 // WidgetModel class
28 // WidgetModel class
27 //-----------------------------------------------------------------------
29 //-----------------------------------------------------------------------
@@ -148,9 +150,24 var IPython = (function (IPython) {
148 widget_view.render();
150 widget_view.render();
149 widget_model.views.push(widget_view);
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 // Add the view's element to cell's widget div.
167 // Add the view's element to cell's widget div.
152 widget_area
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 // Update the view based on the model contents.
172 // Update the view based on the model contents.
156 widget_view.refresh();
173 widget_view.refresh();
@@ -235,7 +252,6 var IPython = (function (IPython) {
235 IPython.WidgetModel = WidgetModel;
252 IPython.WidgetModel = WidgetModel;
236 IPython.WidgetView = WidgetView;
253 IPython.WidgetView = WidgetView;
237
254
255 IPython.notebook.widget_manager = new WidgetManager(IPython.notebook.kernel.comm_manager);
238
256
239 return IPython;
257 }
240
241 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now