diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 4309b0b6e2..ce35a14db3 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/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/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index dba3fc7c67..da12d957d3 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -205,10 +205,6 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { removeView( selected ); } - if ( ! event.initial ) { - wp.mce.views.unbind( editor ); - } - node = editor.selection.getNode(); // When a url is pasted, only try to embed it when pasted in an empty paragrapgh.