PluginProbe
Elementor Website Builder – more than just a page builder / 3.21.3
Elementor Website Builder – more than just a page builder v3.21.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | modules/lazyload/module.php +46 -37 4.2.13.21.3 View file →
@@ -1,20 +1,39 @@
1 1 <?php
2 2 namespace Elementor\Modules\LazyLoad;
3 3
4 4 use Elementor\Core\Base\Module as BaseModule;
5 +use Elementor\Core\Experiments\Manager as Experiments_Manager;
5 6 use Elementor\Plugin;
6 7
7 8 if ( ! defined( 'ABSPATH' ) ) {
8 - exit; // Exit if accessed directly.
9 + exit; // Exit if accessed directly
9 10 }
10 11
11 12 class Module extends BaseModule {
12 13
14 + const EXPERIMENT_NAME = 'e_lazyload';
15 +
13 16 public function get_name() {
14 17 return 'lazyload';
15 18 }
16 19
20 + public static function get_experimental_data() {
21 + return [
22 + 'name' => static::EXPERIMENT_NAME,
23 + 'title' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
24 + 'tag' => esc_html__( 'Performance', 'elementor' ),
25 + 'description' => esc_html__( 'Lazy loading images that are not in the viewport improves initial page load performance and user experience. By activating this experiment all background images except the first one on your page will be lazy loaded to improve your LCP score', 'elementor' ),
26 + 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA,
27 + 'default' => Experiments_Manager::STATE_INACTIVE,
28 + 'new_site' => [
29 + 'default_active' => true,
30 + 'minimum_installation_version' => '3.21.0',
31 + ],
32 + 'generator_tag' => true,
33 + ];
34 + }
35 +
17 36 public function __construct() {
18 37 parent::__construct();
19 38
20 39 add_action( 'init', [ $this, 'init' ] );
@@ -20,14 +39,10 @@
20 39 add_action( 'init', [ $this, 'init' ] );
21 40 }
22 41
23 42 public function init() {
24 - if ( ! $this->is_lazy_load_background_images_enabled() ) {
25 - return;
26 - }
27 -
28 43 add_action( 'wp_head', function() {
29 - if ( ! $this->should_lazy_load_background_images() ) {
44 + if ( ! $this->should_lazyload() ) {
30 45 return;
31 46 }
32 47 ?>
33 48 <style>
@@ -51,48 +66,42 @@
51 66 <?php
52 67 } );
53 68
54 69 add_action( 'wp_footer', function() {
55 - if ( ! $this->should_lazy_load_background_images() ) {
70 + if ( ! $this->should_lazyload() ) {
56 71 return;
57 72 }
58 73 ?>
59 - <script>
60 - ( () => {
61 - const lazyloadRunObserver = () => {
62 - const lazyloadBackgrounds = document.querySelectorAll( `.e-con.e-parent:not(.e-lazyloaded)` );
63 - const lazyloadBackgroundObserver = new IntersectionObserver( ( entries ) => {
64 - entries.forEach( ( entry ) => {
65 - if ( entry.isIntersecting ) {
66 - let lazyloadBackground = entry.target;
67 - if( lazyloadBackground ) {
68 - lazyloadBackground.classList.add( 'e-lazyloaded' );
69 - }
70 - lazyloadBackgroundObserver.unobserve( entry.target );
74 + <script type='text/javascript'>
75 + const lazyloadRunObserver = () => {
76 + const lazyloadBackgrounds = document.querySelectorAll( `.e-con.e-parent:not(.e-lazyloaded)` );
77 + const lazyloadBackgroundObserver = new IntersectionObserver( ( entries ) => {
78 + entries.forEach( ( entry ) => {
79 + if ( entry.isIntersecting ) {
80 + let lazyloadBackground = entry.target;
81 + if( lazyloadBackground ) {
82 + lazyloadBackground.classList.add( 'e-lazyloaded' );
71 83 }
72 - });
73 - }, { rootMargin: '200px 0px 200px 0px' } );
74 - lazyloadBackgrounds.forEach( ( lazyloadBackground ) => {
75 - lazyloadBackgroundObserver.observe( lazyloadBackground );
76 - } );
77 - };
78 - const events = [
79 - 'DOMContentLoaded',
80 - 'elementor/lazyload/observe',
81 - ];
82 - events.forEach( ( event ) => {
83 - document.addEventListener( event, lazyloadRunObserver );
84 + lazyloadBackgroundObserver.unobserve( entry.target );
85 + }
86 + });
87 + }, { rootMargin: '200px 0px 200px 0px' } );
88 + lazyloadBackgrounds.forEach( ( lazyloadBackground ) => {
89 + lazyloadBackgroundObserver.observe( lazyloadBackground );
84 90 } );
85 - } )();
91 + };
92 + const events = [
93 + 'DOMContentLoaded',
94 + 'elementor/lazyload/observe',
95 + ];
96 + events.forEach( ( event ) => {
97 + document.addEventListener( event, lazyloadRunObserver );
98 + } );
86 99 </script>
87 100 <?php
88 101 } );
89 102 }
90 103
91 - private function should_lazy_load_background_images(): bool {
104 + private function should_lazyload() {
92 105 return ! is_admin() && ! Plugin::$instance->preview->is_preview_mode() && ! Plugin::$instance->editor->is_edit_mode();
93 - }
94 -
95 - private static function is_lazy_load_background_images_enabled(): bool {
96 - return '1' === get_option( 'elementor_lazy_load_background_images', '1' );
97 106 }
98 107 }