PageSourceSearch

https://rivercottage.net/wp-content/themes/understrap-child-main/js/custom.js?ver=1.63

js rivercottage.net collected 2026-09-24 18:03:50 UTC 23,206 bytes, 582 lines download raw bytes

1var getUrlParameter = function getUrlParameter(sParam) {
2    var sPageURL = window.location.search.substring(1),
3        sURLVariables = sPageURL.split('&'),
4        sParameterName,
5        i;
6
7    for (i = 0; i < sURLVariables.length; i++) {
8        sParameterName = sURLVariables[i].split('=');
9
10        if (sParameterName[0] === sParam) {
11            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
12        }
13    }
14    return false;
15};
16jQuery(document).ready(function ($) {
17    var get = getUrlParameter('subject');
18    $("#events_form_subject option[value='" + get + "']").attr('selected', 'selected');
19    var getDate = getUrlParameter('date');
20    if (getDate) {
21        $(".booking_date_radio[value='" + getDate + "']").attr('checked', 'checked');
22    } else {
23        $(".booking_date_radio:first").attr('checked', true);
24    }
25});
26
27jQuery(document).ready(function ($) {
28    var date_radio = $('.booking_date_radio');
29    var date_soon = $('.booking_date_soon');
30    if (date_radio.length > 0) {
31        $('.yith-wcbk-form-section-dates-wrapper').addClass("d-none");
32    }
33    if (date_soon.length > 0) {
34        $('.yith-wcbk-form-section-dates-wrapper').addClass("d-none");
35        $('.yith-wcbk-form-section-persons-wrapper').addClass("d-none");
36    }
37    $(document).ajaxComplete(function () {
38        var text = $('form.cart').find('input[name="start-date"]').val();
39        var date_radio = $('.booking_date_radio');
40        if (date_radio) {
41            $('.booking_date_radio').change(function () {
42                var date = $(this).val();
43                var id = $('body').find('.product').attr('id');
44                var ids = id.match(/\d+/);
45                $('form.cart').find('input[name="start-date"]').val(date);
46            })
47        }
48    });
49    $('.booking_date_radio').change(function () {
50        var date = $(this).val();
51        var id = $('body').find('.product').attr('id');
52        var ids = id.match(/\d+/);
53
54        $('#yith-wcbk-booking-hidden-from' + ids).val(date);
55    })
56
57    $(".gallery_image").click(function () {
58        $(".gallery_popup").addClass('d-flex');
59    });
60
61    $(".gallery_popup").click(function () {
62        $(".gallery_popup").removeClass('d-flex');
63    });
64
65    $(".gallery_popup_body").click(function (event) {
66        event.stopPropagation();
67    });
68
69    $('.wpcf7 select').select2({
70        minimumResultsForSearch: Infinity,
71        dropdownParent: $('.form-row.select.position-relative')
72    });
73    $('.wpcf7 .form-feedback select').select2({
74        minimumResultsForSearch: Infinity,
75        dropdownParent: $('.select-parent')
76    });
77    $('#single_term').select2({
78        minimumResultsForSearch: Infinity,
79        dropdownParent: $('.single_term_parent')
80    });
81    $('#billing_country').select2({
82        minimumResultsForSearch: Infinity,
83        dropdownParent: $('.single-country')
84    });
85
86    $(window).on("orientationchange", function (event) {
87        $('.wpcf7 select').select2({
88            minimumResultsForSearch: Infinity
89        });
90    });
91    $('.wpcf7-form').submit(function (event) {
92        let valid = true;
93        $('[aria-required]').each(function (i, ele) {
94            if (ele.value == '') {
95                $(this).parent().parent().find('label').addClass('invalid-label');
96                valid = false;
97            }
98        });
99        if (!valid) {
100            event.preventDefault();
101            return false;
102        }
103        return true;
104    });
105    $('.flex-control-nav').addClass('opacity-0');
106    $(window).on('load', function () {
107        let gallery_height = $('.woocommerce-product-gallery').outerHeight();
108        let flex_control_nav = $('.flex-control-nav').outerHeight();
109        if (flex_control_nav > gallery_height) {
110            $('.flex-control-nav').addClass('overflow-auto mh-100');
111        }
112        $('.flex-control-nav').removeClass('opacity-0');
113    })
114
115    $('.wpcf7-form-control-wrap').each(function () {
116        $(this).find('.wpcf7-list-item').on('click', function () {
117            $(this).parent().find('.wpcf7-list-item').removeClass('active');
118            $(this).addClass('active');
119        })
120    });
121
122    document.addEventListener('wpcf7mailsent', function (event) {
123        if ('9006' == event.detail.contactFormId) {
124            document.getElementById('wpcf7-f9006-o1').style.display = 'none';
125            document.getElementById('thanks-feedback').classList.remove('d-none');
126        }
127    }, false);
128
129    // let link_price = getUrlParameter('price');
130    // let admin_fee = getUrlParameter('admin_fee');
131    // if (link_price && !admin_fee) {
132    //     $('.shop_single_product .woocommerce-Price-amount.amount bdi').html('<span class="woocommerce-Price-currencySymbol">£</span>' + link_price + '')
133    // }
134    // if (link_price && admin_fee) {
135    //     let additional_price = Number(link_price) + Number(admin_fee);
136    //     $('.shop_single_product .woocommerce-Price-amount.amount bdi').html('<span class="woocommerce-Price-currencySymbol">£</span>' + additional_price + '')
137    // }
138    $(".woocommerce-order h2:contains('Related Bookings')").hide();
139
140    const numberInput = $('.yith-wcbk-booking-service-quantity');
141
142    // Add an event handler for the input event (when the value changes)
143    numberInput.on('input', function () {
144        validateInput(this);
145    });
146
147    // Add an event handler for the click event (when the input is clicked)
148    numberInput.on('click', function () {
149        validateInput(this);
150    });
151
152    function validateInput(input) {
153        if (input.value <= 0) {
154            input.value = '1';
155        }
156    }
157
158    $('body').on('click', '.add_to_cart_button_ajax', function (e) {
159        e.preventDefault();
160        let product_id = $(this).data('id');
161        if (!product_id) {
162            product_id = $('input[name=variation_id]').val();
163        }
164        console.log(product_id);
165        $.ajax({
166            type: 'POST',
167            url: custom_object.ajaxurl,
168            data: {
169                'action': 'custom_add_to_cart',
170                'product_id': product_id,
171            },
172            success: function (response) {
173                $(document.body).trigger('added_to_cart');
174
175                // Update the cart content
176                if (response.fragments && response.fragments['div.widget_shopping_cart_content']) {
177                    $('#popupCart .modal-body').html(response.fragments['div.widget_shopping_cart_content']);
178                }
179
180                // Update cart count
181                if (response.fragments && response.fragments['span.cart-contents-count']) {
182                    $('.cart-contents-count').replaceWith(response.fragments['span.cart-contents-count']);
183                }
184
185                // Show the updated cart in the popup modal
186                let tempElement = document.createElement('div');
187                // tempElement.innerHTML = response.fragments.notices_html;
188                let errorElements = tempElement.querySelectorAll('.woocommerce-error');
189
190                if (errorElements.length > 0) {
191                    console.log('Error found:', errorElements);
192                } else {
193                    $('#popupCart').modal('show');
194                    let myModalEl = document.getElementById('popupCart')
195                    myModalEl.addEventListener('shown.bs.modal', function (event) {
196                        jQuery('.popupCart .cart_list').animate({
197                            scrollTop: -jQuery('.popupCart .cart_list')[0].scrollHeight
198                        }, 1000);
199                    })
200                }
201                // Replace "ITEM" with the product name
202                // var productName = response.product_name;
203                // $('.item_added').text(productName + ' ADDED TO bag');
204            },
205            error: function (error) {
206                console.log(error);
207            }
208        });
209    });
210
211    $('body').on('click', '.product-type-pw-gift-card .single_add_to_cart_button', function (e) {
212        e.preventDefault();
213
214        var $thisbutton = $(this),
215            $form = $thisbutton.closest('form.cart'),
216            id = $thisbutton.val(),
217            product_qty = $form.find('input[name=quantity]').val() || 1,
218            product_id = $form.find('input[name=product_id]').val() || id,
219            pw_gift_card_to = $form.find('input[name=pw_gift_card_to]').val() || 0,
220            pw_gift_card_message = $form.find('textarea[name=pw_gift_card_message]').val() || '',
221            pw_gift_card_from = $form.find('input[name=pw_gift_card_from]').val() || '',
222            variation_id = $form.find('input[name=variation_id]').val() || 0,
223            custom_amount = $form.find('input[name="pw_gift_cards_custom_amount"]').val() || 0;
224
225        var data = {
226            action: 'woocommerce_ajax_add_to_cart_voucher',
227            product_id: product_id,
228            product_sku: '',
229            quantity: product_qty,
230            variation_id: variation_id,
231            pw_gift_card_to: pw_gift_card_to,
232            pw_gift_card_message: pw_gift_card_message,
233            pw_gift_card_from: pw_gift_card_from,
234            pw_gift_cards_custom_amount: custom_amount,
235        };
236
237        $(document.body).trigger('adding_to_cart', [$thisbutton, data]);
238
239        $.ajax({
240            type: 'post',
241            url: wc_add_to_cart_params.ajax_url,
242            data: data,
243            beforeSend: function (response) {
244                $thisbutton.removeClass('added').addClass('loading');
245            },
246            success: function (response) {
247                $(document.body).trigger('added_to_cart');
248                $thisbutton.addClass('added').removeClass('loading');
249
250                if (response.fragments && response.fragments.notices_html) {
251                    $('.woocommerce-notices-wrapper').remove();
252                    $('.woocommerce-error').remove();
253                    $('form.cart').before(response.fragments.notices_html);
254                    $thisbutton.removeClass('added').removeClass('loading');
255                    // Scroll to the notices
256                    $('html, body').animate({
257                        scrollTop: $('.shop_single_product').offset().top - 20 // Adjust for spacing
258                    }, 500);
259                }
260                // Update the cart content
261                if (response.fragments && response.fragments['div.widget_shopping_cart_content']) {
262                    $('#popupCart .modal-body').html(response.fragments['div.widget_shopping_cart_content']);
263                }
264
265                // Update cart count
266                if (response.fragments && response.fragments['span.cart-contents-count']) {
267                    $('.cart-contents-count').replaceWith(response.fragments['span.cart-contents-count']);
268                }
269
270                // Show the updated cart in the popup modal
271                let tempElement = document.createElement('div');
272                tempElement.innerHTML = response.fragments.notices_html;
273                let errorElements = tempElement.querySelectorAll('.woocommerce-error');
274
275                if (errorElements.length > 0) {
276                    console.log('Error found:', errorElements);
277                } else {
278                    $('#popupCart').modal('show');
279                }
280            },
281        });
282
283        return false;
284    });
285
286    $('body').on('click', '#vouchers_add_to_cart', function (e) {
287        e.preventDefault();
288        let product_id = $(this).data('id');
289        let custom_quantity = $('#custom_quantity').val();
290        let custom_price = $('#custom_price').val();
291        let gift_personal_message = $('#gift_personal_message').val();
292        // console.log(product_id)
293        $.ajax({
294            type: 'POST',
295            url: custom_object.ajaxurl,
296            data: {
297                'action': 'custom_add_to_cart_voucher',
298                'product_id': product_id,
299                'quantity': custom_quantity,
300                'price': custom_price,
301                'gift_personal_message': gift_personal_message,
302            },
303            success: function (response) {
304                $(document.body).trigger('added_to_cart');
305
306                // Update the cart content
307                if (response.fragments && response.fragments['div.widget_shopping_cart_content']) {
308                    $('#popupCart .modal-body').html(response.fragments['div.widget_shopping_cart_content']);
309                }
310
311                // Update cart count
312                if (response.fragments && response.fragments['span.cart-contents-count']) {
313                    $('.cart-contents-count').replaceWith(response.fragments['span.cart-contents-count']);
314                }
315
316                // Show the updated cart in the popup modal
317                let tempElement = document.createElement('div');
318                tempElement.innerHTML = response.fragments.notices_html;
319                let errorElements = tempElement.querySelectorAll('.woocommerce-error');
320
321                if (errorElements.length > 0) {
322                    console.log('Error found:', errorElements);
323                } else {
324                    $('#popupCart').modal('show');
325                }
326                // Replace "ITEM" with the product name
327                // var productName = response.product_name;
328                // $('.item_added').text(productName + ' ADDED TO bag');
329            },
330            error: function (error) {
331                console.log(error);
332            }
333        });
334    });
335
336    $('body').on('click', '.product-type-variable .single_add_to_cart_button, .woocommerce-shop .single_add_to_cart_button', function (e) {
337        e.preventDefault();
338
339        var $thisbutton = $(this),
340            $form = $thisbutton.closest('form.cart'),
341            id = $thisbutton.val(),
342            product_qty = $form.find('input[name=quantity]').val() || 1,
343            product_id = $form.find('input[name=product_id]').val() || id,
344            variation_id = $form.find('input[name=variation_id]').val() || 0;
345
346        var data = {
347            action: 'woocommerce_ajax_add_to_cart',
348            product_id: product_id,
349            product_sku: '',
350            quantity: product_qty,
351            variation_id: variation_id,
352        };
353
354        $(document.body).trigger('adding_to_cart', [$thisbutton, data]);
355
356        $.ajax({
357            type: 'post',
358            url: wc_add_to_cart_params.ajax_url,
359            data: data,
360            beforeSend: function (response) {
361                $thisbutton.removeClass('added').addClass('loading');
362            },
363            complete: function (response) {
364                $thisbutton.addClass('added').removeClass('loading');
365            },
366            success: function (response) {
367                $(document.body).trigger('added_to_cart');
368
369                // Update the cart content
370                if (response.fragments && response.fragments['div.widget_shopping_cart_content']) {
371                    $('#popupCart .modal-body').html(response.fragments['div.widget_shopping_cart_content']);
372                }
373
374                // Update cart count
375                if (response.fragments && response.fragments['span.cart-contents-count']) {
376                    $('.cart-contents-count').replaceWith(response.fragments['span.cart-contents-count']);
377                }
378
379                // Show the updated cart in the popup modal
380                let tempElement = document.createElement('div');
381                tempElement.innerHTML = response.fragments.notices_html;
382                let errorElements = tempElement.querySelectorAll('.woocommerce-error');
383
384                if (errorElements.length > 0) {
385                    console.log('Error found:', errorElements);
386                } else {
387                    $('#popupCart').modal('show');
388                }
389            },
390        });
391
392        return false;
393    });
394});
395
396window.addEventListener('DOMContentLoaded', (event) => {
397    // Get all h3 elements with the class "info"
398    const infoHeadings = document.querySelectorAll('h3.info');
399
400    // Loop through each h3 element and add numbers
401    infoHeadings.forEach((heading, index) => {
402        // Add 1 to index because index is zero-based
403        const number = index + 1;
404        // Update the text of the h3 element
405        heading.textContent = number + '. ' + heading.textContent;
406    });
407});
408
409function validateMinValue() {
410    const input = document.getElementById('custom_price');
411    if (input.value < 50) {
412        input.value = 50;
413    }
414}
415
416jQuery(document).ready(function ($) {
417    $('form.checkout_coupon').on('submit', function (event) {
418        jQuery(document.body).on('applied_coupon_in_checkout removed_coupon_in_checkout', function () {
419            location.reload();
420        });
421    });
422    $('.order-total-info .woocommerce-remove-coupon').on('click', function () {
423        jQuery(document.body).on('applied_coupon_in_checkout removed_coupon_in_checkout', function () {
424            location.reload();
425        });
426    });
427    // Get the current price
428    let priceText = $('.price .woocommerce-Price-amount bdi').text();
429
430    // Extract the numeric value from the price
431    let currentPrice = parseFloat(priceText.replace('£', ''));
432
433    // Get the discount value
434    let discountVal = parseFloat($('.voucher_balance').val());
435
436    // Check if discountVal exists and is a valid number
437    if (!isNaN(discountVal) && discountVal > 0) {
438        // Calculate the new price
439        let newPrice = currentPrice - discountVal;
440
441        // Update the price element with the new price
442        $('.price .woocommerce-Price-amount bdi').text('£' + newPrice.toFixed(2));
443    }
444});
445
446jQuery(window).on('load', function () {
447    jQuery('.pum').on('click mouseover touchstart touchend', function (event) {
448        jQuery('iframe.video').each(function () {
449            let iframe_src = jQuery(this).attr('data-src');
450            jQuery(this).attr('src', iframe_src).removeClass('d-none');
451        });
452        jQuery(this).unbind('click mouseover touchstart touchend');
453    });
454    jQuery(document).ready(function ($) {
455        var $eventItems = $('.mobile-events .sorting-row').sort(function (a, b) {
456            var dateA = new Date($(a).data('from-date'));
457            var dateB = new Date($(b).data('from-date'));
458            return dateA - dateB;
459        });
460
461        // Append the sorted items back to the container
462        $('.mobile-events').html($eventItems);
463
464        // Hide duplicate .from-date elements
465        var seenDates = {};
466        $('.mobile-events .from-date').each(function () {
467            var fromDate = $(this).data('from-date');
468            if (seenDates[fromDate]) {
469                $(this).hide(); // Hide duplicate
470            } else {
471                seenDates[fromDate] = true; // Mark as seen
472            }
473        });
474
475        $('.calendar-container .preloader').hide();
476    });
477})
478jQuery(window).on('load', function () {
479
480    jQuery(document).ready(function ($) {
481        const $dateInput = $(".custom_labels_fields input[type='date']");
482
483        // Function to format today's date as YYYY-MM-DD
484        function getTodayDate() {
485            const today = new Date();
486            const year = today.getFullYear();
487            const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are zero-based
488            const day = String(today.getDate()).padStart(2, '0');
489            return `${year}-${month}-${day}`;
490        }
491
492        // Set the current date as default if the input is empty
493        if (!$dateInput.val()) {
494            // console.log('no val');
495            // $dateInput.val(getTodayDate());
496            $dateInput.closest(".form-row").addClass("active-label")
497        }
498
499        // Function to check if the field has a value
500        function checkDateValue() {
501            if ($dateInput.val() === "") {
502                $dateInput.addClass("default-value");
503            } else {
504                $dateInput.removeClass("default-value");
505            }
506        }
507
508        // Initial check on page load
509        checkDateValue();
510
511        // Check on input change
512        $dateInput.on("input", function () {
513            checkDateValue();
514        });
515    });
516});
517jQuery(document).ready(function ($) {
518    $('.dropdown-toggle').on('click', function (e) {
519        e.preventDefault();
520        $(this).parent().find('.dropdown-menu').toggleClass('active');
521    });
522});
523jQuery(document).ready(function ($) {
524    const $enquiryType = $('.enquiry-type');
525    const $privateEventFields = $('.private-event-occasion');
526    const $corporateFields = $('.corporate-company-name');
527
528    const toggleFields = function () {
529        const selectedValue = $enquiryType.val();
530
531        if (selectedValue === 'Private Event') {
532            $privateEventFields.removeClass('d-none');
533            $corporateFields.addClass('d-none');
534        } else if (selectedValue === 'Corporate') {
535            $corporateFields.removeClass('d-none');
536            $privateEventFields.addClass('d-none');
537        } else {
538            $privateEventFields.addClass('d-none');
539            $corporateFields.addClass('d-none');
540        }
541    };
542
543    // Initialize field visibility on page load
544    toggleFields();
545
546    // Update field visibility on change
547    $enquiryType.on('change', toggleFields);
548});
549
550
551jQuery(document).on('ajaxComplete', function (event, xhr, settings) {
552    if (settings.data && settings.data.includes('action=yith_wcbk_frontend_ajax_action')) {
553        let allZero = jQuery('.yith-wcbk-people-selector__field__total').toArray().every(el => jQuery(el).text().trim() === '0');
554        let addToCartButton = jQuery('.yith-wcbk-add-to-cart-button');
555        if (allZero) {
556            addToCartButton.addClass('yith-wcbk-not-allowed').attr('disabled', true);
557        }
558    }
559});
560jQuery(document).ready(function ($) {
561    $(".show_more").click(function (e) {
562        e.preventDefault();
563
564        let svg = $(this).find("svg");
565        let text = $(this).contents().filter(function () {
566            return this.nodeType === 3;
567        });
568
569        if (svg.hasClass("rotated")) {
570            // $(".not_current").css("display", "none");
571            $(".not_current").addClass('hidden');
572            svg.removeClass("rotated").css("transform", "rotate(0deg)");
573            text[0].nodeValue = " Other Room Options";
574        } else {
575            // $(".not_current").css("display", "flex");
576            $(".not_current").removeClass('hidden');
577            svg.addClass("rotated").css("transform", "rotate(180deg)");
578            text[0].nodeValue = " Less options ";
579        }
580    });
581});
582

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.