Skip to content

Commit

Permalink
Add baguettebox_selector and baguettebox_filter Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
goaround committed Nov 22, 2021
1 parent 0552ce3 commit 14b1df9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions gallery-block-lightbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@
* Description: Adds a Lightbox to the Block Editor (Gutenberg) Gallery & Image Block.
* Author: Johannes Kinast <[email protected]>
* Author URI: https://go-around.de
* Version: 1.9.0
* Version: 1.10.0
*/
namespace Gallery_Block_Lightbox;

function register_assets() {
wp_register_script( 'baguettebox', plugin_dir_url( __FILE__ ) . 'dist/baguetteBox.min.js', [], '1.11.1', true );
wp_add_inline_script( 'baguettebox', 'window.addEventListener("load", function() {baguetteBox.run(".wp-block-gallery,:not(.wp-block-gallery)>.wp-block-image,.wp-block-media-text,.gallery,.wp-block-coblocks-gallery-masonry,.wp-block-coblocks-gallery-stacked,.wp-block-coblocks-gallery-collage,.wp-block-coblocks-gallery-offset,.wp-block-coblocks-gallery-stacked",{captions:function(t){var e=t.parentElement.classList.contains("wp-block-image")?t.parentElement.querySelector("figcaption"):t.parentElement.parentElement.querySelector("figcaption,dd");return!!e&&e.innerHTML},filter:/.+\.(gif|jpe?g|png|webp|svg|avif|heif|heic|tif?f|)($|\?)/i});});' );
wp_register_style( 'baguettebox-css', plugin_dir_url( __FILE__ ) . 'dist/baguetteBox.min.css', [], '1.11.1' );
wp_register_script( 'baguettebox', plugin_dir_url( __FILE__ ) . 'dist/baguetteBox.min.js', [], '1.11.1', true );

/**
* Filters the CSS selector of baguetteBox.js
*
* @since 1.10.0
*
* @param string $value The CSS selector to a gallery (or galleries) containing a tags
*/
$baguettebox_selector = apply_filters('baguettebox_selector', '.wp-block-gallery,:not(.wp-block-gallery)>.wp-block-image,.wp-block-media-text,.gallery,.wp-block-coblocks-gallery-masonry,.wp-block-coblocks-gallery-stacked,.wp-block-coblocks-gallery-collage,.wp-block-coblocks-gallery-offset,.wp-block-coblocks-gallery-stacked' );

/**
* Filters the image files filter of baguetteBox.js
*
* @since 1.10.0
*
* @param string $value The RegExp Pattern to match image files. Applied to the a.href attribute
*/
$baguettebox_filter = apply_filters( 'baguettebox_filter', '/.+\.(gif|jpe?g|png|webp|svg|avif|heif|heic|tif?f|)($|\?)/i' );

wp_add_inline_script( 'baguettebox', 'window.addEventListener("load", function() {baguetteBox.run("' . $baguettebox_selector . '",{captions:function(t){var e=t.parentElement.classList.contains("wp-block-image")?t.parentElement.querySelector("figcaption"):t.parentElement.parentElement.querySelector("figcaption,dd");return!!e&&e.innerHTML},filter:' . $baguettebox_filter . '});});' );

}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_assets' );

Expand Down

0 comments on commit 14b1df9

Please sign in to comment.