-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add baguettebox_selector and baguettebox_filter Filter
- Loading branch information
Showing
1 changed file
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' ); | ||
|
||
|