From 663cde2c51e387773744fb7ce8c5fa836f6bb158 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Mon, 19 Nov 2012 22:48:11 +0000 Subject: [PATCH] Media: Add render tracking to views. see #21390. git-svn-id: http://core.svn.wordpress.org/trunk@22690 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-views.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 041cd59a77..f43fd02674 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -682,8 +682,10 @@ subviews.selector = selector; }, this ); - if ( ! options.silent ) + if ( ! options.silent ) { + _.each( views, this._maybeRender, this ); this[ method ]( $selector, els, options ); + } return this; }, @@ -755,6 +757,8 @@ render: function() { var root = this._views['']; + _.each( this.all(), this._maybeRender, this ); + if ( root ) this.replace( this.view.$el, _.pluck( root, 'el' ) ); @@ -763,6 +767,7 @@ this.replace( this.view.$( selector ), _.pluck( views, 'el' ) ); }, this ); + this.rendered = true; return this; }, @@ -813,6 +818,16 @@ $target.append( els ); return this; + }, + + + // #### Internal. Maybe render a view. + _maybeRender: function( view ) { + if ( ! view.views || view.views.rendered ) + return; + + view.render(); + view.views.rendered = true; } }); @@ -1148,14 +1163,14 @@ upload: state.get('upload'), AttachmentView: state.get('AttachmentView') - }).render() ); + }) ); }, uploadContent: function() { // In the meantime, render an inline uploader. this.content.view( new media.view.UploaderInline({ controller: this - }).render() ); + }) ); }, // Sidebars