From d76ff5a091d69f313a054b8bd8159efd3337fc30 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 21 Apr 2018 03:34:52 -0400 Subject: [PATCH] * Add filter to a3 lazy load to add skip class no-lazyload * Add filter to rocket_async_css_process_responsive_image to add no-lazyload class if we are processing a slider * Add filter to do_shortcode_tag to add no-lazyload to all class attributes in the slider --- .../CSS/Integration/RevolutionSlider.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/Rocket/Async/CSS/Integration/RevolutionSlider.php b/lib/Rocket/Async/CSS/Integration/RevolutionSlider.php index 306154e..dcb510d 100644 --- a/lib/Rocket/Async/CSS/Integration/RevolutionSlider.php +++ b/lib/Rocket/Async/CSS/Integration/RevolutionSlider.php @@ -28,6 +28,9 @@ public function init() { add_filter( 'rocket_async_css_lazy_load_responsive_image', [ $this, 'check_image' ], 10, 4 ); add_action( 'revslider_modify_core_settings', [ $this, 'in_slider' ] ); add_filter( 'revslider_add_js_delay', [ $this, 'out_slider' ], 10, 2 ); + add_filter( 'a3_lazy_load_skip_images_classes', [ $this, 'skip_class' ] ); + add_filter( 'rocket_async_css_process_responsive_image', [ $this, 'block_image' ] ); + add_filter( 'do_shortcode_tag', [ $this, 'post_process_shortcode' ], 10, 2 ); } } @@ -75,4 +78,32 @@ public function out_slider( $value ) { return $value; } -} \ No newline at end of file + + public function skip_class( $classes ) { + $classes = array_map( 'trim', explode( ',', $classes ) ); + $classes[] = 'no-lazyload'; + $classes = array_unique( array_filter( $classes ) ); + $classes = implode( ',', $classes ); + return $classes; + } + + public function block_image( $value ) { + if ( $this->in_slider ) { + if ( false === strpos( $value, 'no-lazyload' ) ) { + $value = str_replace( 'class="', 'class="no-lazyload ', $value ); + $value = str_replace( "class='", "class='no-lazyload ", $value ); + } + } + return $value; + } + + public function post_process_shortcode( $value, $tag ) { + if ( 'rev_slider' === $tag ) { + if ( false === strpos( $value, 'no-lazyload' ) ) { + $value = str_replace( 'class="', 'class="no-lazyload ', $value ); + $value = str_replace( "class='", "class='no-lazyload ", $value ); + } + } + return $value; + } +}