From eae68af55c89c6e7f9d6f4c56f5e1888ea337611 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Wed, 5 Dec 2012 00:45:21 +0000 Subject: [PATCH] Toggle display of plupload overlays when the select files button is hidden. see #22732. git-svn-id: https://develop.svn.wordpress.org/trunk@23053 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/js/media-views.js | 26 ++++++++++++++++++++ wp-includes/js/plupload/wp-plupload.js | 34 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index d7c050a255..c6b5ca4c43 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -2085,6 +2085,31 @@ } }, + dispose: function() { + if ( this.disposing ) + return media.View.prototype.dispose.apply( this, arguments ); + + // Run remove on `dispose`, so we can be sure to refresh the + // uploader with a view-less DOM. Track whether we're disposing + // so we don't trigger an infinite loop. + this.disposing = true; + return this.remove(); + }, + + remove: function() { + var result = media.View.prototype.remove.apply( this, arguments ); + + _.defer( _.bind( this.refresh, this ) ); + return result; + }, + + refresh: function() { + var uploader = this.controller.uploader; + + if ( uploader ) + uploader.refresh(); + }, + ready: function() { var $browser = this.options.$browser, $placeholder; @@ -2101,6 +2126,7 @@ $placeholder.replaceWith( $browser.show() ); } + this.refresh(); return this; } }); diff --git a/wp-includes/js/plupload/wp-plupload.js b/wp-includes/js/plupload/wp-plupload.js index adf336dc21..3a6c42728b 100644 --- a/wp-includes/js/plupload/wp-plupload.js +++ b/wp-includes/js/plupload/wp-plupload.js @@ -293,7 +293,41 @@ window.wp = window.wp || {}; progress: function() {}, complete: function() {}, refresh: function() { + var node, enabled, container; + + if ( this.browser ) { + node = this.browser[0]; + + while ( node ) { + if ( node === document.body ) { + enabled = true; + break; + } + node = node.parentNode; + } + + this.uploader.disableBrowse( ! enabled ); + // Toggle all auto-created file containers. + this._container().toggle( enabled ); + } + this.uploader.refresh(); + }, + + _container: function() { + var runtime = this.uploader.runtime; + + if ( this._$container && this._$container.length ) + return this._$container; + + if ( 'html4' === runtime ) + return $('[target="' + this.uploader.id + '_iframe"]'); + + if ( 'html5' !== runtime && 'flash' !== runtime && 'silverlight' !== runtime ) + return $(); + + this._$container = $( '#' + this.uploader.id + '_' + runtime + '_container' ); + return this._$container; } });