Skip to content

Commit

Permalink
Handle the new markup of the Gutenberg Gallery blocks. (#10646)
Browse files Browse the repository at this point in the history
* Handle the new markup of the Gutenberg Gallery blocks.

* Conditional to not die on old wp
  • Loading branch information
George Stephanis authored and dereksmart committed Nov 19, 2018
1 parent deacd17 commit 21379ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/carousel/jetpack-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions modules/carousel/jetpack-carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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( '<div ', '<div ' . esc_attr( $data_key ) . "='" . json_encode( $data_values ) . "' ", $html );
$html = str_replace( '<ul class="wp-block-gallery', '<ul ' . esc_attr( $data_key ) . "='" . json_encode( $data_values ) . "' class=\"wp-block-gallery", $html );
}
}

Expand Down

0 comments on commit 21379ab

Please sign in to comment.