Skip to content

Commit

Permalink
Lazy Images: Skip images with data-skip-lazy attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ebinnion committed Jan 31, 2020
1 parent 18e4626 commit f4d0f59
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/lazy-images/lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ static function process_image_attributes( $attributes ) {
return $attributes;
}

if ( isset( $attributes['data-skip-lazy'] ) ) {
return $attributes;
}

/**
* Allow plugins and themes to conditionally skip processing an image via its attributes.
*
Expand Down
28 changes: 28 additions & 0 deletions tests/php/modules/lazy-images/test_class.lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,34 @@ function get_dont_process_images_with_classes_data() {
);
}

/**
* @dataProvider get_dont_process_images_with_skip_lazy_data_attribute_data
*/
function test_dont_process_images_with_skip_lazy_data_attribute( $input, $should_skip = true ) {
$instance = Jetpack_Lazy_Images::instance();
$output = $instance->add_image_placeholders( $input );

if ( $should_skip ) {
$this->assertNotContains( 'srcset="placeholder.jpg"', $output );
} else {
$this->assertContains( 'srcset="placeholder.jpg"', $output );
}
}

function get_dont_process_images_with_skip_lazy_data_attribute_data() {
return array(
'skip_lazy_attr_only' => array(
'<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" data-skip-lazy/>',
),
'skip-lazy-attr-true' => array(
'<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" data-skip-lazy="true"/>',
),
'skip-lazy-attr-1' => array(
'<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" data-skip-lazy="1"/>',
),
);
}

/**
* @dataProvider get_should_skip_image_with_blacklisted_class_data
*/
Expand Down

0 comments on commit f4d0f59

Please sign in to comment.