Media: Make the window-wide uploader a subview of the frame view.

Allows the uploader to leverage the ready event to know when it has been attached to the page.

see #21390.


git-svn-id: http://core.svn.wordpress.org/trunk@22790 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-21 20:27:49 +00:00
parent 095093e390
commit 1923278143
2 changed files with 12 additions and 26 deletions

View File

@ -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 $) )
if ( uploader.dropzone && ! (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;
},
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 );

View File

@ -1406,6 +1406,7 @@ function wp_print_media_templates( $attachment ) {
<div class="media-frame-content"></div>
<div class="media-frame-sidebar"></div>
<div class="media-frame-toolbar"></div>
<div class="media-frame-uploader"></div>
</script>
<script type="text/html" id="tmpl-media-modal">