TinyMCE wpView: improve unbinding of mutationObserver in nested iframes. Props iseulde. See #31412.

git-svn-id: https://develop.svn.wordpress.org/trunk@31667 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-03-07 16:52:54 +00:00
parent 0fb3e2566f
commit 6bb478d3fd
1 changed files with 12 additions and 11 deletions

View File

@ -467,7 +467,7 @@ window.wp = window.wp || {};
var dom = editor.dom, var dom = editor.dom,
styles = '', styles = '',
bodyClasses = editor.getBody().className || '', bodyClasses = editor.getBody().className || '',
iframe, iframeDoc, observer, i, resize; iframe, iframeDoc, observer, i;
content.innerHTML = ''; content.innerHTML = '';
head = head || ''; head = head || '';
@ -543,7 +543,7 @@ window.wp = window.wp || {};
iframeDoc.close(); iframeDoc.close();
resize = function() { function resize() {
var $iframe, iframeDocHeight; var $iframe, iframeDocHeight;
// Make sure the iframe still exists. // Make sure the iframe still exists.
@ -556,18 +556,20 @@ window.wp = window.wp || {};
editor.nodeChanged(); editor.nodeChanged();
} }
} }
}; }
if ( MutationObserver ) { if ( MutationObserver ) {
observer = new MutationObserver( _.debounce( function() { observer = new MutationObserver( _.debounce( resize, 100 ) );
resize();
}, 100 ) );
observer.observe( iframeDoc.body, { observer.observe( iframeDoc.body, {
attributes: true, attributes: true,
childList: true, childList: true,
subtree: true subtree: true
} ); } );
$( node ).one( 'wp-mce-view-unbind', function() {
observer.disconnect();
} );
} else { } else {
for ( i = 1; i < 6; i++ ) { for ( i = 1; i < 6; i++ ) {
setTimeout( resize, i * 700 ); setTimeout( resize, i * 700 );
@ -580,12 +582,11 @@ window.wp = window.wp || {};
if ( importStyles ) { if ( importStyles ) {
editor.on( 'wp-body-class-change', classChange ); editor.on( 'wp-body-class-change', classChange );
}
$( node ).one( 'wp-mce-view-unbind', function() { $( node ).one( 'wp-mce-view-unbind', function() {
observer.disconnect(); editor.off( 'wp-body-class-change', classChange );
editor.off( 'wp-body-class-change', classChange ); } );
} ); }
}, 50 ); }, 50 );
callback && callback.apply( this, arguments ); callback && callback.apply( this, arguments );