TinyMCE: wpviews: cache iframe heights
Cache iframe heights per instance so it can be reused. This will prevent to content from moving in the editor when undoing or redoing changes. Fixes #32593. git-svn-id: https://develop.svn.wordpress.org/trunk@32711 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c345382dee
commit
9f13e05b64
|
@ -501,10 +501,17 @@ window.wp = window.wp || {};
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
if ( self.iframeHeight ) {
|
||||||
|
dom.add( contentNode, 'div', { style: {
|
||||||
|
width: '100%',
|
||||||
|
height: self.iframeHeight
|
||||||
|
} } );
|
||||||
|
}
|
||||||
|
|
||||||
// Seems the browsers need a bit of time to insert/set the view nodes,
|
// Seems the browsers need a bit of time to insert/set the view nodes,
|
||||||
// or the iframe will fail especially when switching Text => Visual.
|
// or the iframe will fail especially when switching Text => Visual.
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
var iframe, iframeDoc, observer, i;
|
var iframe, iframeDoc, observer, i, block;
|
||||||
|
|
||||||
contentNode.innerHTML = '';
|
contentNode.innerHTML = '';
|
||||||
|
|
||||||
|
@ -518,7 +525,8 @@ window.wp = window.wp || {};
|
||||||
style: {
|
style: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
display: 'block'
|
display: 'block'
|
||||||
}
|
},
|
||||||
|
height: self.iframeHeight
|
||||||
} );
|
} );
|
||||||
|
|
||||||
dom.add( contentNode, 'div', { 'class': 'wpview-overlay' } );
|
dom.add( contentNode, 'div', { 'class': 'wpview-overlay' } );
|
||||||
|
@ -561,20 +569,33 @@ window.wp = window.wp || {};
|
||||||
iframeDoc.close();
|
iframeDoc.close();
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
var $iframe, iframeDocHeight;
|
var $iframe;
|
||||||
|
|
||||||
|
if ( block ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the iframe still exists.
|
// Make sure the iframe still exists.
|
||||||
if ( iframe.contentWindow ) {
|
if ( iframe.contentWindow ) {
|
||||||
$iframe = $( iframe );
|
$iframe = $( iframe );
|
||||||
iframeDocHeight = $( iframeDoc.body ).height();
|
self.iframeHeight = $( iframeDoc.body ).height();
|
||||||
|
|
||||||
if ( $iframe.height() !== iframeDocHeight ) {
|
if ( $iframe.height() !== self.iframeHeight ) {
|
||||||
$iframe.height( iframeDocHeight );
|
$iframe.height( self.iframeHeight );
|
||||||
editor.nodeChanged();
|
editor.nodeChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( self.iframeHeight ) {
|
||||||
|
block = true;
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
block = false;
|
||||||
|
resize();
|
||||||
|
}, 3000 );
|
||||||
|
}
|
||||||
|
|
||||||
$( iframe.contentWindow ).on( 'load', resize );
|
$( iframe.contentWindow ).on( 'load', resize );
|
||||||
|
|
||||||
if ( MutationObserver ) {
|
if ( MutationObserver ) {
|
||||||
|
|
Loading…
Reference in New Issue