PageSourceSearch

https://lab-iq.ru/wp-content/themes/miniapp/js/skeleton-loader.js?ver=47.9.5

js lab-iq.ru collected 2026-10-04 19:31:02 UTC 3,174 bytes, 77 lines download raw bytes

1(function ($) {
2    /**
3     * Инициализирует ленивую загрузку изображений в указанном контексте.
4     * @param {jQuery|HTMLElement|string} context - область, в которой ищем изображения.
5     */
6    function initLazyLoading(context) {
7        var $context = $(context);
8        var images = $context.find(".lazyload");
9
10        if ("IntersectionObserver" in window) {
11            var observer = new IntersectionObserver(function (entries, observer) {
12                entries.forEach(function (entry) {
13                    if (entry.isIntersecting) {
14                        var img = $(entry.target);
15                        // Загружаем изображение
16                        loadImage(img);
17                        // Прекращаем наблюдение за этим элементом
18                        observer.unobserve(entry.target);
19                    }
20                });
21            }, {
22                rootMargin: "200px" // Загрузка начинается за 200px до появления в области видимости
23            });
24
25            // Наблюдаем за всеми найденными изображениями
26            images.each(function () {
27                observer.observe(this);
28            });
29        } else {
30            // Fallback для старых браузеров
31            images.each(function () {
32                var img = $(this);
33                loadImage(img);
34            });
35        }
36    }
37
38    /**
39     * Функция загрузки изображения и скрытия скелета.
40     * @param {jQuery} img - элемент изображения.
41     */
42    function loadImage(img) {
43        var skeleton = img.closest(".product-image, .swiper-slide").find(".skeleton");
44        var dataSrc = img.attr("data-src");
45
46        if (!dataSrc || dataSrc.trim() === "") {
47            return;
48        }
49
50        img.attr("src", dataSrc)
51            .on("load", function () {
52                if (skeleton.length > 0) {
53                    skeleton.fadeOut();
54                }
55                img.css({ opacity: 1 });
56            })
57            .on("error", function () {
58                if (skeleton.length > 0) {
59                    skeleton.replaceWith('<div class="error-placeholder"><img src="/wp-content/themes/miniapp/img/no-image.svg" alt="Нет изображения"></div>');
60                }
61            });
62    }
63
64    // Инициализация ленивой загрузки при загрузке страницы
65    $(document).ready(function () {
66        initLazyLoading(document);
67    });
68	
69	// Переинициализация lazyload после обновления корзины
70	$(document.body).on('updated_cart_totals', function () {
71		initLazyLoading(document);
72	});
73
74
75    // Делаем функцию доступной глобально, чтобы её можно было вызвать для нового контента (например, после AJAX)
76    window.initLazyLoading = initLazyLoading;
77})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.