HEX
Server: LiteSpeed
System: Linux s1.hostssdserver.com 4.18.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User: dreamlan (1220)
PHP: 8.3.32
Disabled: exec,system,passthru,shell_exec,proc_open,popen,apache_child_terminate
Upload Files
File: /home/dreamlan/public_html/wp-content/plugins/related-posts-thumbnails/assets/js/lazy-load.js
/**
 * Lazy Load Script
 *
 * This script is responsible for lazy loading images and background images
 * for elements with the classes "rpt-lazyload" and "lazy-load". It uses
 * the IntersectionObserver API to efficiently load images as they enter
 * the viewport.
 */

document.addEventListener("DOMContentLoaded", function() {
    var lazyloadElements = document.querySelectorAll(".rpt-lazyload, .lazy-load");

    if ("IntersectionObserver" in window) {
        var imageObserver = new IntersectionObserver(function(entries, observer) {
            entries.forEach(function(entry) {
                if (entry.isIntersecting) {
                    var element = entry.target;

                    if (element.classList.contains('rpt-lazyload')) {
                        // Handle background images
                        var imageUrl = element.dataset.bg;
                        element.style.backgroundImage = 'url(' + imageUrl + ')';
                    } else if (element.classList.contains('lazy-load')) {
                        // Handle <img> tags
                        var imageUrl = element.dataset.src;
                        element.src = imageUrl;
                    }

                    element.classList.remove("rpt-lazyload", "lazy-load");
                    observer.unobserve(element);
                }
            });
        });

        lazyloadElements.forEach(function(element) {
            imageObserver.observe(element);
        });
    }
});