mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
Handle widget hide/show logic
also only create a widget manager once
This commit is contained in:
parent
4d2bcf02e5
commit
4dc1155c7e
@ -19,8 +19,10 @@
|
||||
// require(['components/underscore/underscore-min.js',
|
||||
// 'components/backbone/backbone-min.js'],
|
||||
|
||||
var IPython = (function (IPython) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
// Only run once on a notebook.
|
||||
if (IPython.notebook.widget_manager == undefined) {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// WidgetModel class
|
||||
@ -148,9 +150,24 @@ var IPython = (function (IPython) {
|
||||
widget_view.render();
|
||||
widget_model.views.push(widget_view);
|
||||
|
||||
// Handle when the view element is remove from the page.
|
||||
widget_view.$el.on("remove", function(){
|
||||
var index = widget_model.views.indexOf(widget_view);
|
||||
if (index > -1) {
|
||||
widget_model.views.splice(index, 1);
|
||||
}
|
||||
widget_view.remove(); // Clean-up view
|
||||
|
||||
// Close the comm if there are no views left.
|
||||
if (widget_model.views.length()==0) {
|
||||
widget_model.comm.close();
|
||||
}
|
||||
});
|
||||
|
||||
// Add the view's element to cell's widget div.
|
||||
widget_area
|
||||
.append($("<div />").append(widget_view.$el));
|
||||
.append($("<div />").append(widget_view.$el))
|
||||
.parent().show(); // Show the widget_area (parent of widget_subarea)
|
||||
|
||||
// Update the view based on the model contents.
|
||||
widget_view.refresh();
|
||||
@ -235,7 +252,6 @@ var IPython = (function (IPython) {
|
||||
IPython.WidgetModel = WidgetModel;
|
||||
IPython.WidgetView = WidgetView;
|
||||
|
||||
IPython.notebook.widget_manager = new WidgetManager(IPython.notebook.kernel.comm_manager);
|
||||
|
||||
return IPython;
|
||||
|
||||
}(IPython));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user