TinyMCE wpView: add small delay before inserting wpview sandbox iframes into the DOM. Fixes a problem in Firefox that may prevent rendering them. Fixes #29241.

Built from https://develop.svn.wordpress.org/trunk@29513


git-svn-id: http://core.svn.wordpress.org/trunk@29290 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-08-17 03:43:18 +00:00
parent ae596dd60b
commit ac463e5c71
2 changed files with 50 additions and 46 deletions

View File

@ -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(
'<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
'</head>' +
'<body data-context="iframe-sandbox" style="padding: 0; margin: 0;" class="' + editor.getBody().className + '">' +
html +
'</body>' +
'</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(
'<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
'</head>' +
'<body data-context="iframe-sandbox" style="padding: 0; margin: 0;" class="' + editor.getBody().className + '">' +
html +
'</body>' +
'</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 );

File diff suppressed because one or more lines are too long