(function ($) { 'use strict'; const CLS = { lazy: '.ei-lazy', lazyBg: '.ei-lazy-bg', scrollContainer: '.ei-top-article .ei-row', loaded: 'ei-lazy-loaded', loadedBg: 'ei-lazy-bg-loaded', }; const DATA = { boundImg: 'eiLazyBound', boundBg: 'eiLazyBgBound', scrollBound: 'eiScrollBound', }; const OPT = { effect: 'fadeIn', effectTime: 300, threshold: 0 }; const OPT_IMG = OPT; const OPT_BG = Object.assign({ attribute: 'data-bg' }, OPT); function hasLazy() { return !!($.fn && $.fn.Lazy); } function runLazy($els, options, boundKey, loadedClass) { if (!hasLazy() || !$els || !$els.length) return; const $targets = $els.filter(function () { return !this.dataset[boundKey]; }); if (!$targets.length) return; $targets.each(function () { this.dataset[boundKey] = '1'; }); $targets.Lazy(Object.assign({}, options, { afterLoad: function (element) { element.addClass(loadedClass); } })); } function bindScroll($containers) { if (!$containers || !$containers.length) return; $containers.each(function () { const $c = $(this); if ($c.data(DATA.scrollBound)) return; $c.on('scroll', function () { runLazy($c.find(CLS.lazy), OPT_IMG, DATA.boundImg, CLS.loaded); runLazy($c.find(CLS.lazyBg), OPT_BG, DATA.boundBg, CLS.loadedBg); }); $c.data(DATA.scrollBound, true); }); } function boot(root) { const $root = $(root || document); runLazy($root.find(CLS.lazy), OPT_IMG, DATA.boundImg, CLS.loaded); runLazy($root.find(CLS.lazyBg), OPT_BG, DATA.boundBg, CLS.loadedBg); bindScroll($root.find(CLS.scrollContainer)); } // Frontend (DOM Ready) $(function () { boot(document); }); // Elementor Live Editor $(window).on('elementor/frontend/init', function () { if (window.elementorFrontend && elementorFrontend.hooks) { elementorFrontend.hooks.addAction('frontend/element_ready/global', function ($scope) { boot($scope && $scope[0] ? $scope[0] : document); }); } }); })(jQuery);