diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 4309b0b6e2..ce35a14db3 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -46,24 +46,30 @@ window.wp = window.wp || {}; '
' + ''; }, - render: function() { - this.setContent( - '\u00a0
' + - '\u00a0
', - 'wrap' - ); + render: function( force ) { + if ( force || ! this.rendered() ) { + this.unbind(); - $( this ).trigger( 'ready' ); + this.setContent( + '\u00a0
' + + '\u00a0
', + 'wrap' + ); + + $( this ).trigger( 'ready' ); + + this.rendered( true ); + } }, unbind: function() {}, getEditors: function( callback ) { @@ -190,6 +196,19 @@ window.wp = window.wp || {}; '' + message + '
' + '' ); + }, + rendered: function( value ) { + var notRendered; + + this.getNodes( function( editor, node ) { + if ( value != null ) { + $( node ).data( 'rendered', value === true ); + } else { + notRendered = notRendered || ! $( node ).data( 'rendered' ); + } + } ); + + return ! notRendered; } } ); @@ -390,7 +409,7 @@ window.wp = window.wp || {}; instances[ encodedText ] = instance; } - wp.mce.views.render(); + instance.render(); }, getInstance: function( encodedText ) { @@ -406,9 +425,9 @@ window.wp = window.wp || {}; * To generate wrapper elements, pass your content through * `wp.mce.view.toViews( content )`. */ - render: function() { + render: function( force ) { _.each( instances, function( instance ) { - instance.render(); + instance.render( force ); } ); }, @@ -438,8 +457,12 @@ window.wp = window.wp || {}; }, fetch: function() { + var self = this; + this.attachments = wp.media.gallery.attachments( this.shortcode, this.postID ); - this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); + this.dfd = this.attachments.more().done( function() { + self.render( true ); + } ); }, getHtml: function() { diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index fb33aef92a..5f0bf296f3 100644 --- a/wp-includes/js/mce-view.min.js +++ b/wp-includes/js/mce-view.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a){"use strict";var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a=a||{},this.type=a.type,_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},getHtml:function(){return""},loadingPlaceholder:function(){return'
',"wrap"),a(this).trigger("ready")},unbind:function(){},getEditors:function(a){var b=[];return _.each(tinymce.editors,function(c){c.plugins.wpview&&(a&&a(c),b.push(c))},this),b},getNodes:function(b){var c=[],d=this;return this.getEditors(function(e){a(e.getBody()).find('[data-wpview-text="'+d.encodedText+'"]').each(function(d,f){b&&b(e,f,a(f).find(".wpview-content").get(0)),c.push(f)})}),c},setContent:function(a,b){this.getNodes(function(c,d,e){var f="wrap"===b||"replace"===b?d:e,g=a;_.isString(g)&&(g=c.dom.createFragment(g)),"replace"===b?c.dom.replace(g,f):(f.innerHTML="",f.appendChild(g))})},setIframes:function(b){var c=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;-1!==b.indexOf("