Skip to content

Commit f44a1fc

Browse files
authored
Merge pull request #529 from Codeinwp/fix/issue-755
Add Otter lazy-load selectors
2 parents 0e194e7 + c62e6b5 commit f44a1fc

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
describe("Check Otter Background Lazyload", function () {
2+
it("successfully loads", function () {
3+
cy.visit("/otter/background-lazyload/");
4+
});
5+
6+
it("Otter Flip block front should have background lazyloaded", function () {
7+
cy.get(".wp-block-themeisle-blocks-flip")
8+
.find(".o-flip-front")
9+
.eq(0)
10+
.should("have.attr", "class")
11+
.and("include", "optml-bg-lazyloaded");
12+
});
13+
14+
it("Otter Flip block front should have background image url optimized (ie. external css is processed)", function () {
15+
cy.get(".wp-block-themeisle-blocks-flip")
16+
.find(".o-flip-front")
17+
.eq(0)
18+
.should("have.css", "background-image")
19+
.and("match", /url\(.*\.i\.optimole\.com.*\)/);
20+
});
21+
22+
it("Otter Flip block back should have background lazyloaded", function () {
23+
cy.get(".wp-block-themeisle-blocks-flip")
24+
.find(".o-flip-back")
25+
.eq(0)
26+
.should("have.attr", "class")
27+
.and("include", "optml-bg-lazyloaded");
28+
});
29+
30+
it("Otter Flip block back should have background image url optimized (ie. external css is processed)", function () {
31+
cy.get(".wp-block-themeisle-blocks-flip")
32+
.find(".o-flip-back")
33+
.eq(0)
34+
.should("have.css", "background-image")
35+
.and("match", /url\(.*\.i\.optimole\.com.*\)/);
36+
});
37+
38+
it("Otter Section Block should have background lazyloaded", function () {
39+
cy.scrollTo( 0, 500 );
40+
cy.get("#wp-block-themeisle-blocks-advanced-columns-e62611eb")
41+
.eq(0)
42+
.should("have.attr", "class")
43+
.and("include", "optml-bg-lazyloaded");
44+
});
45+
46+
it("Otter Section Block should have background image url optimized (ie. external css is processed)", function () {
47+
cy.get("#wp-block-themeisle-blocks-advanced-columns-e62611eb")
48+
.eq(0)
49+
.should("have.css", "background-image")
50+
.and("match", /url\(.*\.i\.optimole\.com.*\)/);
51+
});
52+
53+
it("Otter Section Block's Overlay should have background lazyloaded", function () {
54+
cy.get("#wp-block-themeisle-blocks-advanced-columns-e62611eb")
55+
.find(".wp-block-themeisle-blocks-advanced-columns-overlay")
56+
.eq(0)
57+
.should("have.attr", "class")
58+
.and("include", "optml-bg-lazyloaded");
59+
});
60+
61+
it("Otter Section Block's Overlay should have background image url optimized (ie. external css is processed)", function () {
62+
cy.get("#wp-block-themeisle-blocks-advanced-columns-e62611eb")
63+
.find(".wp-block-themeisle-blocks-advanced-columns-overlay")
64+
.eq(0)
65+
.should("have.css", "background-image")
66+
.and("match", /url\(.*\.i\.optimole\.com.*\)/);
67+
});
68+
});
69+

inc/compatibilities/otter_blocks.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_otter_blocks.
5+
*
6+
* @reason Adding selectors for background lazyload
7+
*/
8+
class Optml_otter_blocks extends Optml_compatibility {
9+
10+
11+
/**
12+
* Should we load the integration logic.
13+
*
14+
* @return bool Should we load.
15+
*/
16+
function should_load() {
17+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
18+
19+
return is_plugin_active( 'otter-blocks/otter-blocks.php' );
20+
}
21+
22+
/**
23+
* Register integration details.
24+
*/
25+
public function register() {
26+
add_filter(
27+
'optml_lazyload_bg_selectors',
28+
function ( $all_watchers ) {
29+
$all_watchers[] = '.o-flip-front';
30+
$all_watchers[] = '.o-flip-back';
31+
$all_watchers[] = '.wp-block-themeisle-blocks-advanced-columns';
32+
$all_watchers[] = '.wp-block-themeisle-blocks-advanced-columns-overlay';
33+
$all_watchers[] = '.wp-block-themeisle-blocks-advanced-column';
34+
$all_watchers[] = '.wp-block-themeisle-blocks-advanced-column-overlay';
35+
36+
return $all_watchers;
37+
}
38+
);
39+
40+
// Replace the image URL with the optimized one in Otter-generated CSS.
41+
add_filter( 'otter_apply_dynamic_image', [ Optml_Main::instance()->manager->url_replacer, 'build_url' ], 99 );
42+
}
43+
44+
}

inc/manager.php

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ final class Optml_Manager {
8383
'wp_bakery',
8484
'elementor_builder_late',
8585
'wpml',
86+
'otter_blocks',
8687
];
8788
/**
8889
* The current state of the buffer.

0 commit comments

Comments
 (0)