Merge pull request #17152 from woocommerce/fix/lazy-load-embeds

Load videos when the help tab is opened, not before.
This commit is contained in:
Mike Jolley 2017-10-12 12:28:00 +01:00 committed by GitHub
commit 6aca58324a
3 changed files with 9 additions and 5 deletions

View File

@ -291,8 +291,9 @@ jQuery( function ( $ ) {
// Load videos when help button is clicked. // Load videos when help button is clicked.
$( '#contextual-help-link' ).on( 'click', function() { $( '#contextual-help-link' ).on( 'click', function() {
var frame = $( '#tab-panel-woocommerce_guided_tour_tab iframe' ); $( '.wc-guided-tour-embed' ).each( function() {
var video_id = $( this ).data( 'video_id' );
frame.attr( 'src', frame.data( 'src' ) ); $( this ).replaceWith( '<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/' + video_id + '" frameborder="0" allowfullscreen></iframe>' );
} );
}); });
}); });

File diff suppressed because one or more lines are too long

View File

@ -177,7 +177,10 @@ class WC_Admin_Help {
} }
if ( isset( $video_map[ $video_key ] ) ) { if ( isset( $video_map[ $video_key ] ) ) {
$embed_code = str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&scolor=white', wp_oembed_get( 'https://www.youtube.com/watch?v=' . $video_map[ $video_key ]['id'], array( 'width' => '420px' ) ) ); $embed_code = '
<a href="https://www.youtube.com/watch?v=' . esc_attr( $video_map[ $video_key ]['id'] ) . '" target="_blank" class="wc-guided-tour-embed" data-video_id="' . esc_attr( $video_map[ $video_key ]['id'] ) . '">
<img src="https://img.youtube.com/vi/' . esc_attr( $video_map[ $video_key ]['id'] ) . '/maxresdefault.jpg" width="560" height="315" />
</a>';
$screen->add_help_tab( array( $screen->add_help_tab( array(
'id' => 'woocommerce_guided_tour_tab', 'id' => 'woocommerce_guided_tour_tab',