PageSourceSearch

https://www.greybeardrentals.com/sites/all/modules/bluetent/bt_optimize/js/bto.jquery.js

js greybeardrentals.com collected 2026-10-05 11:42:00 UTC 6,419 bytes, 175 lines download raw bytes

1(function($) {
2    var detectIE = function () {
3        var ua = window.navigator.userAgent;
4
5        var msie = ua.indexOf('MSIE ');
6        if (msie > 0) {
7            // IE 10 or older => return version number
8            return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
9        }
10
11        var trident = ua.indexOf('Trident/');
12        if (trident > 0) {
13            // IE 11 => return version number
14            var rv = ua.indexOf('rv:');
15            return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
16        }
17
18        var edge = ua.indexOf('Edge/');
19        if (edge > 0) {
20            // Edge (IE 12+) => return version number
21            return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
22        }
23
24        // other browser
25        return false;
26    }
27    var beforeDoc = true;
28    var LazyLoadImgIO = (typeof IntersectionObserver == 'undefined' || detectIE()) ? undefined : new IntersectionObserver(function(entries) {
29        for(ind in entries) {
30            if(entries[ind].isIntersecting) {
31                swapOut(entries[ind].target)
32                LazyLoadImgIO.unobserve(entries[ind].target)
33            }
34        }
35    }, {rootMargin: "80px 0px 80px 0px"});
36    var LazyLoadJumpIO = (typeof IntersectionObserver == 'undefined' || detectIE()) ? undefined : new IntersectionObserver(function(entries) {
37        for(ind in entries) {
38            if(entries[ind].isIntersecting) {
39                lazyJump(entries[ind].target)
40                LazyLoadJumpIO.unobserve(entries[ind].target)
41            }
42        }
43    }, {rootMargin: "80px 0px 80px 0px"});
44    var LazyLoadBackgroundImgIO = (typeof IntersectionObserver == 'undefined' || detectIE()) ? undefined : new IntersectionObserver(function(entries) {
45        for(ind in entries) {
46            if(entries[ind].isIntersecting) {
47                swapBackgroundOut(entries[ind].target)
48                LazyLoadBackgroundImgIO.unobserve(entries[ind].target)
49            }
50        }
51    }, {rootMargin: "80px 0px 80px 0px"});
52
53    var swapOut = function(elem) {
54      var $elem = $(elem),
55        srcset;
56      if (beforeDoc) {
57        setSrc($elem);
58      } else {
59        srcset = $elem.attr('data-srcset');
60        if (srcset) {
61          srcset = 'srcset="' + srcset + '" ';
62        }
63
64        $('<img src="' + $elem.attr('data-src') + '" ' + srcset + '/>').on('load', function() {
65          setSrc($elem);
66        });
67      }
68    }
69    function setSrc($elem) {
70      var src = $elem.attr('data-src'),
71        srcset = $elem.attr('data-srcset');
72      $elem.attr('src', src);
73      $elem.addClass('bto-lazy-loaded').removeClass('bto-lazy');
74      if (srcset) {
75        $elem.attr('srcset', srcset);
76      }
77    }
78    var lazyJump = function(elem) {
79        $.get($(elem).attr('data-bto-jump-select'), function(data) {
80            var sel = $(data)
81                $(sel).addClass('bto-lazy-loaded').removeClass('bto-lazy')
82            $(elem).replaceWith(sel)
83           Drupal.attachBehaviors(sel, Drupal.settings)
84        });
85    }
86    var swapBackgroundOut = function(elem) {
87        // Get the background info.
88        let background = elem.getAttribute("data--bto-lazy-background");
89        let backgroundImage = elem.getAttribute("data--bto-lazy-background-image");
90
91        // No background info, nothing left to do.
92        if (!background && !backgroundImage) {
93            return;
94        }
95
96        // Update the css property with the one coming from lazy load context.
97        background && (elem.style.background = background);
98        backgroundImage && (elem.style.backgroundImage = backgroundImage);
99    }
100
101    var lazyLoad = function(context) {
102        $('img[data-src].bto-lazy', context).once('btoLazyLoad', function() {
103            if(typeof LazyLoadImgIO != 'undefined') {
104                LazyLoadImgIO.observe(this)
105            } else {
106                swapOut(this)
107            }
108        })
109        $('div.bto-lazy-jump', context).once('btoLazyLoad', function() {
110            if(typeof LazyLoadJumpIO != 'undefined') {
111                LazyLoadJumpIO.observe(this)
112            } else {
113                lazyJump(this)
114            }
115        })
116
117        // Locate all elements with background images intended to be lazy loaded.
118        // This is done by using a css variable, so stylesheet are checked instead
119        // of elements.
120        for (let x = 0; x < document.styleSheets.length; x++) {
121            let rules = [];
122
123            try {
124                // Get all rules from current stylesheet.
125                rules = document.styleSheets[x].cssRules;
126            } catch {
127                // rules cannot be loaded/accessed, keep checking next style sheet.
128                continue;
129            }
130
131            // Check every rule.
132            for (let i = 0; i < rules.length; i++) {
133                // Ensure rule has style.
134                if (!rules[i].style) {
135                    continue;
136                }
137
138                // Check for the properties to lazy load.
139                let background = rules[i].style.getPropertyValue("--bto-lazy-background");
140                let backgroundImage = rules[i].style.getPropertyValue("--bto-lazy-background-image");
141
142                // Nothing setup for lazy load, do nothing else.
143                if (!background && !backgroundImage) {
144                    continue;
145                }
146
147                // Get the selector for the rule that has background lazy load logic.
148                let selector = rules[i].selectorText;
149
150                // Attach the lazy load process for background images.
151                $(selector, context).once('btoLazyLoad', function() {
152                    // Pass info about lazy backgrounds for the element.
153                    this.setAttribute('data--bto-lazy-background', background);
154                    this.setAttribute('data--bto-lazy-background-image', backgroundImage);
155
156                    if(typeof LazyLoadBackgroundImgIO != 'undefined') {
157                        LazyLoadBackgroundImgIO.observe(this);
158                    } else {
159                        swapBackgroundOut(this);
160                    }
161                })
162            }
163        }
164    }
165
166    Drupal.behaviors.btoLazyLoad = {
167        attach: function(context) {
168            lazyLoad(context)
169        }
170    }
171    lazyLoad(document)
172    $(document).ready(function() {
173        beforeDoc = false
174    })
175})(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.