From c3394e2c93118f71b6fac278ce0c9d5b97e8dca6 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 18 Jun 2016 09:59:54 +0000 Subject: [PATCH] Embeds: Improve height calculation for slow loading images. When the featured image takes longer to load, the browser might not know its exact dimensions yet and therefore sends an incorrect document height to the embedding site. By sending the document's height again after the featured image has been loaded, we ensure that the iframe doesn't get cut off. Fixes #35657. git-svn-id: https://develop.svn.wordpress.org/trunk@37745 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/wp-embed-template.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wp-includes/js/wp-embed-template.js b/src/wp-includes/js/wp-embed-template.js index 60ea47d387..2960991cee 100644 --- a/src/wp-includes/js/wp-embed-template.js +++ b/src/wp-includes/js/wp-embed-template.js @@ -138,6 +138,11 @@ */ sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) ); + // Send the document's height again after the featured image has been loaded. + document.querySelector( '.wp-embed-featured-image img' ).addEventListener( 'load', function() { + sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) ); + } ); + /** * Detect clicks to external (_top) links. */