Skip to content

Commit

Permalink
1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
goaround committed Sep 23, 2024
1 parent 9a75ba2 commit 2b9c853
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ If you would like to have this as a default behaviour, go to `yourblog.com/wp-ad

## Changelog

### 1.15

- Add filter baguettebox_captions to change the JavaScript function to get the caption of an image

### 1.14

- Add the CSS class `.no-lightbox` to an <a> element to disable the lightbox

### 1.13

- Support GenerateBlocks Image
Expand Down
13 changes: 11 additions & 2 deletions gallery-block-lightbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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.14
* Version: 1.15
*/
namespace Gallery_Block_Lightbox;

Expand Down Expand Up @@ -40,7 +40,16 @@ function register_assets() {
*/
$baguettebox_ignoreclass = apply_filters( 'baguettebox_ignoreclass', 'no-lightbox' );

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.classList.contains("wp-block-media-text__media")?t.parentElement.querySelector("figcaption"):t.parentElement.parentElement.querySelector("figcaption,dd");return!!e&&e.innerHTML},filter:' . $baguettebox_filter . ',ignoreClass:"' . $baguettebox_ignoreclass . '"});});' );
/**
* Filters the captions attribute of baguetteBox.js
*
* @since 1.15
*
* @param string $value A JavaScript function that receives the image <a> element and returns the caption for a given image
*/
$baguettebox_captions = apply_filters( 'baguettebox_captions', 'function(t){var e=t.parentElement.classList.contains("wp-block-image")||t.parentElement.classList.contains("wp-block-media-text__media")?t.parentElement.querySelector("figcaption"):t.parentElement.parentElement.querySelector("figcaption,dd");return!!e&&e.innerHTML}' );

wp_add_inline_script( 'baguettebox', 'window.addEventListener("load", function() {baguetteBox.run("' . $baguettebox_selector . '",{captions:' . $baguettebox_captions . ',filter:' . $baguettebox_filter . ',ignoreClass:"' . $baguettebox_ignoreclass . '"});});' );

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

0 comments on commit 2b9c853

Please sign in to comment.