WordPress.org

Make WordPress Core

Changeset 37093


Ignore:
Timestamp:
03/30/2016 10:56:44 AM (4 years ago)
Author:
swissspidy
Message:

Embeds: Improve how iframes are loaded after being initially hidden.

Use a more accessible way to initially hide the iframe. After that, only display an iframe when it was successfully loaded.

Merge of [36648] and [36708] to the 4.4 branch.

Fixes #35894.

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4/src/wp-includes/embed.php

    r36060 r37093  
    777777    if ( ! empty( $content[1] ) ) {
    778778        // We have a blockquote to fall back on. Hide the iframe by default.
    779         $html = str_replace( '<iframe', '<iframe style="display:none;"', $html );
     779        $html = str_replace( '<iframe', '<iframe style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', $html );
    780780        $html = str_replace( '<blockquote', '<blockquote class="wp-embedded-content"', $html );
    781781    }
     
    953953 */
    954954function _oembed_filter_feed_content( $content ) {
    955     return str_replace( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content );
     955    return str_replace( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content );
    956956}
    957957
  • branches/4.4/src/wp-includes/js/wp-embed.js

    r35762 r37093  
    5151            }
    5252
    53             source.style.display = '';
     53            source.removeAttribute( 'style' );
    5454
    5555            /* Resize the iframe on request. */
     
    8787            return;
    8888        }
     89
    8990        loaded = true;
    9091
     
    9293            isIE11 = !!navigator.userAgent.match( /Trident.*rv:11\./ ),
    9394            iframes = document.querySelectorAll( 'iframe.wp-embedded-content' ),
    94             blockquotes = document.querySelectorAll( 'blockquote.wp-embedded-content' ),
    9595            iframeClone, i, source, secret;
    96 
    97         for ( i = 0; i < blockquotes.length; i++ ) {
    98             blockquotes[ i ].style.display = 'none';
    99         }
    10096
    10197        for ( i = 0; i < iframes.length; i++ ) {
    10298            source = iframes[ i ];
    103             source.style.display = '';
    10499
    105100            if ( source.getAttribute( 'data-secret' ) ) {
  • branches/4.4/tests/phpunit/tests/oembed/filterResult.php

    r35577 r37093  
    8484        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
    8585
    86         $this->assertEquals( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
     86        $this->assertEquals( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual );
    8787    }
    8888
     
    9191        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
    9292
    93         $this->assertEquals( '<blockquote class="wp-embedded-content"><a href=""></a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
     93        $this->assertEquals( '<blockquote class="wp-embedded-content"><a href=""></a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual );
    9494    }
    9595
Note: See TracChangeset for help on using the changeset viewer.