diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 1065d69daa..9217b30373 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -47,8 +47,6 @@ window.wp = window.wp || {}; ''; }, render: function() { - var html = this.getHtml() || this.loadingPlaceholder(); - this.setContent( '
\u00a0
' + '\u00a0
', - function( self, editor, node ) { - $( self ).trigger( 'ready', [ editor, node ] ); - }, 'wrap' ); + + $( this ).trigger( 'ready' ); }, unbind: function() {}, - getNodes: function( callback ) { - var nodes = []; + getEditors: function( callback ) { + var editors = []; _.each( tinymce.editors, function( editor ) { if ( editor.plugins.wpview ) { - $( editor.getBody() ) - .find( '[data-wpview-text="' + this.encodedText + '"]' ) - .each( function ( i, node ) { - if ( callback ) { - callback( editor, node ); - } + if ( callback ) { + callback( editor ); + } - nodes.push( node ); - } ); + editors.push( editor ); } }, this ); + return editors; + }, + getNodes: function( callback ) { + var nodes = [], + self = this; + + this.getEditors( function( editor ) { + $( editor.getBody() ) + .find( '[data-wpview-text="' + self.encodedText + '"]' ) + .each( function ( i, node ) { + if ( callback ) { + callback( editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); + } + + nodes.push( node ); + } ); + } ); + return nodes; }, - setContent: function( html, callback, option ) { - var self = this; + setContent: function( html, option ) { + this.getNodes( function ( editor, node, content ) { + var el = ( option === 'wrap' || option === 'replace' ) ? node : content, + insert = html; - this.getNodes( function ( editor, element ) { - var contentWrap = $( element ).find( '.wpview-content' ), - wrap = element; - - if ( contentWrap.length && option !== 'wrap' ) { - element = contentWrap = contentWrap[0]; + if ( _.isString( insert ) ) { + insert = editor.dom.createFragment( insert ); } - if ( _.isString( html ) ) { - if ( option === 'replace' ) { - element = editor.dom.replace( editor.dom.createFragment( html ), wrap ); - } else { - editor.dom.setHTML( element, html ); - } + if ( option === 'replace' ) { + editor.dom.replace( insert, el ); } else { - if ( option === 'replace' ) { - element = editor.dom.replace( html, wrap ); - } else { - $( element ).empty().append( html ); - } - } - - if ( _.isFunction( callback ) ) { - callback( self, editor, $( element ).find( '.wpview-content' )[0] ); + el.innerHTML = ''; + el.appendChild( insert ); } } ); }, - /* jshint scripturl: true */ - createIframe: function ( content ) { + setIframes: function ( html ) { var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; - if ( content.indexOf( '' + '' + '' + - content + + html + '' + '