Make WordPress Core

Changeset 37745


Ignore:
Timestamp:
06/18/2016 09:59:54 AM (9 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/wp-embed-template.js

    r36637 r37745  
    138138         */
    139139        sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) );
     140
     141        // Send the document's height again after the featured image has been loaded.
     142        document.querySelector( '.wp-embed-featured-image img' ).addEventListener( 'load', function() {
     143            sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) );
     144        } );
    140145
    141146        /**
Note: See TracChangeset for help on using the changeset viewer.