From 21379abdd2db10a0616e4de72d5c10390c360c64 Mon Sep 17 00:00:00 2001 From: George Stephanis Date: Mon, 19 Nov 2018 17:11:39 -0500 Subject: [PATCH] Handle the new markup of the Gutenberg Gallery blocks. (#10646) * Handle the new markup of the Gutenberg Gallery blocks. * Conditional to not die on old wp --- modules/carousel/jetpack-carousel.js | 2 +- modules/carousel/jetpack-carousel.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/carousel/jetpack-carousel.js b/modules/carousel/jetpack-carousel.js index f07ec8266cc97..056c376b5457a 100644 --- a/modules/carousel/jetpack-carousel.js +++ b/modules/carousel/jetpack-carousel.js @@ -1446,7 +1446,7 @@ jQuery(document).ready(function($) { }; // register the event listener for starting the gallery - $( document.body ).on( 'click.jp-carousel', 'div.gallery,div.tiled-gallery, a.single-image-gallery', function(e) { + $( document.body ).on( 'click.jp-carousel', 'div.gallery, div.tiled-gallery, ul.wp-block-gallery, a.single-image-gallery', function( e ) { if ( ! $(this).jp_carousel( 'testForData', e.currentTarget ) ) { return; } diff --git a/modules/carousel/jetpack-carousel.php b/modules/carousel/jetpack-carousel.php index 9bbf602b6bc72..b024d005b6361 100644 --- a/modules/carousel/jetpack-carousel.php +++ b/modules/carousel/jetpack-carousel.php @@ -77,6 +77,7 @@ function init() { add_filter( 'post_gallery', array( $this, 'set_in_gallery' ), -1000 ); add_filter( 'gallery_style', array( $this, 'add_data_to_container' ) ); add_filter( 'wp_get_attachment_image_attributes', array( $this, 'add_data_to_images' ), 10, 2 ); + add_filter( 'the_content', array( $this, 'check_content_for_blocks' ), 1 ); if ( $this->single_image_gallery_enabled ) { add_filter( 'the_content', array( $this, 'add_data_img_tags_and_enqueue_assets' ) ); } @@ -198,6 +199,14 @@ function check_if_shortcode_processed_and_enqueue_assets( $output ) { return $output; } + function check_content_for_blocks( $content ) { + if ( function_exists( 'has_block' ) && has_block( 'gallery', $content ) ) { + $this->enqueue_assets(); + $content = $this->add_data_to_container( $content ); + } + return $content; + } + function enqueue_assets() { if ( $this->first_run ) { wp_enqueue_script( @@ -493,6 +502,7 @@ function add_data_to_container( $html ) { $extra_data = apply_filters( 'jp_carousel_add_data_to_container', $extra_data ); foreach ( (array) $extra_data as $data_key => $data_values ) { $html = str_replace( '