From c83a1cbb63a1a4a89ce12d83e613fbe0e64ce46b Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 8 May 2014 13:46:48 -0500 Subject: [PATCH 1/2] Fixed bugs in displayed event triggering for containers --- IPython/html/static/widgets/js/manager.js | 1 + .../static/widgets/js/widget_container.js | 35 ++++++++++++++++++- .../widgets/js/widget_selectioncontainer.js | 30 ++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index d1af78c0a..4cab8e3f2 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -123,6 +123,7 @@ model.on('destroy', view.remove, view); return view; } + console.log('VIEW NOT REGISTERED?!'); return null; }; diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index 6fcbaca84..c55f35959 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -27,6 +27,18 @@ define(["widgets/js/widget"], function(WidgetManager) { this.update_children(model.previous('_children'), value); }, this); this.update(); + + // Trigger model displayed events for any models that are child to + // this model when this model is displayed. + var that = this; + this.model.on('displayed', function(){ + that.is_displayed = true; + for (var property in that.child_views) { + if (that.child_views.hasOwnProperty(property)) { + that.child_views[property].model.trigger('displayed'); + } + } + }); }, update_children: function(old_list, new_list) { @@ -47,6 +59,11 @@ define(["widgets/js/widget"], function(WidgetManager) { // Called when a model is added to the children list. var view = this.create_child_view(model); this.$el.append(view.$el); + + // Trigger the displayed event if this model is displayed. + if (this.is_displayed) { + model.trigger('displayed'); + } }, update: function(){ @@ -81,7 +98,7 @@ define(["widgets/js/widget"], function(WidgetManager) { // need to know about all of the top-level widgets. The IPython // widget manager uses this to register the elements with the // keyboard manager. - this.additional_elements = [this.$window] + this.additional_elements = [this.$window]; this.$title_bar = $('
') .addClass('popover-title') @@ -169,6 +186,17 @@ define(["widgets/js/widget"], function(WidgetManager) { this.update_children(model.previous('_children'), value); }, this); this.update(); + + // Trigger model displayed events for any models that are child to + // this model when this model is displayed. + this.model.on('displayed', function(){ + that.is_displayed = true; + for (var property in that.child_views) { + if (that.child_views.hasOwnProperty(property)) { + that.child_views[property].model.trigger('displayed'); + } + } + }); }, hide: function() { @@ -228,6 +256,11 @@ define(["widgets/js/widget"], function(WidgetManager) { // Called when a child is added to children list. var view = this.create_child_view(model); this.$body.append(view.$el); + + // Trigger the displayed event if this model is displayed. + if (this.is_displayed) { + model.trigger('displayed'); + } }, update: function(){ diff --git a/IPython/html/static/widgets/js/widget_selectioncontainer.js b/IPython/html/static/widgets/js/widget_selectioncontainer.js index 203135661..a585162ac 100644 --- a/IPython/html/static/widgets/js/widget_selectioncontainer.js +++ b/IPython/html/static/widgets/js/widget_selectioncontainer.js @@ -35,8 +35,17 @@ define(["widgets/js/widget"], function(WidgetManager){ this.model.on('change:_titles', function(model, value, options) { this.update_titles(value); }, this); + var that = this; this.model.on('displayed', function() { this.update_titles(); + // Trigger model displayed events for any models that are child to + // this model when this model is displayed. + that.is_displayed = true; + for (var property in that.child_views) { + if (that.child_views.hasOwnProperty(property)) { + that.child_views[property].model.trigger('displayed'); + } + } }, this); }, @@ -125,6 +134,11 @@ define(["widgets/js/widget"], function(WidgetManager){ this.update(); this.update_titles(); + + // Trigger the displayed event if this model is displayed. + if (this.is_displayed) { + model.trigger('displayed'); + } }, }); WidgetManager.register_widget_view('AccordionView', AccordionView); @@ -153,6 +167,17 @@ define(["widgets/js/widget"], function(WidgetManager){ this.model.on('change:_children', function(model, value, options) { this.update_children(model.previous('_children'), value); }, this); + + // Trigger model displayed events for any models that are child to + // this model when this model is displayed. + this.model.on('displayed', function(){ + that.is_displayed = true; + for (var property in that.child_views) { + if (that.child_views.hasOwnProperty(property)) { + that.child_views[property].model.trigger('displayed'); + } + } + }); }, update_children: function(old_list, new_list) { @@ -206,6 +231,11 @@ define(["widgets/js/widget"], function(WidgetManager){ .append(view.$el) .appendTo(this.$tab_contents); view.parent_container = contents_div; + + // Trigger the displayed event if this model is displayed. + if (this.is_displayed) { + model.trigger('displayed'); + } }, update: function(options) { From a65b6f3c1e0e48fdf63019126b5d51b341067aac Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 8 May 2014 13:50:00 -0500 Subject: [PATCH 2/2] Removed log statement --- IPython/html/static/widgets/js/manager.js | 1 - 1 file changed, 1 deletion(-) diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index 4cab8e3f2..d1af78c0a 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -123,7 +123,6 @@ model.on('destroy', view.remove, view); return view; } - console.log('VIEW NOT REGISTERED?!'); return null; };