Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the new markup of the Gutenberg Gallery blocks. #10646

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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