templates/front/includes/scripts.twig line 1

Open in your IDE?
  1. {% set blogUrl = get_blog_url(app.request.locale|default('pl')) %}
  2. <!-- jquery.min.js -->
  3. <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
  4. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
  5. <!-- script.js -->
  6. <script src="{{ asset('/assets/js/jquery.nicescroll.min.js') }}"></script>
  7. <script src="{{ asset('assets/js/parallax.min.js') }}"></script>
  8. <script src="{{ asset('/assets/js/slick.min.js') }}"></script>
  9. <script src="{{ asset('assets/js/wow.min.js') }}"></script>
  10. <script src="{{ asset('assets/js/jquery.paroller.js') }}"></script>
  11. <script src="{{ asset('/assets/js/flexslider/jquery.flexslider-min.js') }}"></script>
  12. <script src="{{ asset('/assets/js/script.min.js') }}"></script>
  13. <script>
  14.     const searchDeliveryCityInfo = '{{ path('search-delivery-city-info') }}';
  15.     const kcalCalc = '{{ path('kcal-calc') }}';
  16.     $(document).on('click', '.searchCityBtn', function(e) {
  17.         let cityName = $("#searchCity").val();
  18.         let postCode = $("#searchPostCode").val();
  19.         let type = $("#type").val();
  20.         searchCityDelivery(cityName, postCode, type);
  21.     });
  22.     $(document).on('click', '.searchCityBtnSecond', function(e) {
  23.         let cityName = $("#searchCitySecond").val();
  24.         let type = $("#typeSecond").val();
  25.         clearSection();
  26.         searchCityDelivery(cityName, '', type);
  27.     });
  28.     function searchCityDelivery(cityName, postCode, type) {
  29.         let formData = new FormData();
  30.         formData.append('cityName', cityName);
  31.         formData.append('postCode', postCode);
  32.         formData.append('type', type);
  33.         clearMess();
  34.         $.ajax({
  35.             type: "POST",
  36.             url: searchDeliveryCityInfo,
  37.             processData: false,
  38.             contentType: false,
  39.             async: true,
  40.             data: formData,
  41.             beforeSend: function () {},
  42.             complete: function (response) {
  43.                if(type === 'first') {
  44.                    if(response.responseJSON.statement) {
  45.                        $('.mess-success').show();
  46.                    } else {
  47.                        $('.mess-danger').show();
  48.                    }
  49.                }
  50.                if(type === 'second') {
  51.                    let searchCitySection = $('#search-city-section');
  52.                    searchCitySection.html(response.responseJSON.content);
  53.                }
  54.             }
  55.         });
  56.     }
  57.     function clearMess() {
  58.         $('.mess-success').hide();
  59.         $('.mess-danger').hide();
  60.     }
  61.     function clearSection() {
  62.         $('#search-city-section').html('');
  63.     }
  64.     function validateForm() {
  65.         let age = $("#age").val();
  66.         let height = $("#height").val();
  67.         let weight = $("#weight").val();
  68.         if (age < 1 || age > 150 || isNaN(age) || age == "") {
  69.             $("#age").addClass("wrong-value");
  70.             $("#age-wrong").html("wprowadź poprawny wiek");
  71.             var agePoint = 0
  72.         } else {
  73.             $(".wrong-value").removeClass("wrong-value");
  74.             $("#age-wrong").html("");
  75.             var agePoint = 1
  76.         }
  77.         if (height < 1 || height > 300 || isNaN(height) || height == "") {
  78.             $("#height").addClass("wrong-value");
  79.             $("#height-wrong").html("wprowadź poprawny wzrost");
  80.             var heightPoint = 0
  81.         } else {
  82.             $(".wrong-value").removeClass("wrong-value");
  83.             $("#height-wrong").html("");
  84.             var heightPoint = 1
  85.         }
  86.         if (weight < 1 || weight > 300 || isNaN(weight) || weight == "") {
  87.             $("#weight").addClass("wrong-value");
  88.             $("#weight-wrong").html("wprowadź poprawną wagę");
  89.             var weightPoint = 0
  90.         } else {
  91.             $(".weight").removeClass("wrong-value");
  92.             $("#weight-wrong").html("");
  93.             var weightPoint = 1
  94.         }
  95.         if (agePoint + heightPoint + weightPoint >= 3) {
  96.             calc();
  97.             document.querySelector('#activity-level').scrollIntoView({
  98.                 behavior: 'smooth'
  99.             });
  100.         }
  101.     }
  102.     function calc() {
  103.         let gender = $('#gender').val();
  104.         let age = $('#age').val();
  105.         let height = $('#height').val();
  106.         let weight = $('#weight').val();
  107.         let activity = $('.activity:checked').val();
  108.         let destination = $('#destination').val();
  109.         let formData = new FormData();
  110.         formData.append('gender', gender);
  111.         formData.append('age', age);
  112.         formData.append('height', height);
  113.         formData.append('weight', weight);
  114.         formData.append('activity', activity);
  115.         formData.append('destination', destination);
  116.         $.ajax({
  117.             type: "POST",
  118.             url: kcalCalc,
  119.             processData: false,
  120.             contentType: false,
  121.             async: true,
  122.             data: formData,
  123.             beforeSend: function () {},
  124.             complete: function (response) { $('#kcal_result').text(response.responseJSON.kcal);}
  125.         });
  126.     }
  127.     $(document).on('change', '#categoryChoose', function(e) {
  128.         let category = $(this).val();
  129.         let searchPhrase = $('#searchPhrase').val();
  130.         changeLocation(category, searchPhrase);
  131.     });
  132.     $(document).on('click', '#searchBtn', function (){
  133.         let category = $('#categoryChoose').val();
  134.         let searchPhrase = $('#searchPhrase').val();
  135.         changeLocation(category, searchPhrase);
  136.     });
  137.     function changeLocation(category, searchPhrase) {
  138.         let link = '{{ blogUrl|default('') }}?page=1';
  139.         if(category !== '' && (typeof category !== 'undefined')) {
  140.             link = link + '&category=' + category;
  141.         }
  142.         if(searchPhrase !== '') {
  143.             link = link + '&searchPhrase=' + searchPhrase;
  144.         }
  145.         location.replace(link);
  146.     }
  147.     const setCookie = (cname, cvalue, exdays) => {
  148.         const d = new Date();
  149.         d.setTime(d.getTime() + (exdays*24*60*60*1000));
  150.         let expires = "expires="+ d.toUTCString();
  151.         document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  152.     }
  153.     const getCookie = (cname) => {
  154.         let name = cname + "=";
  155.         let decodedCookie = decodeURIComponent(document.cookie);
  156.         let ca = decodedCookie.split(';');
  157.         for(let i = 0; i <ca.length; i++) {
  158.             let c = ca[i];
  159.             while (c.charAt(0) == ' ') {
  160.                 c = c.substring(1);
  161.             }
  162.             if (c.indexOf(name) == 0) {
  163.                 return c.substring(name.length, c.length);
  164.             }
  165.         }
  166.         return "";
  167.     }
  168.     const deleteCookie = (cname) => {
  169.         const d = new Date();
  170.         d.setTime(d.getTime() + (24*60*60*1000));
  171.         let expires = "expires="+ d.toUTCString();
  172.         document.cookie = cname + "=;" + expires + ";path=/";
  173.     }
  174.     const thankYou = (from) => {
  175.         deleteCookie('user_cookie_consent');
  176.         setCookie('user_cookie_consent', 1, 365);
  177.         let email;
  178.         if(from === 'modal') {
  179.             email = $('#newsletter-email-modal').val();
  180.         } else {
  181.             email = $('#newsletter-email-section').val();
  182.         }
  183.         $.ajax({
  184.             url: '/join/newsletter',
  185.             dataType: 'json',
  186.             type: 'POST',
  187.             data: {
  188.                 email,
  189.             },
  190.             success: (documentData) => {
  191.                 $("#modal-thanks-form-open").click();
  192.                 setTimeout(function() {
  193.                     $("#close-thanks-modal").click();
  194.                 },3000);
  195.             },
  196.             error: (documentData) => {
  197.                 $("#modal-error-form-open").click();
  198.                 setTimeout(function() {
  199.                     $("#close-error-modal").click();
  200.                 },3000);
  201.             }
  202.         })
  203.         // .done(function (data) {
  204.         //     console.log(data.status);
  205.         //
  206.         //     if(data.status === 'success') {
  207.         //         setTimeout(function() {
  208.         //             $("#close-thanks-modal").click();
  209.         //         },3000);
  210.         //     } else {
  211.         //         setTimeout(function() {
  212.         //             $("#close-error-modal").click();
  213.         //         },3000);
  214.         //     }
  215.         //
  216.         //     // let response = $.parseJSON(data);
  217.         //     // console.log(response.statusCode);
  218.         // });
  219.     }
  220.     const newsletterCookie = getCookie('user_cookie_consent');
  221.     const policyCookie = getCookie('policy_cookie');
  222.     const policy = $("#policy-accept")
  223.     $(window).on('load', function() {
  224.         if(!newsletterCookie) {
  225.             $("#newsletter-open").click();
  226.         }
  227.         if(!policyCookie) {
  228.             policy.addClass('show');
  229.         } else {
  230.             policy.addClass('d-none');
  231.         }
  232.     })
  233.     $("#close-newsletter").on('click', () => {
  234.         deleteCookie('user_cookie_consent');
  235.         setCookie('user_cookie_consent', 1, 1);
  236.     })
  237.     $("#modal-newsletter").submit(function(event) {
  238.         $("#close-newsletter").click();
  239.         event.preventDefault();
  240.         thankYou('modal');
  241.     });
  242.     $("#newsletter-section").submit(function(event) {
  243.         event.preventDefault();
  244.         thankYou('section');
  245.     })
  246.     $("#accept-policy").on('click', () => {
  247.         setCookie('policy_cookie', 1, 365);
  248.         policy.removeClass('show');
  249.         setTimeout(function() {
  250.             policy.addClass('d-none');
  251.         },2000);
  252.     })
  253. </script>
  254.