diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index f5c4857..12e8eca 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -508,8 +508,47 @@ window.wp = window.wp || {}; iframeDoc = iframe.contentWindow.document; - iframeDoc.open(); + resize = function() { + var $iframe, iframeDocHeight; + + // Make sure the iframe still exists. + if ( iframe.contentWindow ) { + $iframe = $( iframe ); + iframeDocHeight = $( iframeDoc.body ).height(); + + if ( $iframe.height() !== iframeDocHeight ) { + $iframe.height( iframeDocHeight ); + editor.nodeChanged(); + } + } + }; + + if ( MutationObserver ) { + observer = new MutationObserver( _.debounce( function( mutations ) { + + resize(); + + // Trigger resize after images have loaded. + mutations.forEach( function( mutation ) { + _.each( mutation.addedNodes, function( node ) { + $(node).find('img').load( resize ); + } ); + }); + + }, 100 ) ); + + observer.observe( iframeDoc, { + attributes: true, + childList: true, + subtree: true + } ); + } else { + for ( i = 1; i < 6; i++ ) { + setTimeout( resize, i * 700 ); + } + } + iframeDoc.open(); iframeDoc.write( '' + '' + @@ -540,40 +579,8 @@ window.wp = window.wp || {}; '' + '' ); - iframeDoc.close(); - resize = function() { - var $iframe, iframeDocHeight; - - // Make sure the iframe still exists. - if ( iframe.contentWindow ) { - $iframe = $( iframe ); - iframeDocHeight = $( iframeDoc.body ).height(); - - if ( $iframe.height() !== iframeDocHeight ) { - $iframe.height( iframeDocHeight ); - editor.nodeChanged(); - } - } - }; - - if ( MutationObserver ) { - observer = new MutationObserver( _.debounce( function() { - resize(); - }, 100 ) ); - - observer.observe( iframeDoc.body, { - attributes: true, - childList: true, - subtree: true - } ); - } else { - for ( i = 1; i < 6; i++ ) { - setTimeout( resize, i * 700 ); - } - } - function classChange() { iframeDoc.body.className = editor.getBody().className; }