-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds compatibility with multiple slider plugins
- Loading branch information
1 parent
3134629
commit d78fd1b
Showing
9 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
cypress/integration/test_masterslider_background_lazyload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe( 'Check MasterSlider Background Page', function () { | ||
it( 'successfully loads', function () { | ||
cy.visit( '/masterslider/' ) | ||
} ); | ||
it( 'Slider background images in view should be lazyloaded', function () { | ||
cy.get( '.entry-content' ).find( '.master-slider' ).eq( 0 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' ) | ||
} ); | ||
it( 'Scroll the page', function () { | ||
cy.scrollTo( 0, 2500 ) | ||
cy.get( '.entry-content' ).find( '.master-slider' ).eq( 1 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ) | ||
} ); | ||
|
||
} ); |
25 changes: 25 additions & 0 deletions
25
cypress/integration/test_metaslider_background_lazyload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe( 'Check Metaslider Background Page', function () { | ||
it( 'successfully loads', function () { | ||
cy.visit( '/metaslider/' ) | ||
} ); | ||
it( 'Slider background images in view should be lazyloaded', function () { | ||
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider' ).eq( 0 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' ); | ||
} ); | ||
it( 'Slider background images in view should be lazyloaded', function () { | ||
for ( let i=4;i<=30;i++ ) { | ||
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider > a' ).eq( i ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' ); | ||
} | ||
} ); | ||
|
||
it( 'Scroll the page', function () { | ||
cy.scrollTo( 0, 2500 ) | ||
} ); | ||
it( 'After scroll slider background images not in view should be lazyloaded', function () { | ||
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider' ).eq( 1 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
} ); | ||
it( 'After scroll slider background images not in view should be lazyloaded', function () { | ||
for ( let i=35;i<=67;i++ ) { | ||
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider > a' ).eq( i ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
} | ||
} ); | ||
} ); |
27 changes: 27 additions & 0 deletions
27
cypress/integration/test_smartslider3_background_lazyload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
describe( 'Check Smart Slider Background Page', function () { | ||
it( 'successfully loads', function () { | ||
cy.visit( '/smartslider3/' ) | ||
} ); | ||
it( 'Slider background images in view should be lazyloaded', function () { | ||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 0 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' ); | ||
} ); | ||
it( 'Slider background images not in view have background-image:none', function () { | ||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 1 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
} ); | ||
it( 'Slider background images not in view have background-image:none', function () { | ||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 2 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
} ); | ||
it( 'Slider background images not in view have background-image:none', function () { | ||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 3 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
} ); | ||
it( 'After scroll the background images that come in view should be loaded', function () { | ||
cy.scrollTo( 0, 2000 ) | ||
|
||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 3 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' ); | ||
|
||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 4 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
|
||
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 5 ).should( 'have.css', 'background-image' ).and( 'match', /none/ ); | ||
|
||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* Class Optml_master_slider. | ||
* | ||
* @reason Added classes to watch for background lazyload | ||
*/ | ||
class Optml_master_slider extends Optml_compatibility { | ||
|
||
|
||
|
||
/** | ||
* Should we load the integration logic. | ||
* | ||
* @return bool Should we load. | ||
*/ | ||
function should_load() { | ||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | ||
|
||
return is_plugin_active( 'master-slider/master-slider.php' ); | ||
} | ||
|
||
/** | ||
* Register integration details. | ||
*/ | ||
public function register() { | ||
add_filter( | ||
'optml_lazyload_bg_selectors', | ||
function ( $all_watchers ) { | ||
$all_watchers = array_merge( $all_watchers, ['.master-slider'] ); | ||
return $all_watchers; | ||
} | ||
); | ||
add_filter( | ||
'optml_dont_replace_url', | ||
function ( $arg, $url = null ) { | ||
if ( strpos( $url, 'blank.gif' ) !== false ) { | ||
return true; | ||
} | ||
return $arg; | ||
}, | ||
10, | ||
2 | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* Class Optml_smart_slider_3. | ||
* | ||
* @reason Added classes to watch for background lazyload | ||
*/ | ||
class Optml_smart_slider_3 extends Optml_compatibility { | ||
|
||
|
||
|
||
/** | ||
* Should we load the integration logic. | ||
* | ||
* @return bool Should we load. | ||
*/ | ||
function should_load() { | ||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | ||
|
||
return is_plugin_active( 'smart-slider-3/smart-slider-3.php' ); | ||
} | ||
|
||
/** | ||
* Register integration details. | ||
*/ | ||
public function register() { | ||
add_filter( | ||
'optml_lazyload_bg_selectors', | ||
function ( $all_watchers ) { | ||
$all_watchers = array_merge( $all_watchers, ['.n2-ss-slide-background-image'] ); | ||
return $all_watchers; | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.