Skip to content

Commit

Permalink
* Add filter to a3 lazy load to add skip class no-lazyload
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pcfreak30 committed Apr 21, 2018
1 parent 5711cf8 commit d76ff5a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/Rocket/Async/CSS/Integration/RevolutionSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -75,4 +78,32 @@ public function out_slider( $value ) {

return $value;
}
}

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;
}
}

0 comments on commit d76ff5a

Please sign in to comment.