diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 9c8b9512b4..4309b0b6e2 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -127,53 +127,57 @@ window.wp = window.wp || {}; content.innerHTML = ''; - iframe = dom.add( content, 'iframe', { - src: tinymce.Env.ie ? 'javascript:""' : '', - frameBorder: '0', - allowTransparency: 'true', - scrolling: 'no', - 'class': 'wpview-sandbox', - style: { - width: '100%', - display: 'block' - } - } ); - - iframeDoc = iframe.contentWindow.document; - - iframeDoc.open(); - iframeDoc.write( - '' + - '' + - '
' + - '' + - '' + - '' + - html + - '' + - '' - ); - iframeDoc.close(); - - resize = function() { - // Make sure the iframe still exists. - iframe.contentWindow && $( iframe ).height( $( iframeDoc.body ).height() ); - }; - - if ( MutationObserver ) { - new MutationObserver( _.debounce( function() { - resize(); - }, 100 ) ) - .observe( iframeDoc.body, { - attributes: true, - childList: true, - subtree: true + // Seems Firefox needs a bit of time to insert/set the view nodes, or the iframe will fail + // especially when switching Text => Visual. + setTimeout( function() { + iframe = dom.add( content, 'iframe', { + src: tinymce.Env.ie ? 'javascript:""' : '', + frameBorder: '0', + allowTransparency: 'true', + scrolling: 'no', + 'class': 'wpview-sandbox', + style: { + width: '100%', + display: 'block' + } } ); - } else { - for ( i = 1; i < 6; i++ ) { - setTimeout( resize, i * 700 ); + + iframeDoc = iframe.contentWindow.document; + + iframeDoc.open(); + iframeDoc.write( + '' + + '' + + '' + + '' + + '' + + '' + + html + + '' + + '' + ); + iframeDoc.close(); + + resize = function() { + // Make sure the iframe still exists. + iframe.contentWindow && $( iframe ).height( $( iframeDoc.body ).height() ); + }; + + if ( MutationObserver ) { + new MutationObserver( _.debounce( function() { + resize(); + }, 100 ) ) + .observe( iframeDoc.body, { + attributes: true, + childList: true, + subtree: true + } ); + } else { + for ( i = 1; i < 6; i++ ) { + setTimeout( resize, i * 700 ); + } } - } + }, 50 ); }); } else { this.setContent( html ); diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index e128b49a27..fb33aef92a 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("