Skip to content

Commit

Permalink
load when plugin is active, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae committed Nov 28, 2024
1 parent 9af5554 commit a54e771
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/block-components/image/image-optimizer-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import domReady from '@wordpress/dom-ready'

class ImageOptimizerPolyfill {
/**
* This script is loaded when EWWW Image Optimizer plugin is activated
* If Easy IO setting is activated for EWWW Image Optimizer plugin, dynamic images becomes blurry.
* This script fixes the issue by removing the &fit parameter from the srcset and src attributes
*/
init = () => {
const imgs = document.querySelectorAll( '.stk-block img' )
imgs.forEach( img => {
Expand Down
5 changes: 4 additions & 1 deletion src/block-components/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

if ( ! function_exists( 'stackable_load_image_optimizer_polyfill_frontend_script' ) ) {
function stackable_load_image_optimizer_polyfill_frontend_script( $block_content, $block ) {
// If Easy IO setting is activated for EWWW Image Optimizer, dynamic images becomes blurry.
// Load the script to fix the issue.
if ( ! is_admin() ) {
wp_enqueue_script(
'stk-frontend-image-optimizer-polyfill',
Expand All @@ -21,7 +23,8 @@ function stackable_load_image_optimizer_polyfill_frontend_script( $block_content
}
}

if ( ! is_admin() ) {
if ( ! is_admin() && is_plugin_active( 'ewww-image-optimizer/ewww-image-optimizer.php' )) {
// Load the script in the frontend if EWWW Image Optimizer is active.
add_action( 'stackable/enqueue_scripts', 'stackable_load_image_optimizer_polyfill_frontend_script', 10, 2 );
}
}

0 comments on commit a54e771

Please sign in to comment.