PageSourceSearch

https://www.cookfood.net/Content/scripts/cookfood.js?202609221200

js cookfood.net collected 2026-09-25 19:53:50 UTC 31,259 bytes, 1,073 lines download raw bytes

1var res;
2
3
4var lastUrl = '';
5
6$.fn.redraw = function () {
7    $(this).each(function () {
8        var redraw = this.offsetHeight;
9    });
10};
11
12
13jQuery.extend({
14    postJSON: function (params) {
15        return jQuery.ajax(jQuery.extend(params, {
16            type: "POST",
17            data: JSON.stringify(params.data),
18            dataType: "json",
19            contentType: "application/json",
20            processData: false
21        }));
22    }
23});
24
25var _lbTop = 0;
26
27 
28
29var showLightbox = function (url) {
30    // show lightbox for delivery logon
31    var lb = $('#lb');
32    _lbTop = $('body').scrollTop();
33    if ($(window).width() < 400) {
34        $('body').addClass('fixed');
35    }
36    lb.empty();
37    lb.removeClass('hidden');
38
39    var ol = $('<div class="overlay" />');;
40    ol.fadeTo(0, 0.7);
41    ol.appendTo(lb);
42    ol.click(function (x) {
43        lb.fadeOut(200);
44        $('body').scrollTop(_lbTop);
45        $('body').removeClass('fixed');
46    });
47
48    //Menu.cont = $('<div class="content" />');
49
50    var content = $('<div class="content" />');
51    content.appendTo(lb);
52
53    //Menu.cont.appendTo(lb);
54
55    var close = $('<img class="lbclose" src="/images/lightboxClose.png" width="38" height="38" alt="Close" title="Close" />');// new Element('img', { 'class': 'lbclose', 'src': '/newcook/images/lightboxClose.png', 'width': '38', 'height': '38', 'alt': 'Close', 'title': 'Close' });
56
57
58    close.click(function (x) { lb.fadeOut(0); $('body').removeClass('fixed'); });
59    close.appendTo(lb);
60
61    lb.fadeIn(200);
62
63    var ifr = $('<iframe border="0" width="100%" height="600" style="border:none" />');
64    ifr.attr('src', url);
65    //ifr.appendTo(Menu.cont);
66    ifr.appendTo(content);
67
68
69
70    var setClosePos = function () {
71
72        close.css('margin-left',   $('#lb .content').width() /2 - 15);
73    }
74    setClosePos();
75    $(window).resize(function () { setClosePos(); });
76}
77
78var showContentLightbox = function (content) {
79    // show lightbox for delivery logon
80    var lb = $('#lb');
81    _lbTop = $('body').scrollTop();
82    if ($(window).width() < 400) {
83        $('body').addClass('fixed');
84    }
85    lb.empty();
86    lb.removeClass('hidden');
87
88    var ol = $('<div class="overlay" />');;
89    ol.fadeTo(0, 0.7);
90    ol.appendTo(lb);
91    ol.click(function (x) {
92        lb.fadeOut(200);
93    });
94
95    //Menu.cont = $('<div class="content" />');
96
97    var contentOuter = $('<div class="content" />');
98    contentOuter.appendTo(lb);
99
100    //Menu.cont.appendTo(lb);
101
102    var close = $('<img class="lbclose" src="/images/lightboxClose.png" width="38" height="38" alt="Close" title="Close" />');// new Element('img', { 'class': 'lbclose', 'src': '/newcook/images/lightboxClose.png', 'width': '38', 'height': '38', 'alt': 'Close', 'title': 'Close' });
103
104
105    close.click(function (x) {
106        lb.fadeOut(0);
107        $('body').scrollTop(_lbTop);
108        $('body').removeClass('fixed');
109    });
110    close.appendTo(lb);
111
112    lb.fadeIn(200);
113
114    contentOuter.html(content);
115
116    contentOuter.find('.popup-continue-shopping').click(function (a) {
117        a.preventDefault();
118
119        lb.fadeOut(0);
120    });
121
122
123    var setClosePos = function () {
124
125        close.css('margin-left', $('#lb .content').width() / 2 - 15);
126    }
127    setClosePos();
128    $(window).resize(function () { setClosePos(); });
129}
130
131
132
133
134$(function () {
135
136    $.fn.serializeObject = function () {
137        "use strict";
138
139        var result = {};
140        var extend = function (i, element) {
141            var node = result[element.name];
142
143            // If node with same name exists already, need to convert it to an array as it
144            // is a multi-value field (i.e., checkboxes)
145
146            if ('undefined' !== typeof node && node !== null) {
147                if ($.isArray(node)) {
148                    node.push(element.value);
149                } else {
150                    result[element.name] = [node, element.value];
151                }
152            } else {
153                result[element.name] = element.value;
154            }
155        };
156
157        $.each(this.serializeArray(), extend);
158        return result;
159    };
160
161
162
163    var closePopup = function () {
164        $('.signuppopup,.signupoverlay').fadeOut(1000);
165    };
166
167    $('.signupoverlay').click(function (e) {
168        e.preventDefault();
169        closePopup();
170    });
171
172    $('.signuppopup .closepopup').click(function (e) {
173        e.preventDefault();
174        closePopup();
175    });
176    setTimeout(function () { $('.signuppopup').fadeIn(1000); }, 10000);
177
178    $('.signuppopup form').submit(function (e) {
179        e.preventDefault();
180        var _t = $(this);
181        var data = _t.serializeObject();
182        var url = _t.attr('action');
183
184        console.log(data);
185
186        _t.find('.popuperror').addClass('hidden');
187        _t.find('.optinerror').addClass('hidden');
188        _t.find('.invalidemailerror').addClass('hidden');
189
190        $.postJSON({
191            url: url, data: data, success: function (data) {
192                if (data.alreadyRegistered) {
193                    $('.signupstart').addClass('hidden');
194                    $('.alreadyregistered').removeClass('hidden');
195                    setTimeout(closePopup, 2500);
196                }
197                else if (data.OK) {
198                    if (typeof fbq !== 'undefined') {
199                        fbq('track', 'Lead', { content_name: 'Newsletter Sign Up' });
200                    }
201                    if (typeof dataLayer !== 'undefined') {
202                        dataLayer.push({
203                            'event': 'GAEvent',
204                            'eventCategory': 'Newsletter',
205                            'eventAction': 'Subscribe',
206                            'eventLabel': 'Popup Signup'
207                        });
208                    }
209
210                    $('.signupstart').addClass('hidden');
211                    $('.thankstext').removeClass('hidden');
212
213                    var email = data.Email;
214                    var SDK_ID = data.Guid;
215                    var event_name = 'popup-signup';
216                    var parameters = {
217                        newsletter_signup: true,
218                        source: data.Source
219                    };
220                    if (typeof optimoveSDK !== 'undefined') {
221                        optimoveSDK.API.registerUser(SDK_ID, email, event_name, parameters);
222                    }
223
224
225                    setTimeout(closePopup, 2500);
226
227                }
228                else {
229                    console.log(data.Name, data.Email, data.OptIn);
230
231                    if (data.OptIn != "on") {
232                        _t.find('.optinerror').removeClass('hidden');
233                    }
234
235                    if (data.Name == null || data.Email == null) {
236                        _t.find('.popuperror').removeClass('hidden');
237                    }
238                    else {
239                        _t.find('.invalidemailerror').removeClass('hidden');
240                    }
241                }
242            }
243        });
244    });
245
246    $('.importantinfo').click(function () {
247        $(this).toggleClass('active');
248    });
249
250    $('body').on('click', '.stockcheckclose', function () {
251        $('.stockcheckresults').addClass('hidden');
252    });
253
254    $('body').on('click', '.confirmservicechange', function () {
255        $(this).next().removeClass('hidden');
256    });
257
258    $('body').on('click', '.hovertoggle', function (a) {
259        a.preventDefault();
260        $('.hovertoggle').addClass('hidden');
261        $('.hovercontainer').slideDown(1000);
262    });
263
264    //mobile dropdown
265    $('body').on('click', '.mobile-dropdown-home', function (a) {
266        a.preventDefault();
267        if ($('.mobile-dropdown-home').text() == "More Details") {
268            $('.mobile-dropdown-home').text("Hide Details");
269        } else {
270            $('.mobile-dropdown-home').text("More Details");
271        }
272        $('.mobile-dropdown-content').toggleClass('active');
273    });
274
275    //mobile dropdown
276    $('body').on('click', '.mobile-dropdown-cc', function (a) {
277        a.preventDefault();
278        if ($('.mobile-dropdown-cc').text() == "More Details") {
279            $('.mobile-dropdown-cc').text("Hide Details");
280        } else {
281            $('.mobile-dropdown-cc').text("More Details");
282        }
283        $('.mobile-dropdown-contentCC').toggleClass('active');
284    });
285    
286    $('body').on('click', '.pointerclose', function (a) {
287        a.preventDefault();
288        $('.hovertoggle').removeClass('hidden');
289        $('.hovercontainer').slideUp(1000);
290    });
291
292    $('body').on('click', '.hoverclose', function (a) {
293        a.preventDefault();
294        $('.hovertoggle').removeClass('hidden');
295        $('.hovercontainer').slideUp(1000);
296    });
297
298    $('body').on('click', '#toggleclickcollectswitch', function (e) {
299        e.preventDefault();
300        $('.clickcollectswitch').toggleClass('hidden');
301    });
302
303  
304
305    $('body').on('click', '.changeserviceoption', function (e) {
306        e.preventDefault();
307        showLightbox($(this).attr('href'));
308    });
309
310    $('#Content_newcustomer, #Content_existingcustomer').on('change', function (e) {
311      
312        if (this.value == '1') {
313            $('#password_Show').removeClass('show');
314       
315        } else if (this.value == '2') {
316            $('#password_Show').addClass('show');
317        
318        }
319    });
320
321
322    $('.optionselector').each(function () {
323        var opt = $(this).find('input[type=radio]');
324        var input = $(this).find('.inlineblock input');
325        input.click(function () {
326            opt.prop('checked', true);
327        });
328        opt.change(function () {
329            input.focus();
330        });
331    });
332
333    $('.checkoutlogin').submit(function (e) {
334        if ($('#Content_newcustomer').is(':checked')) {
335            e.preventDefault(); $('.checkoutlogin').addClass('hidden');
336            $('.registerdetails').removeClass('hidden');
337            $('#Content_email').val($('#Content_emailLogon').val());
338        }
339    });
340
341    $('.checkoutshowlogin').click(function () {
342        $('.registerdetails').addClass('hidden');
343        var emailAddr = $('#Content_email').val();
344
345        if (emailAddr != null) {
346            $('#Content_emailLogon').val(emailAddr);
347        }
348
349        $('.registerdetails').addClass('hidden');
350        $('.checkoutlogin').removeClass('hidden');
351    });
352
353
354    $('.checkstock').each(function (x) {
355        var _t = $(this);
356
357        _t.find('a.checkstockbutton').click(function (e) {
358            e.preventDefault();
359            $('.stockcheckresults').addClass('hidden');
360            var action = $(this).attr('href');
361
362
363            $.postJSON({
364                url: action, success: function (r) {
365                
366                    if (r.Result) {
367                        var res = _t.find('.stockcheckresults');
368                        res.html(r.View);
369
370                       
371
372                        res.removeClass('hidden');
373                        res.css('left', 'auto');
374                        res.css('right', 'auto');
375                        var offset = res.width() + res.offset().left;
376
377
378                        if (offset > $(window).width()) {
379                            res.css('right', 0);
380                        }
381                        else {
382                            res.css('left', 0);
383                        }
384                        _t.parent().parent().removeClass('mobileavailability');
385
386                        if (res.offset().left < 0) {
387
388                            res.css('left', 0);
389
390                            _t.parent().parent().addClass('mobileavailability');
391
392                        }
393
394                    }
395                }
396            });
397        });
398    });
399
400
401
402    // book slot functionality
403    $(document).on('click', '.bookslot', function (e) {
404        e.preventDefault();
405        lastUrl = $(this).data('addurl');
406
407        showLightbox($(this).attr('href'));
408    });
409
410    var dateprompt = $('.dateselectionprompt');
411   
412    if (dateprompt.length > 0)
413    {
414        var item = $(dateprompt[0]);
415        lastUrl = item.data('addurl');
416
417        var url = item.data('bookurl');
418        showLightbox(url);
419    }
420
421    var wd = $('#wantdeliveredswitch');
422    var wdAction = wd.attr('data-action');
423
424
425
426
427    $(document).on('click', '#wantdeliveredswitch', function (e) {
428        e.preventDefault();
429        $.postJSON({
430            url: wdAction, success: function (r) {
431                if (r.Result) {
432                    $('.selectdelivery').html(r.View);
433                }
434            }
435        });
436        $('.selectdelivery').toggleClass('hidden');
437    });
438
439    $('.module-ajaxcontent').each(function (a) {
440
441        $(this).load($(this).attr('data-url'), function () {
442
443            postcodeChange();
444
445        });
446    });
447
448    var BREAKPOINT_1 = 705;
449    var s = $('.search #searchform').clone();
450    s.find('#search').attr('id', 'sidesearch');
451    s.appendTo($('#sidenav'));
452
453    var b = $('.nav-bar #book-slot').clone();
454    b.appendTo($('#sidenav'));
455
456    var primaryNav = $('nav.primary');
457
458    if (primaryNav.length > 0) {
459        var h = primaryNav.clone();
460        h.removeClass('primary');
461        h.appendTo($('#sidenav'));
462        var a = $('<li class="hidden" id="toggleMenu" ><a href="#"><span class="menu-word">MENU<span></a></li>');
463        a.insertBefore($('.secondarylinks ul li')[0]);
464    }
465
466    res = function () {
467      
468    };
469
470    $(window).resize(res);
471
472    imagesLoaded('body', function () { res(); });
473    if ($('.slideshow .slide').length >= 2) {
474        var setCurrentSlide = function (num) {
475            $('.slidenav a').removeClass('active');
476            $($('.slidenav a')[num]).addClass('active');
477        }
478
479
480        $('.slideshow').iosSlider({
481
482            desktopClickDrag: true,
483            autoSlide: true,
484            infiniteSlider: true,
485            snapToChildren: true,
486            responsiveSlideContainer: true,
487            responsiveSlides: true,
488            navSlideSelector: $('.slidenav a'),
489            onSlideChange: function (arg) {
490
491                setCurrentSlide(arg.currentSlideNumber - 1);
492
493            }
494        });
495        setCurrentSlide(0);
496    } else {
497        $('.slideshow').iosSlider('destroy');
498        $('.slidenav').addClass('hidden');
499    }
500
501    //var snapper = new Snap({
502    //    element: document.getElementById('content'),
503    //    disable: 'right'
504    //});
505
506
507
508    //$('#toggleMenu').click(function (a) {
509    //    a.preventDefault();
510    //    if (snapper.state().state == "closed") {
511    //        snapper.open('left');
512    //    }
513    //    else {
514    //        snapper.close();
515    //    }
516    //});
517
518    $('.cookieclose').click(function (e) {
519        e.preventDefault();
520        $('.cookiedetails').hide();
521    });
522
523    //$('.cookieaccept').click(function (e) {
524    //    e.preventDefault();
525    //    $('.cookiedetails').hide();
526    //});
527
528    $('#search').focus(function () { $('#searchresults').removeClass('hidden'); });
529    $('#search').blur(function () {
530        setTimeout(function () {
531            $('#searchresults').addClass('hidden');
532        }, 200)
533    });
534
535
536    $('#search2').focus(function () { $('#searchresults2').removeClass('hidden'); });
537    $('#search2').blur(function () {
538    });
539
540    $('.accordion_content').not('.open').hide();
541
542    if ($('.accordion_content.open').length == 0) {
543        var first = $($('.accordion_content')[0]);
544        if (!first.hasClass('nutritabs')) {
545            $($('.accordion_item h3')[0]).addClass('current');
546            first.addClass('open').show();
547        }
548    }
549
550    var customerReviews = $($('.accordion_content').last());
551    if (customerReviews.hasClass('trustpilot-review')) {
552        customerReviews.prev('h3').addClass('current'); 
553        customerReviews.addClass('open').show();
554    }
555
556
557    $('.accordion h3 a').click(function (e) {
558        if ($(this).parent().hasClass('current')) {
559            $(this).parent()
560                .removeClass('current')
561                .next('.accordion_content').slideUp();
562        } else {
563            $(document).find('.current')
564                 .removeClass('current')
565                 .next('.accordion_content').slideUp();
566            $(this).parent()
567                  .addClass('current')
568                  .next('.accordion_content').slideDown();
569        }
570        e.preventDefault();
571    });
572
573    if ($('.productadd').length > 0) {
574        var setHeight = function () {
575            var h = $('.productadd').height();
576            $('.productcontents').css('min-height', h);
577        }
578        $(window).resize(setHeight);
579        setHeight();
580    }
581
582    res();
583
584    /* Sticky Header */
585
586    var $body = $('html,body'),
587        //$content = $('#content'),
588        //$contentWrapper = $('#content-wrapper'),
589        $header = $('header'),
590        scrollTop = $('html,body').scrollTop(),
591        otop = 0,
592        headerHeight = $header.height(),
593        windowWidth = $(window).width(),
594        $bodyouter = $('.bodyouter'),
595        $miniBasket = $('#mini-basket')
596    $total = $('#basket_totalprice').text();
597
598
599    $(window).scroll(function () {
600        otop = $(document).scrollTop();
601
602        if (otop > 10) {
603            $header.addClass("scrolled");
604        } else {
605            $header.removeClass("scrolled");
606        }
607
608       
609    });
610
611    $(window).on('resize', function (e) {
612        windowWidth = $(window).width();
613    });
614
615    if ($total == "£0.00") {
616        $miniBasket.addClass("hidden");
617    } else {
618        $miniBasket.removeClass("hidden");
619    }
620    /* Tabs */
621    $('.tabs .tab-links a').on('click', function (e) {
622        var currentAttrValue = $(this).attr('rel');
623
624        // Show/Hide Tabs
625        $('.tab-content ' + currentAttrValue).show().siblings().hide();
626
627        // Change/remove current tab to active
628        $(this).parent('li').addClass('active').siblings().removeClass('active');
629
630        e.preventDefault();
631    });
632
633
634
635    if ($('.usepackery').length > 0) {
636        var doPackery = function () {
637
638            var packery = new Packery($('.usepackery')[0], { itemSelector: '.pagecell' });
639            packery.on('layoutComplete', function () { res(); });
640
641        };
642        doPackery();
643
644        imagesLoaded('body', function () { doPackery(); });
645    }
646});
647
648$('body').on('click', '#choose-another-shop', function (e) {
649    var $storeSearch = $('body #store-search');
650
651    $storeSearch.toggleClass('hidden');
652    e.preventDefault();
653});
654
655/* Accordion */
656
657(function ($) {
658    $(function () {
659        var $accordion = $('.tabs'),
660            $liLinks = $accordion.find('.tab-content > .accordion-heading');
661
662        $accordion.find('.tab-content > .accordion-heading').click(function (e) {
663
664            if ($(this).hasClass('active')) {
665                $(this).removeClass('active');
666            } else {
667                $liLinks.removeClass('active');
668                $(this).addClass('active');
669            }
670
671            var $contentPanels = $accordion.find($(".tab"));
672
673            //Expand or collapse this panel
674            $(this).next().slideToggle('fast');
675
676            //Hide the other panels
677            $(".tab").not($(this).next()).slideUp('fast');
678
679            e.preventDefault();
680
681        });
682
683    });
684})(jQuery);
685
686/* Desktop nav for touch devices */
687
688(function ($) {
689    $(function () {
690        
691        var $html = $('html'),
692            windowWidth = $(window).width(),
693            $topNavLinks = $('.primary > ul > li > a');
694
695        $(window).on("resize", function (event) {
696            windowWidth = $(window).width();
697        });
698
699        $topNavLinks.on('click', function (e) {
700
701            if(windowWidth < 1024 == true) {
702                return false;
703            } else {
704                if (($html.hasClass('touchevents') && windowWidth >= 1024 && windowWidth <= 1366) == true) {
705
706                    e.preventDefault();
707                    var subnav = $(this).next('div');
708
709                    if ($(this).hasClass('open') || subnav.length == 0) {
710                        window.location.href = $(this).attr("href");
711                    } else {
712                        e.preventDefault();
713                    }
714
715                } else {
716                    window.location.href = $(this).attr("href");
717                }
718
719                $(this).addClass('open');
720            }
721        });
722    });
723
724    var $checkboxWrapper = $(".checkbox-wrapper"),
725        $checkbox = $("#Content_emailsub");
726
727    /* Checkbox add class on change */
728    $checkboxWrapper.on("click", function () {
729        if ($checkbox.attr('checked')) {
730            $(".check-label").addClass("checked");
731        } else {
732            $(".check-label").removeClass("checked");
733        }
734    });
735
736})(jQuery);
737
738/* Browser detection for finding specific Safari version */
739
740(function ($) {
741    function get_browser() {
742        var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
743        if (/trident/i.test(M[1])) {
744            tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
745            return { name: 'IE', version: (tem[1] || '') };
746        }
747        if (M[1] === 'Chrome') {
748            tem = ua.match(/\bOPR|Edge\/(\d+)/)
749            if (tem != null) { return { name: 'Opera', version: tem[1] }; }
750        }
751        M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
752        if ((tem = ua.match(/version\/(\d+)/i)) != null) { M.splice(1, 1, tem[1]); }
753        return {
754            name: M[0],
755            version: M[1]
756        };
757    }
758
759    var browser = get_browser();
760
761    $('html').addClass(browser.name + "-" + browser.version);
762})(jQuery);
763
764
765
766var resetPageHeight = function () {
767    var $sidebar = $('.checkout-summary'),
768        sidebarHeight = $sidebar.height(),
769        $checkoutpage = $('.checkout #pagecontent'),
770        pageHeight = $checkoutpage.height();
771
772    if (pageHeight < sidebarHeight)
773        $checkoutpage.css({ "height": sidebarHeight + 50 });
774}
775
776
777var $preloadedImages = [];
778var $topNavImages;
779
780var loadTopNavImages = function (windowWidth) {
781    
782    if (windowWidth > 1023 && $topNavImages) {
783        for (var i = 0; i < $topNavImages.length; i++) {
784
785            if ($preloadedImages[i] !== null) {
786                var img = $($topNavImages[i]);
787                var url = img.data('src');
788                $preloadedImages[i] = new Image();
789                $preloadedImages[i] = url;
790                img.attr('src', url);
791            }
792        }
793
794    }
795};
796
797$(function () {
798    $topNavImages = $('nav.primary img');
799    loadTopNavImages($(window).width());
800});
801
802$(window).on('resize', function () {
803    var $sidebar = $('.checkout-summary'),
804        $window = $(window),
805        sidebarHeight = $sidebar.height(),
806        $checkoutpage = $('.checkout #pagecontent'),
807        pageHeight = $checkoutpage.height(),
808        windowWidth = $window.width();
809
810    loadTopNavImages(windowWidth);
811
812    if ($sidebar.length == 0)
813        return;
814
815    if (windowWidth <= 720)
816        $checkoutpage.css({ "height": "auto" });
817
818    resetPageHeight();
819
820    $sidebar.on('click', function () {
821        resetPageHeight();
822    });
823    
824});
825
826
827var slick6 = function () {
828    var $slick6 = $('.slick-6');
829
830    if ($slick6.length == 0) {
831        return;
832    }
833
834    $slick6.slick({
835        infinite: true,
836        slidesToShow: 6,
837        slidesToScroll: 6,
838        dots: false,
839        arrows: true,
840        centerPadding: '0',
841        centerMode: false,
842        responsive: [
843            {
844                breakpoint: 1024,
845                settings: {
846                    slidesToShow: 4,
847                    slidesToScroll: 4,
848                }
849            },
850            {
851                breakpoint: 480,
852                settings: {
853                    slidesToShow: 2,
854                    slidesToScroll: 2,
855                }
856            }
857        ]
858    });
859}
860
861slick6();
862
863var slick4 = function () {
864    var $slick4 = $('.slick-4');
865
866    if ($slick4.length == 0) {
867        return;
868    }
869
870    $slick4.slick({
871        infinite: true,
872        slidesToShow: 4,
873        slidesToScroll: 4,
874        dots: false,
875        arrows: true,
876        centerMode: false,
877        centerPadding: '0',
878        variableWidth: false,
879        responsive: [
880            {
881                breakpoint: 480,
882                settings: {
883                    slidesToShow: 2,
884                    slidesToScroll: 2,
885                }
886            }
887        ]
888    });
889}
890
891if ($('.olark-click-to-chat').length > 0) {
892    olark('api.chat.onOperatorsAvailable', function () {
893        $('.olark-click-to-chat').show();
894    });
895
896    olark('api.chat.onOperatorsAway', function () {
897        $('.olark-click-to-chat').hide();
898    });
899}
900
901var productSlick = function () {
902    var $prodImages = $('.productdetails .productimages');
903
904    if ($prodImages.length == 0) {
905        return;
906    }
907
908    $prodImages.slick({
909        slidesToShow: 1,
910        slidesToScroll: 1,
911        arrows: true,
912        fade: true,
913        //asNavFor: '.productdetails .thumbnails'
914    });
915
916    $('.productdetails .thumbnails img').on('click', function (e) {
917        e.preventDefault();
918        var slideIndex = $(this).data('index');
919        $prodImages.slick("slickGoTo", slideIndex);
920    });
921
922    
923};
924
925productSlick();
926
927//Product contents for meal box js
928//nav tabs for meal box servings
929let tabHeaders = document.querySelectorAll('.nav-tabs .tab-header > li')
930let tabContents = document.querySelectorAll('.nav-tabs .tab-body .tab-content')
931
932tabHeaders.forEach((tabHeader, index) => {
933    tabHeader.addEventListener('click', function () {
934        document
935            .querySelector('.nav-tabs .tab-header > .active')
936            .classList.remove('active')
937        tabHeader.classList.add('active')
938        document
939            .querySelector('.nav-tabs .tab-body > .active')
940            .classList.remove('active')
941        tabContents[index].classList.add('active')
942    })
943})
944
945//jQuery WOW Carousel for meal box
946$(document).ready(function () {
947    if ($('.owl-carousel').length > 0) {
948        $('.owl-carousel').owlCarousel({
949            loop: false,
950            margin: 10,
951            autoplay: false,
952            autoplayTimeout: 3000,
953            autoWidth: true,
954            nav: true,
955            navText: ["<span class='prev'></span>", "<span class='next'></span>"],
956            items: 1,
957            margin: 28,
958            dots: false,
959            responsive: {
960                0: {
961                    margin: 10,
962                },
963                600: {
964                    margin: 28,
965                },
966            },
967        })
968    }
969})
970
971//===============================
972
973var filters = function () {
974    var $filterButton = $('.dropdown-button'),
975        $dropdownList = $('.filter-dropdown'),
976        $mobileFilter = $('.mobile-filter'),
977        $window = $(window),
978        windowWidth = $window.width();
979
980    if ($filterButton.length === 0) {
981        return;
982    }
983
984    $($filterButton).on('click', function (e) {
985        e.preventDefault();
986
987        if ($(this).hasClass("active")) {
988            $filterButton.removeClass("active");
989            $dropdownList.removeClass("active");
990        } else {
991            $filterButton.removeClass("active");
992            $dropdownList.removeClass("active");
993
994            var $dropdown = $(this).next('.filter-dropdown');
995            $(this).toggleClass("active");
996            $dropdown.toggleClass("active");
997        }
998    });
999
1000    $($mobileFilter).on('click', function (e) {
1001        e.preventDefault();
1002        var $dropdown = $(this).next('.filter-inner');
1003        $(this).toggleClass("active");
1004        $dropdown.toggleClass("active");
1005    });
1006
1007    $(document).on("click", function (e) {
1008        if ($(e.target).is($filterButton) === false) {
1009            $filterButton.removeClass("active");
1010            $dropdownList.removeClass("active");
1011        }
1012    });
1013
1014    if (windowWidth > 800) {
1015        $(window).scroll(function () {
1016            $filterButtonActive = $('.filter-button.active')
1017            $dropdownListActive = $('.filter-dropdown.active');
1018
1019            if ($dropdownListActive.length > 0) {
1020                var height = $dropdownListActive.offset().top + $dropdownListActive.outerHeight();
1021
1022                if ($(window).scrollTop() > height) {
1023                    $filterButtonActive.removeClass("active");
1024                    $dropdownListActive.removeClass("active");
1025                }
1026            }
1027        });
1028    }
1029};
1030
1031filters();
1032$(function () {
1033    //Read more / read less for category pages
1034    var toggles = document.querySelectorAll('.productintro-readmore .rm-toggle');
1035    if (!toggles.length) return;
1036
1037    // The toggle that was clicked gets hidden by its own action, so keyboard users are handed
1038    // focus on the opposite toggle that has just taken its place.
1039    function toggleCopy(toggle, moveFocus) {
1040        var readmore = toggle.closest('.productintro-readmore');
1041        if (!readmore) return;
1042        var target = toggle.getAttribute('data-rm-target');
1043        var expand = toggle.getAttribute('data-rm-action') !== 'less';
1044        var collapsed = readmore.querySelector('.rm-collapsed[data-rm-target="' + target + '"]');
1045        var full = readmore.querySelector('.rm-full[data-rm-id="' + target + '"]');
1046        if (collapsed) {
1047            if (expand) { collapsed.classList.add('hidden'); } else { collapsed.classList.remove('hidden'); }
1048        }
1049        if (full) {
1050            if (expand) { full.classList.remove('hidden'); } else { full.classList.add('hidden'); }
1051        }
1052        if (moveFocus) {
1053            var shown = expand ? full : collapsed;
1054            var next = shown ? shown.querySelector('.rm-toggle') : null;
1055            if (next) next.focus();
1056        }
1057    }
1058
1059    Array.prototype.forEach.call(toggles, function (toggle) {
1060        toggle.addEventListener('click', function () {
1061            toggleCopy(toggle, false);
1062        });
1063        // These are href-less anchors, so the browser gives them no native keyboard activation.
1064        toggle.addEventListener('keydown', function (e) {
1065            var key = e.key || e.keyCode;
1066            if (key === 'Enter' || key === ' ' || key === 'Spacebar' || key === 13 || key === 32) {
1067                e.preventDefault();
1068                toggleCopy(toggle, true);
1069            }
1070        });
1071    });
1072});
1073

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.