From a986fd150996edeaf4baaebe6002e1ba7057d0e0 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 30 Nov 2012 01:55:37 +0000 Subject: [PATCH] In the media modal, ensure modal events are always fired on its frame. This ensures restoreThickbox() and thus tbRemove() are called properly when clicking the close button of the modal. Props koopersmith fixes #22632 git-svn-id: http://core.svn.wordpress.org/trunk@22938 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-views.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index e694c476c7..08170b9047 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1216,7 +1216,6 @@ media.view.MediaFrame.prototype[ method ] = function( view ) { if ( this.modal ) this.modal[ method ].apply( this.modal, arguments ); - this.trigger( method ); return this; }; }); @@ -1657,7 +1656,8 @@ _.defaults( this.options, { container: document.body, - title: '' + title: '', + propagate: true }); }, @@ -1680,26 +1680,22 @@ attach: function() { this.$el.appendTo( this.options.container ); - this.trigger('attach'); - return this; + return this.propagate('attach'); }, detach: function() { this.$el.detach(); - this.trigger('detach'); - return this; + return this.propagate('detach'); }, open: function() { this.$el.show(); - this.trigger('open'); - return this; + return this.propagate('open'); }, close: function() { this.$el.hide(); - this.trigger('close'); - return this; + return this.propagate('close'); }, closeHandler: function( event ) { @@ -1715,6 +1711,17 @@ // Set and render the content. this.options.$content = ( $content instanceof Backbone.View ) ? $content.$el : $content; return this.render(); + }, + + // Triggers a modal event and if the `propagate` option is set, + // forwards events to the modal's controller. + propagate: function( id ) { + this.trigger( id ); + + if ( this.options.propagate ) + this.controller.trigger( id ); + + return this; } });