PageSourceSearch

https://sopa.org/wp-content/plugins/tenweb-speed-optimizer/include…/js/vanilla-lazyload/two_bg_vanilla.js

js sopa.org collected 2026-10-02 11:00:14 UTC 3,243 bytes, 92 lines download raw bytes

1window.onload = function () {
2    two_replace_backgrounds();
3};
4window.addEventListener( 'elementor/frontend/init', () => {
5    elementorFrontend.hooks.addAction( 'frontend/element_ready/global', function( $scope ) {
6        $scope.find("*").addClass("two_elementor_element");
7        two_replace_backgrounds($scope.get( 0 ));
8    } );
9} );
10
11let twbb_slides_wrapper = document.querySelectorAll(".twbb_slides-wrapper , .e-flex.elementor-element");
12if (twbb_slides_wrapper.length > 0) {
13    window.onscroll = function() {
14        two_calculate_position(twbb_slides_wrapper);
15    }
16
17}
18
19
20function two_calculate_position(lazy_elements) {
21    lazy_elements.forEach(function(element) {
22        if(!element.classList.contains("two_bg_lazy_init")){
23            let scrollPosition = window.scrollY || document.documentElement.scrollTop;
24            let element_top = two_get_element_position(element).top;
25            if(parseInt(element_top) < parseInt(scrollPosition)+500){
26                element.classList.add("two_bg_lazy_init");
27                two_replace_backgrounds();
28                two_lazyLoadInstance.update();
29            }
30        }
31    });
32}
33
34function two_get_element_position(element) {
35    const rect = element.getBoundingClientRect();
36    const scrollLeft = window.scrollX || document.documentElement.scrollLeft;
37    const scrollTop = window.scrollY || document.documentElement.scrollTop;
38    return {
39        top: rect.top + scrollTop,
40        left: rect.left + scrollLeft
41    };
42}
43
44
45function two_replace_backgrounds(elementor_elements = false) {
46    let two_elements_list;
47    if(!elementor_elements){
48        two_elements_list = document.querySelectorAll("*:not(br):not(hr):not(iframe):not(pre)");
49    }else{
50        two_elements_list = elementor_elements.querySelectorAll(".two_elementor_element");
51    }
52    two_elements_list.forEach((elem) => {
53        let style = elem.currentStyle || window.getComputedStyle(elem, false);
54
55        let bg_image = style.backgroundImage;
56
57        if (bg_image === 'none' || bg_image.indexOf(window['two_svg_placeholder']) === -1) {
58            return;
59        }
60
61        bg_image = bg_image.replace(window['two_svg_placeholder'], "");
62        if (!bg_image) {
63            return;
64        }
65
66        elem.classList.add("two_bg");
67        elem.classList.add("lazy");
68        elem.classList.remove("two_elementor_element");
69        elem.setAttribute("data-bg-multi", bg_image);
70    });
71
72    if (typeof two_lazyLoadInstance === "undefined") {
73         window.two_lazyLoadInstance = new LazyLoad({
74            'callback_applied': function(element, instance){
75                let settings = instance._settings;
76                var bgDataValue = element.getAttribute("data-" + settings.data_bg_multi);
77                if (!bgDataValue) {
78                    return;
79                }
80
81                if(window.getComputedStyle(element).getPropertyValue("background-image") !== bgDataValue) {
82                    let style = element.getAttribute("style");
83                    style += "background-image: " + bgDataValue + " !important;";
84                    element.setAttribute("style", style);
85                }
86            }
87        });
88    } else {
89        two_lazyLoadInstance.update();
90    }
91}
92

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.