PageSourceSearch

https://garringtoneastmidlands.co.uk/wp-content/themes/garrington/assets/js/speedup.js?ver=1646914159

js garringtoneastmidlands.co.uk collected 2026-10-07 17:26:56 UTC 10,180 bytes, 367 lines download raw bytes

1var imageResize = function() {};
2var lazy_iframe = function() {};
3var lazy_gmaps = function() {};
4var deep_is_visible = function(a,b) {};
5var _canUseWebP = null;
6var canUseWebP = function () {
7    if (_canUseWebP === null) {
8        var elem = document.createElement('canvas');
9
10        if (!!(elem.getContext && elem.getContext('2d'))) {
11            // was able or not to get WebP representation
12            _canUseWebP = elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
13        }
14
15        // very old browser like IE 8, canvas not supported
16        if (_canUseWebP === null) {
17            _canUseWebP = false;
18        }
19    }
20    return _canUseWebP;
21};
22
23jQuery(document).ready(function ($) {
24
25
26    var $b = $('body');
27
28    var loadingImagesCount = 0;
29    var maxImageSize = 2000;
30
31    imageResize = function (resize) {
32
33        resize = typeof resize === 'undefined' ? true : resize;
34
35        var ratio = !!window.devicePixelRatio ? window.devicePixelRatio : 1;
36
37        $b.find('.imageResize').each(function () {
38
39            var $s = $(this),
40                $p = $(this).parent(),
41                src = $s.data('src'),
42                w = $s.data('width'),
43                h = $s.data('height'),
44                cw,
45                ch,
46                o_cw = $s.attr('data-cw'),
47                o_ch = $s.attr('data-ch'),
48                meta = $s.data('meta');
49
50            // lazy load
51            if (!$s.hasClass('ignoreIsVisible') && !deep_is_visible($s)) {
52                return true;
53            }
54
55            if (!resize && typeof $s.attr('src') !== 'undefined') {
56                return true;
57            }
58
59            if ($s.hasClass('print-full')) {
60                $s.attr('src', src);
61                return true;
62            }
63
64            $s.removeAttr('data-meta').data('meta', meta);
65
66            if ($s.css('object-fit') === 'cover') {
67
68                cw = Math.round($p.outerWidth());
69                ch = Math.round($p.outerHeight());
70
71            } else if ($s.css('object-fit') === 'contain') {
72
73                cw = $p.outerWidth();
74                ch = $p.outerHeight();
75
76                var tw = Math.round(ch * w / h);
77                var th = Math.round(cw * h / w);
78
79                var a = w / h;
80                var ta = tw / th;
81
82                if (a > ta) {
83                    cw = tw;
84                } else {
85                    ch = th;
86                }
87
88            } else {
89                // auto
90                cw = $p.outerWidth();
91                ch = Math.round(cw * h / w);
92            }
93
94            // debug
95            // $s.attr('tmp', 'cw: '+cw+' ch: '+ch+' w:' + w+' ratio:' + ratio+' h:' + h);
96
97            cw = Math.round(cw * ratio);
98            ch = Math.round(ch * ratio);
99
100            cw = cw > maxImageSize ? maxImageSize : cw;
101            ch = ch > maxImageSize ? maxImageSize : ch;
102
103            var cw_1 = ceil_100(cw);
104
105            var ch_1 = Math.round(cw_1 * ch / cw);
106            var ch_2 = ceil_100(ch);
107
108            var cw_2 = Math.round(ch_2 * cw / ch);
109
110            var con = Math.abs(w + h * cw_1 * ch_1) < Math.abs(w * h - cw_2 * ch_2);
111            if (cw >= maxImageSize) {
112                con = true;
113            } else if (ch >= maxImageSize) {
114                con = false;
115            }
116            cw = con ? cw_1 : cw_2;
117            ch = con ? ch_1 : ch_2;
118
119            if (cw > o_cw && ch > o_ch) {
120
121                $s.attr('data-cw', cw);
122                $s.attr('data-ch', ch);
123
124                var key;
125
126
127                if (cw > w || ch > h) {
128                    if (w > maxImageSize && h > maxImageSize) {
129                        key = (maxImageSize - 1) + 'x' + (maxImageSize - 1);
130                    } else if (w > maxImageSize) {
131                        key = (maxImageSize - 1) + 'x' + (h - 1);
132                    } else if (h > maxImageSize) {
133                        key = (w - 1) + 'x' + (maxImageSize - 1);
134                    } else {
135                        if(cw > w){
136                            key = (w - 1) + 'x' + ch;
137                        }else{
138                            key = cw + 'x' + (h - 1);
139                        }
140                    }
141                } else {
142                    key = cw + 'x' + ch;
143                }
144
145                var suffix = '-' + key;
146
147
148                if (canUseWebP()) {
149                    src = src.replace(/.(jpg|png)$/, '.webp');
150                }
151
152                src = src.replace(/.(jpg|png|webp)$/, suffix + '.$1');
153
154                var type = src.match(/.(jpg|jpeg|png|webp)$/);
155                if (type !== null) {
156                    var suffix2 = key + type[0];
157                    if ($.inArray(suffix2, meta) === -1 && new RegExp('jpg|jpeg|png|webp').test(src) && !$('html').hasClass('LOCAL_WEBSITE')) {
158                        // src += '/';
159                    }
160                }
161
162                $s.attr('src', src);
163
164                loadingImagesCount++;
165            }
166        });
167    };
168
169    // return true if item is visible on the screen based on
170    // its position, document scroll and dimensions
171    deep_is_visible = function($s, viewportRatio) {
172
173        var windowHeight = $(window).height();
174        viewportRatio = typeof viewportRatio === 'undefined' ? 0.5 : viewportRatio;
175        var increaseViewportBy = (viewportRatio * windowHeight);
176
177        var docViewTop = $(window).scrollTop();
178        var docViewBottom = docViewTop + windowHeight;
179
180        var elemTop = $s.offset().top;
181        var elemBottom = elemTop + $s.outerHeight();
182        if (!((elemTop - increaseViewportBy < docViewBottom) && (elemBottom + increaseViewportBy > docViewTop))) {
183            return false;
184        }
185
186        var docViewLeft = $(window).scrollLeft();
187        var docViewRight = docViewLeft + $(window).width();
188
189        var elemLeft = $s.offset().left;
190        var elemRight = elemLeft + $s.outerWidth();
191
192        if (!((elemLeft < docViewRight) && (elemRight > docViewLeft))) {
193            return false
194        }
195
196        return !parentIsHidden($s);
197    };
198
199    function parentIsHidden($s) {
200
201        var is_hidden = $s.css('display') === 'none' || $s.css('opacity') === '0';
202
203        if (!is_hidden && !$s.parent().is('body')) {
204            is_hidden = parentIsHidden($s.parent());
205        }
206
207        return is_hidden;
208    }
209
210    var timeoutID = false;
211    $(window).resize(function() {
212        clearTimeout(timeoutID);
213        timeoutID = setTimeout(imageResize, 200);
214        setTimeout(lazy_gmaps, 500);
215    });
216
217    $(window).scroll(function() {
218        imageResize(false);
219        lazy_iframe();
220        lazyFormRecaptcha();
221        lazy_gmaps();
222    });
223
224    $(document).ajaxSuccess(function () {
225        setTimeout(imageResize, 500);
226        setTimeout(lazy_iframe, 500);
227    });
228
229    setTimeout(imageResize, 500);
230    setTimeout(lazy_iframe, 500);
231    setTimeout(lazyFormRecaptcha, 500);
232    setTimeout(lazy_gmaps, 500);
233
234    $("#mc-embedded-subscribe").on('click', function(e) {
235        setTimeout(lazyFormRecaptcha, 500);
236    });
237
238    $('.imageResize').on('load', function(){
239        loadingImagesCount--;
240    });
241
242    var videoQueue = [];
243
244    lazy_iframe = function() {
245
246        $('.lazy-iframe').each(function () {
247
248            var $v = $(this);
249            if (!$v.hasClass('init')) {
250                $v.addClass('init');
251                videoQueue.push($v);
252            }
253        });
254    };
255    function tryLoadVideo() {
256        if (loadingImagesCount < 1 && videoQueue.length > 0) {
257            $.each(videoQueue, function (i, $s) {
258
259                if (!deep_is_visible($s,0)) {
260                    return true;
261                }
262
263                if ($s.is('iframe')) {
264                    $s.attr('src', $s.data('src'));
265                    $s.addClass('loaded');
266                }
267
268                videoQueue.splice(i , 1);
269                return false;
270            });
271        }
272    }
273
274    setInterval(function () {
275        tryLoadVideo();
276    }, 1000);
277
278    function ceil_100(x) {
279        return Math.ceil(x / 100) * 100
280    }
281
282
283    function lazyFormRecaptcha() {
284
285        $('.ginput_container.ginput_recaptcha').closest('.gform_wrapper').each(function () {
286
287            var $s = $(this);
288
289            if (!deep_is_visible($s, 0.5)) {
290                return true;
291            }
292
293            if (typeof __gform_recaptcha === 'function') {
294                __gform_recaptcha();
295            }
296        });
297    }
298
299    $('.carousel2').each(function () {
300        var $s = $(this);
301        $s.flexslider({
302            slideshow: true,
303            after: function () {
304                show_next_slide($s.find('.flex-active-slide'));
305            }
306        });
307        show_next_slide($s.find('.flex-active-slide'));
308    });
309
310
311    function show_next_slide($s) {
312        $s.find('img').addClass('ignoreIsVisible');
313        var $n = $s.next();
314        if (!$n.length){
315            return;
316        }
317        $n.find('img').addClass('ignoreIsVisible');
318        var opacity = parseInt($n.css('opacity'));
319        var transition = $n.css('transition');
320        $n.css({
321            'opacity': '0.001',
322            'margin-right': '0',
323            'transition': 'none',
324        });
325        imageResize();
326        $n.css({
327            'opacity': opacity,
328            'margin-right': '-100%',
329            'transition': transition,
330        });
331    }
332
333    $(document).on('gform_post_render', function (event, form_id, current_page) {
334        if (typeof renderRecaptcha === 'function') {
335            //renderRecaptcha();
336        }
337    });
338
339    lazy_gmaps = function() {
340
341        $('.lazy-map').each(function () {
342
343            var $map = $(this);
344
345            if($map.hasClass('loaded')){
346                return true;
347            }
348
349            if (!$map.hasClass('ignoreIsVisible') && !deep_is_visible($map)) {
350                return true;
351            }
352
353            var frame = document.createElement('iframe');
354            frame.src = $map.data('src');
355            frame.width = "100%";
356            frame.height = "290";
357            frame.frameborder = "0";
358            frame.style.border = "0";
359            $map.append(frame);
360
361            $map.addClass('loaded');
362
363        });
364    };
365
366});
367

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.