Skip to content

Commit d78fd1b

Browse files
GrigoreMihaiselul
authored andcommitted
feat: adds compatibility with multiple slider plugins
1 parent 3134629 commit d78fd1b

9 files changed

+170
-14
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe( 'Check MasterSlider Background Page', function () {
2+
it( 'successfully loads', function () {
3+
cy.visit( '/masterslider/' )
4+
} );
5+
it( 'Slider background images in view should be lazyloaded', function () {
6+
cy.get( '.entry-content' ).find( '.master-slider' ).eq( 0 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' )
7+
} );
8+
it( 'Scroll the page', function () {
9+
cy.scrollTo( 0, 2500 )
10+
cy.get( '.entry-content' ).find( '.master-slider' ).eq( 1 ).should( 'have.css', 'background-image' ).and( 'match', /none/ )
11+
} );
12+
13+
} );
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe( 'Check Metaslider Background Page', function () {
2+
it( 'successfully loads', function () {
3+
cy.visit( '/metaslider/' )
4+
} );
5+
it( 'Slider background images in view should be lazyloaded', function () {
6+
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider' ).eq( 0 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' );
7+
} );
8+
it( 'Slider background images in view should be lazyloaded', function () {
9+
for ( let i=4;i<=30;i++ ) {
10+
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider > a' ).eq( i ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' );
11+
}
12+
} );
13+
14+
it( 'Scroll the page', function () {
15+
cy.scrollTo( 0, 2500 )
16+
} );
17+
it( 'After scroll slider background images not in view should be lazyloaded', function () {
18+
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider' ).eq( 1 ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
19+
} );
20+
it( 'After scroll slider background images not in view should be lazyloaded', function () {
21+
for ( let i=35;i<=67;i++ ) {
22+
cy.get( '.entry-content' ).find( '.coin-slider > .coin-slider > a' ).eq( i ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
23+
}
24+
} );
25+
} );
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
describe( 'Check Smart Slider Background Page', function () {
2+
it( 'successfully loads', function () {
3+
cy.visit( '/smartslider3/' )
4+
} );
5+
it( 'Slider background images in view should be lazyloaded', function () {
6+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 0 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' );
7+
} );
8+
it( 'Slider background images not in view have background-image:none', function () {
9+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 1 ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
10+
} );
11+
it( 'Slider background images not in view have background-image:none', function () {
12+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 2 ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
13+
} );
14+
it( 'Slider background images not in view have background-image:none', function () {
15+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 3 ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
16+
} );
17+
it( 'After scroll the background images that come in view should be loaded', function () {
18+
cy.scrollTo( 0, 2000 )
19+
20+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 3 ).should( 'have.attr', 'class' ).and( 'include', 'optml-bg-lazyloaded' );
21+
22+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 4 ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
23+
24+
cy.get( '.entry-content' ).find( '.n2-ss-slide-background-image' ).eq( 5 ).should( 'have.css', 'background-image' ).and( 'match', /none/ );
25+
26+
} );
27+
} );

inc/compatibilities/master_slider.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_master_slider.
5+
*
6+
* @reason Added classes to watch for background lazyload
7+
*/
8+
class Optml_master_slider extends Optml_compatibility {
9+
10+
11+
12+
/**
13+
* Should we load the integration logic.
14+
*
15+
* @return bool Should we load.
16+
*/
17+
function should_load() {
18+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
19+
20+
return is_plugin_active( 'master-slider/master-slider.php' );
21+
}
22+
23+
/**
24+
* Register integration details.
25+
*/
26+
public function register() {
27+
add_filter(
28+
'optml_lazyload_bg_selectors',
29+
function ( $all_watchers ) {
30+
$all_watchers = array_merge( $all_watchers, ['.master-slider'] );
31+
return $all_watchers;
32+
}
33+
);
34+
add_filter(
35+
'optml_dont_replace_url',
36+
function ( $arg, $url = null ) {
37+
if ( strpos( $url, 'blank.gif' ) !== false ) {
38+
return true;
39+
}
40+
return $arg;
41+
},
42+
10,
43+
2
44+
);
45+
46+
}
47+
}

inc/compatibilities/metaslider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public function register() {
2727
add_filter( 'optml_possible_lazyload_flags', [ $this, 'add_ignore_lazyload' ], PHP_INT_MAX, 1 );
2828
add_filter( 'optml_watcher_lz_classes', [ $this, 'add_watcher_class' ], 10, 1 );
2929
add_filter( 'metaslider_coin_slider_image_attributes', [ $this, 'setup_listner' ], PHP_INT_MAX, 1 );
30+
add_filter(
31+
'optml_lazyload_bg_selectors',
32+
function ( $all_watchers ) {
33+
$all_watchers = array_merge( $all_watchers, ['.coin-slider > .coin-slider > a', '.coin-slider > .coin-slider'] );
34+
return $all_watchers;
35+
}
36+
);
3037
}
3138

3239
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_smart_slider_3.
5+
*
6+
* @reason Added classes to watch for background lazyload
7+
*/
8+
class Optml_smart_slider_3 extends Optml_compatibility {
9+
10+
11+
12+
/**
13+
* Should we load the integration logic.
14+
*
15+
* @return bool Should we load.
16+
*/
17+
function should_load() {
18+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
19+
20+
return is_plugin_active( 'smart-slider-3/smart-slider-3.php' );
21+
}
22+
23+
/**
24+
* Register integration details.
25+
*/
26+
public function register() {
27+
add_filter(
28+
'optml_lazyload_bg_selectors',
29+
function ( $all_watchers ) {
30+
$all_watchers = array_merge( $all_watchers, ['.n2-ss-slide-background-image'] );
31+
return $all_watchers;
32+
}
33+
);
34+
}
35+
}

inc/lazyload_replacer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ public function can_lazyload_for( $url, $tag = '' ) {
255255
return false;
256256
}
257257
}
258-
259258
if ( false === Optml_Filters::should_do_image( $url, self::$filters[ Optml_Settings::FILTER_TYPE_LAZYLOAD ][ Optml_Settings::FILTER_FILENAME ] ) ) {
260259
return false;
261260
}

inc/manager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ final class Optml_Manager {
6868
'elementor_builder',
6969
'divi_builder',
7070
'thrive',
71+
'smart_slider_3',
72+
'master_slider',
7173
);
74+
7275
/**
7376
* Class instance method.
7477
*

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)