diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index aae6dc21c2..3148926232 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1049,6 +1049,7 @@ container: this.$el } }); + this.views.set( '.media-frame-uploader', this.uploader ); } this.on( 'attach', _.bind( this.views.ready, this.views ), this ); @@ -1059,11 +1060,6 @@ this.modal.render(); media.view.Frame.prototype.render.apply( this, arguments ); - - // Render the window uploader if it exists. - if ( this.uploader ) - this.uploader.render().$el.appendTo( this.$el ); - return this; }, @@ -1733,20 +1729,9 @@ params: {} }); - if ( uploader.dropzone ) { - // Ensure the dropzone is a jQuery collection. - if ( ! (uploader.dropzone instanceof $) ) - uploader.dropzone = $( uploader.dropzone ); - - // Attempt to initialize the uploader whenever the dropzone is hovered. - uploader.dropzone.one( 'mouseenter dragenter', _.bind( this.maybeInitUploader, this ) ); - } - }, - - render: function() { - this.maybeInitUploader(); - this.$el.html( this.template( this.options ) ); - return this; + // Ensure the dropzone is a jQuery collection. + if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) + uploader.dropzone = $( uploader.dropzone ); }, refresh: function() { @@ -1754,16 +1739,16 @@ this.uploader.refresh(); }, - maybeInitUploader: function() { - var $id, dropzone; + ready: function() { + var postId = media.view.settings.postId, + dropzone; - // If the uploader already exists or the body isn't in the DOM, bail. - if ( this.uploader || ! this.$el.closest('body').length ) + // If the uploader already exists, bail. + if ( this.uploader ) return; - $id = $('#post_ID'); - if ( $id.length ) - this.options.uploader.params.post_id = $id.val(); + if ( postId ) + this.options.uploader.params.post_id = postId; this.uploader = new wp.Uploader( this.options.uploader ); diff --git a/wp-includes/media.php b/wp-includes/media.php index 10ac1740e6..ff531c925b 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1406,6 +1406,7 @@ function wp_print_media_templates( $attachment ) {
+