Skip to content

Commit

Permalink
fix: improve compatibility with Envira, ignora optimole lazyload on them
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Jul 4, 2019
1 parent 74219b1 commit 00b68fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
22 changes: 22 additions & 0 deletions cypress/integration/test_envira.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe( 'Check envira page', function () {
it( 'successfully loads', function () {
cy.visit( '/envira-test-page/' )
} );
it( 'Gallery images all attributes replaced properly', function () {
cy.get( '#envira-gallery-wrap-92 .envira-gallery-image' ).should( 'have.attr', 'src' ).and( 'contain', 'i.optimole.com' );
cy.get( '#envira-gallery-wrap-92 .envira-gallery-image' ).should( 'have.attr', 'data-envira-src' ).and( 'contain', 'i.optimole.com' );
cy.get( '#envira-gallery-wrap-92 .envira-gallery-image' ).should( 'have.attr', 'data-envira-srcset' ).and( 'contain', 'i.optimole.com' );

cy.get( '#envira-gallery-wrap-97 .envira-gallery-image' ).should( 'have.attr', 'data-safe-src' ).and( 'contain', 'i.optimole.com' );

cy.get( '.envira-gallery-link' ).should( 'have.attr', 'href' ).and( 'contain', 'i.optimole.com' );
} );

it( 'Gallery images should never have lazyload on', function () {
cy.get( '.envira-gallery-image' ).not( 'have.attr', 'data-opt-src' );
} );

it( 'Gallery should have proper crop', function () {
cy.get( '#envira-gallery-wrap-98 img' ).should( 'have.attr', 'data-envira-src' ).and( 'contain', 'rt:fill' );
} );
} );
19 changes: 2 additions & 17 deletions inc/compatibilities/envira.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ function should_load() {
* Register integration details.
*/
public function register() {
add_filter( 'optml_possible_src_attributes', [ $this, 'add_lazysrc' ], 10, 3 );
add_filter( 'optml_possible_lazyload_flags', [ $this, 'add_lazyflag' ], 10, 3 );
add_filter( 'optml_possible_lazyload_flags', [ $this, 'add_lazyflag' ], 10, 2 );
add_filter( 'optml_parse_resize_from_tag', [ $this, 'check_resize_tag' ], 10, 2 );
add_filter( 'envira_gallery_image_src', [ $this, 'revert_src' ], 10, 1 );
}
Expand Down Expand Up @@ -74,22 +73,8 @@ function check_resize_tag( $old_resize, $tag ) {
*/
function add_lazyflag( $strings = array() ) {

$strings[] = 'envira-lazy';
$strings[] = 'envira-gallery-image';

return $strings;
}

/**
* Add Envira lazysrc attribute.
*
* @param array $attributes Old src attributes.
*
* @return array New src attributes.
*/
function add_lazysrc( $attributes = array() ) {

$attributes[] = 'data-envira-src';

return $attributes;
}
}

0 comments on commit 00b68fd

Please sign in to comment.