Skip to content

Commit c55a6fc

Browse files
committed
fix hover animations, use stackable_frontend_css
1 parent 1dab4ab commit c55a6fc

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/init.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,20 +494,25 @@ function stackable_init_animations() {
494494

495495
if ( ! function_exists( 'stackable_check_block_animation' ) ) {
496496

497+
function stackable_css_has_hover_effects_or_animation( $css_string ) {
498+
if ( strpos( $css_string, ':hover' ) !== false || // Hover effects
499+
strpos( $css_string, '--entrance-' ) !== false || // Entrance animations
500+
strpos( $css_string, 'stk-anim' ) !== false || // Scroll animations
501+
strpos( $css_string, '--stk-tran' ) !== false || // Transition duration
502+
strpos( $css_string, 'stk-entrance' ) !== false || // Entrance class
503+
strpos( $css_string, '-hover' ) !== false // has CSS custom property for hover effects
504+
) {
505+
return true;
506+
}
507+
return false;
508+
}
509+
497510
function stackable_check_block_animation( $block_content, $block ) {
498511
if ( ! isset( $block['blockName'] ) || strpos( $block['blockName'], 'stackable/' ) === false ) {
499512
return $block_content;
500513
}
501514

502-
$has_global_animations = apply_filters( 'stackable_has_global_animations', false );
503-
504-
if ( strpos( $block_content, ':hover' ) !== false || // Hover effects
505-
strpos( $block_content, '--entrance-' ) !== false || // Entrance animations
506-
strpos( $block_content, 'stk-anim' ) !== false || // Scroll animations
507-
strpos( $block_content, '--stk-tran' ) !== false || // Transition duration
508-
strpos( $block_content, 'stk-entrance' ) !== false || // Entrance class
509-
$has_global_animations !== false // Global block layouts has hover effects
510-
) {
515+
if ( stackable_css_has_hover_effects_or_animation( $block_content ) ) {
511516
// Adds a special class to the body tag, to indicate we can now run animations.
512517
add_action( 'wp_footer', 'stackable_init_animations' );
513518
remove_filter( 'render_block', 'stackable_check_block_animation', 10, 2 );
@@ -516,7 +521,17 @@ function stackable_check_block_animation( $block_content, $block ) {
516521
return $block_content;
517522
}
518523

524+
function stackable_check_block_animation_on_global_styles( $css ) {
525+
if ( stackable_css_has_hover_effects_or_animation( $css ) ) {
526+
// Adds a special class to the body tag, to indicate we can now run animations.
527+
add_action( 'wp_footer', 'stackable_init_animations' );
528+
}
529+
530+
return $css;
531+
}
532+
519533
if ( is_frontend() ) {
520534
add_filter( 'render_block', 'stackable_check_block_animation', 1, 2 );
535+
add_filter( 'stackable_frontend_css', 'stackable_check_block_animation_on_global_styles', 999 );
521536
}
522537
}

src/plugins/global-settings/buttons-and-icons/index.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ public function add_global_buttons_and_icons_styles( $current_css ) {
101101
return $current_css;
102102
}
103103

104-
if ( strpos( $generated_css, 'hover' ) !== false ) {
105-
add_filter( 'stackable_has_global_animations', function( $has_global_animations ) {
106-
return true;
107-
} );
108-
}
109-
110104
$current_css .= $generated_css;
111105
return apply_filters( 'stackable_frontend_css' , $current_css );
112106
}

src/plugins/global-settings/spacing-and-borders/index.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ public function add_global_spacing_and_borders_styles( $current_css ) {
102102
return $current_css;
103103
}
104104

105-
if ( strpos( $generated_css, 'hover' ) !== false ) {
106-
add_filter( 'stackable_has_global_animations', function( $has_global_animations ) {
107-
return true;
108-
} );
109-
}
110-
111105
$current_css .= $generated_css;
112106
return apply_filters( 'stackable_frontend_css' , $current_css );
113107
}

0 commit comments

Comments
 (0)