PageSourceSearch

https://coeliaceasy.com/wp-content/plugins/fifu-premium/includes/html/js/image.js?ver=6.4.1

js coeliaceasy.com collected 2026-10-02 16:11:05 UTC 11,292 bytes, 318 lines download raw bytes

1jQuery(document).ready(function ($) {
2    if (fifuImageVars.fifu_block) {
3        jQuery('body').on('contextmenu', 'img', function (e) {
4            return false;
5        });
6    }
7
8    // forwarding
9    if (fifuImageVars.fifu_redirection && fifuImageVars.fifu_forwarding_url && !fifuImageVars.fifu_is_front_page) {
10        attr = fifuImageVars.fifu_lazy ? 'data-src' : 'src';
11        if (fifuImageVars.fifu_main_image_url)
12            jQuery('img[' + attr + '*="' + fifu_no_protocol(fifuImageVars.fifu_main_image_url) + '"]').wrap('<a href="' + fifuImageVars.fifu_forwarding_url + '" target="_blank"></a>');
13        else
14            jQuery('img[srcset*="' + fifu_no_protocol(fifuImageVars.fifu_local_image_url) + '"]').wrap('<a href="' + fifuImageVars.fifu_forwarding_url + '" target="_blank"></a>');
15    }
16
17    // lazy load
18    if (fifuImageVars.fifu_lazy)
19        fifu_lazy();
20    else {
21        // no WordPress lazy load for the top images
22        jQuery('img').each(function (index) {
23            if (jQuery(this).offset().top < jQuery(window).height()) {
24                jQuery(this).removeAttr('loading');
25            }
26        });
27    }
28
29    // for all images on home/shop
30    if (fifuImageVars.fifu_should_crop) {
31        setTimeout(function () {
32            cropImage();
33        }, parseInt(fifuImageVars.fifu_crop_delay));
34    }
35
36    // woocommerce lightbox/zoom
37    disableClick($);
38    disableLink($);
39
40    // zoomImg
41    setTimeout(function () {
42        jQuery('img.zoomImg').css('z-index', '');
43    }, 1000);
44
45    jQuery('img[height=1]').each(function (index) {
46        if (jQuery(this).attr('width') != 1)
47            jQuery(this).css('position', 'relative');
48    });
49
50    // load more buttons + lazy load
51    jQuery('a.btn-load-more').on('click', function () {
52        fifu_lazy();
53    });
54});
55
56jQuery(document).ajaxComplete(function ($) {
57    // image not found
58    jQuery('div.woocommerce-product-gallery img').on('error', function () {
59        jQuery(this)[0].src = fifuImageVars.fifu_error_url;
60    });
61});
62
63jQuery(window).on('ajaxComplete', function () {
64    if (fifuImageVars.fifu_lazy)
65        fifu_lazy();
66
67    // timeout necessary (load more button of Bimber)
68    setTimeout(function () {
69        if (fifuImageVars.fifu_slider)
70            fifu_slider = fifu_load_slider();
71    }, 300);
72});
73
74jQuery(document).ajaxSuccess(function ($) {
75    if (fifuImageVars.fifu_lazy)
76        fifu_lazy_ajax();
77});
78
79var observer = new MutationObserver(function (mutations) {
80    if (fifuImageVars.fifu_lazy) {
81        mutations.forEach(function (mutation) {
82            mutation.addedNodes.forEach(function (node) {
83                if (jQuery(node).find('img').length > 0) {
84                    // ignore WooCommerce zoom
85                    if (!jQuery(node).hasClass('pswp__zoom-wrap')) {
86                        jQuery(node).find('img').each(function (index) {
87                            // dont touch on slider
88                            if (jQuery(this).attr('src') == 'null' || jQuery(this).hasClass('lazyload') || jQuery(this).parent().hasClass('lslide') || jQuery(this).parent().hasClass('lg-img-wrap'))
89                                return;
90
91                            fifu_lazy_ajax(this);
92                        });
93                    }
94                    return;
95                } else if (jQuery(node).prop('tagName') == 'IMG') {
96                    // ignore WooCommerce zoom
97                    if (!jQuery(node).hasClass('zoomImg'))
98                        fifu_lazy_ajax(node);
99                    return;
100                }
101            });
102        });
103    }
104});
105observer.observe(document, {attributes: false, childList: true, characterData: false, subtree: true});
106
107function cropImage(selector) {
108    if (!selector)
109        selector = fifuImageVars.fifu_crop_default + fifuImageVars.fifu_crop_selectors;
110
111    // get selectors and set individual ratios in a dictionary
112    sel = selector.split(',');
113    dictRatio = {};
114    dicFit = {};
115    selector = '';
116    for (i = 0; i < sel.length; i++) {
117        arr = sel[i].split('|');
118        if (arr.length > 1) {
119            dictRatio[i] = arr[1];
120            if (arr.length > 2)
121                dicFit[i] = arr[2];
122        }
123        selector += arr[0];
124        if (i + 1 < sel.length)
125            selector += ', ';
126    }
127
128    fit = fifuImageVars.fifu_fit;
129
130    // get global ratio
131    global_ratio = fifuImageVars.fifu_crop_ratio;
132    global_ratio_w = global_ratio.split(':')[0];
133    global_ratio_h = global_ratio.split(':')[1];
134
135    // for each selector
136    sel = selector.split(',');
137    for (i = 0; i < sel.length; i++) {
138
139        // define which ratio will be used
140        if (dictRatio) {
141            local_ratio = dictRatio[i];
142            ratio_w = local_ratio ? local_ratio.split(':')[0] : global_ratio_w;
143            ratio_h = local_ratio ? local_ratio.split(':')[1] : global_ratio_h;
144        }
145
146        // define which fit will be used
147        if (dicFit) {
148            local_fit = dicFit[i];
149            fit = local_fit ? local_fit : fit;
150        }
151
152        jQuery(sel[i]).each(function (index) {
153            // ignore fifu slider
154            if (sel[i].trim() === '.fifu-slider')
155                return;
156
157            var width;
158            var backend = false;
159            // a.g1-frame-inner is for bimber theme
160            jQuery(this).find('img, a.g1-frame').each(function (index) {
161                // ignore
162                ignoreSelectors = fifuImageVars.fifu_crop_ignore_parent.split(',');
163                skip = false;
164                for (j = 0; j < ignoreSelectors.length; j++) {
165                    if (jQuery(this).parent().is(ignoreSelectors[j])) {
166                        skip = true;
167                        break
168                    }
169                }
170                if (skip)
171                    return;
172
173                // from backend
174                theme_width = jQuery(this).attr('theme-width');
175                theme_height = jQuery(this).attr('theme-height');
176
177                // from frontend
178                if (!width) {
179                    width = jQuery(this).parent().css('width').replace('px', '');
180                    width = width != 0 ? width : jQuery(this).parent().parent().css('width').replace('px', '');
181                    width = width != 0 ? width : jQuery(this).parent().parent().parent().css('width').replace('px', '');
182                }
183                if (width == '100%') {
184                    width = jQuery(this).parent()[0].clientWidth;
185                    width = width != 0 ? width : jQuery(this).parent().parent()[0].clientWidth;
186                    width = width != 0 ? width : jQuery(this).parent().parent().parent()[0].clientWidth;
187                }
188
189                if (isValidImgClass(jQuery(this).attr('class'))) {
190                    if (fifuImageVars.fifu_should_crop_with_theme_sizes && (backend || (theme_width && theme_height && theme_height != 9999))) {
191                        backend = true;
192                        // backend
193                        jQuery(this).attr('style', jQuery(this).attr('style') + ';height: ' + (width * theme_height / theme_width) + 'px !important');
194                    } else {
195                        // frontend
196                        jQuery(this).attr('style', jQuery(this).attr('style') + ';height: ' + (width * ratio_h / ratio_w) + 'px !important');
197                    }
198                    if (jQuery(this)[0].clientHeight > jQuery(this)[0].clientWidth)
199                        jQuery(this).css('width', '100%');
200                    else
201                        jQuery(this).css('width', width + 'px !important');
202
203                    jQuery(this).css('object-fit', fit ? fit : 'cover');
204
205                    // position
206                    position = jQuery(this).attr('fifu-position');
207                    if (position) {
208                        jQuery(this).css('object-position', position);
209                        jQuery(this).removeAttr('fifu-position');
210                    }
211                }
212            });
213
214            // background images
215            jQuery(this).find('*[style*="background-image"]').each(function (index) {
216                jQuery(this).css('background-size', fit);
217            });
218        });
219    }
220
221    jQuery('a.woocommerce-LoopProduct-link').css('width', '100%');
222}
223
224function isValidImgClass(className) {
225    // bimber
226    return !className || !className.includes('avatar');
227}
228
229function disableClick($) {
230    if (!fifuImageVars.fifu_woo_lbox_enabled) {
231        firstParentClass = '';
232        parentClass = '';
233        jQuery('figure.woocommerce-product-gallery__wrapper').find('div.woocommerce-product-gallery__image').each(function (index) {
234            parentClass = jQuery(this).parent().attr('class').split(' ')[0];
235            if (!firstParentClass)
236                firstParentClass = parentClass;
237
238            if (parentClass != firstParentClass)
239                return false;
240
241            jQuery(this).children().click(function () {
242                return false;
243            });
244            jQuery(this).children().children().css("cursor", "default");
245        });
246    }
247}
248
249function disableLink($) {
250    if (!fifuImageVars.fifu_woo_lbox_enabled) {
251        firstParentClass = '';
252        parentClass = '';
253        jQuery('figure.woocommerce-product-gallery__wrapper').find('div.woocommerce-product-gallery__image').each(function (index) {
254            parentClass = jQuery(this).parent().attr('class').split(' ')[0];
255            if (!firstParentClass)
256                firstParentClass = parentClass;
257
258            if (parentClass != firstParentClass)
259                return false;
260
261            jQuery(this).children().attr("href", "");
262        });
263    }
264}
265
266jQuery(document).ajaxSuccess(function () {
267    if (fifuImageVars.fifu_should_crop) {
268        setTimeout(function () {
269            cropImage();
270        }, parseInt(fifuImageVars.fifu_crop_delay));
271    }
272});
273
274jQuery(document).click(function ($) {
275    fifu_fix_gallery_height();
276})
277
278function fifu_fix_gallery_height() {
279    if (fifuImageVars.fifu_is_flatsome_active) {
280        mainImage = jQuery('.woocommerce-product-gallery__wrapper div.flickity-viewport').find('img')[0];
281        if (mainImage)
282            jQuery('.woocommerce-product-gallery__wrapper div.flickity-viewport').css('height', mainImage.clientHeight + 'px');
283    }
284}
285
286// var resizeWindowTimeout;
287// jQuery(window).on('resize', function (e) {
288// clearTimeout(resizeWindowTimeout);
289// resizeWindowTimeout = setTimeout(fifu_resize_slider, 100);
290// });
291
292// for infinite scroll
293jQuery(document.body).on('post-load', function () {
294    if (fifuImageVars.fifu_lazy)
295        fifu_lazy();
296
297    setTimeout(function () {
298        if (fifuImageVars.fifu_slider)
299            fifu_slider = fifu_load_slider();
300    }, 300);
301});
302
303jQuery('img.lazy').on('appear', function () {
304    if (fifuImageVars.fifu_should_crop)
305        cropImage();
306});
307
308// fix conflict between lazyload and slider (height:0px)
309jQuery('ul#image-gallery > li > img').on('load', function () {
310    if (fifuImageVars.fifu_lazy && !fifuImageVars.fifu_slider_vertical) {
311        if (jQuery(this).parent().hasClass('active'))
312            jQuery(this).parent().parent().css('height', this.clientHeight);
313    }
314});
315
316function fifu_no_protocol(url) {
317    return url.replace(/^https?:\/\//, '');
318}

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.