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