PageSourceSearch

https://ambapizza.ru/wp-content/themes/pizza/js/script.js?v=amba-1790256740

js ambapizza.ru collected 2026-09-24 13:32:42 UTC 17,027 bytes, 538 lines download raw bytes

1const swiperStocks = new Swiper('.swiper-stocks', {
2    loop: true,
3    slidesPerView: 3,
4    navigation: {
5        nextEl: '.swiper-next1',
6        prevEl: '.swiper-prev1',
7    },
8    autoplay: {
9        delay: 2500,
10        disableOnInteraction: false,
11    },
12    speed: 3000,
13
14    breakpoints: {
15        320: {
16            slidesPerView: 1,
17        },
18        1000: {
19            slidesPerView: 2,
20        },
21        1200: {
22            slidesPerView: 3,
23        },
24
25
26    }
27});
28
29const mainSwiper = new Swiper(".mainSwiper", {
30    loop: true,
31    navigation: {
32        nextEl: '.swiper-button-next',
33        prevEl: '.swiper-button-prev',
34    },
35    autoplay: {
36        delay: 2500,
37        disableOnInteraction: false,
38    },
39});
40
41window.addEventListener("load", function (event) {
42    preloader();
43    new WOW().init();
44    menubutton();
45    //     menuscroll();
46    menumobscroll();
47    clickmenu();
48    hidemenu();
49    resizepage();
50    clicktocart();
51    cityButton();
52    setCart();
53    setCity();
54});
55
56function _scrollTo(selector, yOffset = 0) {
57    const el = document.querySelector(selector);
58    const y = el.getBoundingClientRect().top + window.pageYOffset + yOffset;
59
60    window.scrollTo({ top: y, behavior: 'smooth' });
61}
62
63function preloader() {
64    setTimeout(() => {
65        $('.container_body').css({ 'display': 'flex' });
66        $('.preloader').addClass('out');
67
68        setTimeout(() => {
69            $('.preloader').remove();
70
71            var hash = window.location.hash;
72
73            if (hash) {
74                switch (hash) {
75                    case '#benefits': hash = '#benefits_block'; break;
76                    case '#stocks': hash = '#stocks_block'; break;
77                    default: break;
78                }
79                /*$('html, body').animate({
80                    scrollTop: $(hash).offset().top
81                }, 1000);*/
82                _scrollTo(hash, -100);
83            }
84        },
85            500)
86    },
87        1000);
88}
89
90function menubutton() {
91    $('.menubutton').on('click', async function () {
92        var header = $('header').find('.body');
93        var header_mobile = $('.white').find('.body');
94
95        if (header) {
96            if ($(this).hasClass('active')) {
97                $(this).removeClass('active');
98                $(header).removeClass('mobile');
99                $('body').removeClass('mobile');
100                $(header_mobile).removeClass('mobile');
101            } else {
102                $(this).addClass('active');
103                $(header).addClass('mobile');
104                $('body').addClass('mobile');
105                $(header_mobile).addClass('mobile');
106            }
107        }
108
109    });
110}
111
112// function menuscroll() {
113//     let headerNav = $('header.header')
114//     let scrollPrev = 0
115//     $(window).scroll(function () {
116//         let scrolled = $(window).scrollTop()
117
118//         if (scrolled > 400) {
119//             if (scrolled < scrollPrev - 10) {
120//                 headerNav.removeClass('out')
121//             }
122
123//             if (scrolled > scrollPrev) {
124//                 headerNav.addClass('out')
125//             }
126//         } else {
127//             headerNav.removeClass('out')
128//         }
129//         scrollPrev = scrolled
130//     })
131// }
132
133function menumobscroll() {
134    $(window).on('scroll', function (event) {
135        var scrollValue = $(window).scrollTop();
136        if (scrollValue > $('.header').height()) {
137            $('.scroll_logo').addClass('scroll');
138        } else {
139            $('.scroll_logo').removeClass('scroll');
140        }
141    });
142}
143
144function clickmenu() {
145    $('.menuitem').on('click', async function (event) {
146        event.preventDefault();
147        var header = $('.white').find('.body');
148
149        if (header) {
150            if ($(header).hasClass('mobile')) {
151                $('.menubutton').removeClass('active');
152                $(header).removeClass('mobile');
153                $('body').removeClass('mobile');
154            }
155        }
156
157        let hash = $(this).attr('href');
158        var hashval = hash.match(/#([\s\S]*)$/);
159        if (hashval) {
160            hash = hashval[0];
161
162            if (hash) {
163                if ($(hash).length) {
164                    switch (hash) {
165                        case '#benefits': hash = '#benefits_block'; break;
166                        case '#stocks': hash = '#stocks_block'; break;
167                        default: break;
168                    }
169                    _scrollTo(hash, -100);
170                    return true;
171                }
172            }
173        }
174        console.log('Location...');
175        window.location.href = $(this).attr('href');
176        //window.open(window.location.href,"_self");
177    });
178}
179
180function hidemenu() {
181    $(document).mouseup(function (e) {
182        var div_header = $('header.header');
183        if (!div_header.is(e.target) && div_header.has(e.target).length === 0) {
184            var header = $('header').find('.body');
185            if (header) {
186                if ($(header).hasClass('mobile')) {
187                    $('.menubutton').removeClass('active');
188                    $(header).removeClass('mobile');
189                    $('body').removeClass('mobile');
190                }
191            }
192        }
193    });
194}
195
196function resizepage() {
197    $(window).resize(function () {
198        var header = $('.white').find('.body');
199
200        if (header) {
201            if ($(header).hasClass('mobile')) {
202                $('.menubutton').removeClass('active');
203                $(header).removeClass('mobile');
204                $('body').removeClass('mobile');
205            }
206        }
207    });
208}
209
210//Обновление старых позиций
211allorders = JSON.parse(localStorage.getItem('cart'));
212if (allorders) {
213    allorders.map(item => {
214        if (item.kbzhu) {
215            if (item.kbzhu.length > 1) {
216                localStorage.removeItem('cart');
217            }
218        }
219    });
220}
221
222function clicktocart() {
223    $('.assortment').on('click', '.addtocart', function () {
224        let localArr = JSON.parse(localStorage.getItem('cart'));
225        if (localArr) {
226            //Поиск данной карточки в куках, формриование массива новых карточек
227            var find_id = $(this).attr('data-id');
228            var find_size = $(this).attr('data-size');
229            var find_name = $(this).attr('data-name');
230            var data_price = Number($(this).attr('data-price'));
231
232            var find = localArr.find(x => x.id === find_id && x.size === find_size && x.name === find_name);
233            if (find?.id === find_id && find?.size === find_size && find?.name === find_name) {
234                const new_cart = localArr.filter(item => !(item.id == find.id && item.size == find.size && item.name == find.name)); //поиск других карточек
235                find.count++;
236                find.price = find.price + data_price;
237                new_cart.push(find); /// добавление к ним найденной, но с увеличенным количестовм
238                localStorage.setItem('cart', JSON.stringify(new_cart)); // формирование новых карточек
239            }
240            else {
241                let item = {
242                    id: 0,
243                    number: localArr.length + 1,
244                    size: '',
245                    size_id: '',
246                    type: '',
247                    cat: '',
248                    name: '',
249                    text: '',
250                    photo: '',
251                    price: 0,
252                    cost: 0,
253                    count: 1,
254                    mod: [],
255                    hot: []
256                };
257
258                item.id = $(this).attr('data-id');
259                item.size = $(this).attr('data-size');
260                item.size_id = $(this).attr('data-size-id');
261                item.type = $(this).attr('data-type');
262                item.name = $(this).attr('data-name');
263                item.text = $(this).attr('data-text');
264                item.photo = $(this).attr('data-photo');
265                item.cat = $(this).attr('data-cat');
266                item.price = Number($(this).attr('data-price'));
267                item.cost = Number($(this).attr('data-price'));
268
269                //Острота - Переобразование строки в массив по остроте и потом в массив для разделения их
270                let hot = $(this).attr('data-hot');
271                var massiv_hot = hot.split(';');
272                massiv_hot.pop();
273                massiv_hot.forEach(function (element, key) {
274                    var massiv_hot_even = element.split('#');
275                    item.hot[key] = [massiv_hot_even[0], massiv_hot_even[1], massiv_hot_even[2]];
276                });
277
278                //Моды - Переобразование строки в массив по модам и потом в массив для разделения их
279                let mod = $(this).attr('data-mod');
280                var massiv_mod = mod.split(';');
281                massiv_mod.pop();
282                massiv_mod.forEach(function (element, key) {
283                    var massiv_mod_even = element.split('#');
284                    item.mod[key] = [massiv_mod_even[0], massiv_mod_even[1], massiv_mod_even[2], massiv_mod_even[3], massiv_mod_even[4]];
285                });
286
287                //Добавление товара в куки
288                localArr.push(item);
289                localStorage.setItem('cart', JSON.stringify(localArr));
290
291            }
292        }
293        else {
294            let item = {
295                id: 0,
296                number: 1,
297                size: '',
298                size_id: '',
299                type: '',
300                cat: '',
301                name: '',
302                text: '',
303                photo: '',
304                price: 0,
305                cost: 0,
306                count: 1,
307                mod: [],
308                hot: []
309            };
310
311            item.id = $(this).attr('data-id');
312            item.size = $(this).attr('data-size');
313            item.size_id = $(this).attr('data-size-id');
314            item.type = $(this).attr('data-type');
315            item.name = $(this).attr('data-name');
316            item.text = $(this).attr('data-text');
317            item.cat = $(this).attr('data-cat');
318            item.photo = $(this).attr('data-photo');
319            item.price = Number($(this).attr('data-price'));
320            item.cost = Number($(this).attr('data-price'));
321
322            //Острота - Переобразование строки в массив по остроте и потом в массив для разделения их
323            let hot = $(this).attr('data-hot');
324            var massiv_hot = hot.split(';');
325            massiv_hot.pop();
326            massiv_hot.forEach(function (element, key) {
327                var massiv_hot_even = element.split('#');
328                item.hot[key] = [massiv_hot_even[0], massiv_hot_even[1], massiv_hot_even[2]];
329            });
330
331
332            //Моды - Переобразование строки в массив по модам и потом в массив для разделения их
333            let mod = $(this).attr('data-mod');
334            var massiv_mod = mod.split(';');
335            massiv_mod.pop();
336            massiv_mod.forEach(function (element, key) {
337                var massiv_mod_even = element.split('#');
338                item.mod[key] = [massiv_mod_even[0], massiv_mod_even[1], massiv_mod_even[2], massiv_mod_even[3], massiv_mod_even[4]];
339            });
340
341            //Добавление товара в куки
342            let products = [];
343            products.push(item);
344            localStorage.setItem('cart', JSON.stringify(products));
345
346        }
347
348        //Перерасчет количества товаров
349        let allLocalArr = JSON.parse(localStorage.getItem('cart'))
350        let sum = 0;
351        allLocalArr.map(item => {
352            sum += Number(item.count)
353        })
354
355        if (sum) {
356            $('.cart').find('.text').text(`Корзина (${sum})`);
357            $('.float_cart_count').text(sum);
358            $('.float_cart_count').addClass('active');
359        } else {
360            $('.cart').find('.text').text(`Корзина`);
361            $('.float_cart_count').text('');
362            $('.float_cart_count').removeClass('active');
363        }
364
365        //Обновление мини и больших карточек
366        if (typeof update_minicart === "function") {
367            $('.cart_body').empty();
368            $('.all-pop').empty();
369            update_minicart(1);
370            update_cart();
371
372        }
373
374    });
375
376}
377
378function cityButton() {
379    $('.city_button').on('click', async function () {
380        let button = $(this);
381        let parent_div = button.parent();
382        let city = parent_div.find('.city');
383        if ($(button).hasClass('active')) {
384            $(button).removeClass('active');
385            $(city).removeClass('active');
386        } else {
387            $(button).addClass('active');
388            $(city).addClass('active');
389        }
390    });
391}
392
393function setCart() {
394    let allLocalArr = JSON.parse(localStorage.getItem('cart'));
395    let sum = 0;
396    if (allLocalArr) {
397        allLocalArr.map(item => { sum += Number(item.count) });
398        if (sum) {
399            $('.cart').find('.text').text(`Корзина (${sum})`);
400            $('.float_cart_count').text(sum);
401            $('.float_cart_count').addClass('active');
402        } else {
403            $('.cart').find('.text').text(`Корзина`);
404            $('.float_cart_count').text('');
405            $('.float_cart_count').text(sum);
406            $('.float_cart_count').removeClass('active');
407        }
408    }
409
410    $('.float_cart_count').bind("DOMSubtreeModified", function () {
411        console.log(this);
412        $(this).animate({
413            transform: 'scale(1.2)'
414        },
415            300,
416            function () {
417                // выполняется, когда анимация завершена
418            })
419    });
420}
421
422function setCity() {
423    let city = localStorage.getItem('city');
424    if (!city) {
425        city = 'Нижний Новгород';
426    }
427
428    $('.city_button').find('.text').text(city);
429    let button = $('.changecity');
430    $(button).removeClass('active');
431    $(`.changecity[data-name="${city}"]`).addClass('active');
432
433    $('.changecity').on('click', async function () {
434        let city = $(this).attr('data-name');
435
436        localStorage.setItem('city', city);
437
438        $('.city_button').find('.text').text(city);
439        let button = $('.changecity');
440        $(button).removeClass('active');
441        $(`.changecity[data-name="${city}"]`).addClass('active');
442
443        $('.search_city').val(city);
444    });
445
446    $('.search_city').val(city);
447}
448
449tippy('button', {
450    placement: 'top-end',
451    arrow: true,
452    animation: 'fade',
453
454    theme: 'white',
455
456    content(reference) {
457        const id = reference.getAttribute('data-template');
458        const template = document.getElementById(id);
459        return template.innerHTML;
460    },
461    allowHTML: true,
462
463    trigger: 'click',
464
465});
466
467const gallery_default_mini = new Swiper(".gallery_default_mini", {
468    spaceBetween: 10,
469    slidesPerView: 2,
470    freeMode: true,
471    watchSlidesProgress: true,
472    direction: 'vertical',
473
474    breakpoints: {
475
476        0: {
477            direction: 'horizontal'
478        },
479
480        1101: {
481            direction: 'vertical'
482        }
483    }
484
485
486});
487
488const gallery_default = new Swiper(".gallery_default", {
489    spaceBetween: 10,
490
491    thumbs: {
492        swiper: gallery_default_mini,
493    },
494});
495
496$(document).ready(function () {
497
498    function Scroll_block() {
499        var scroll_top = $(document).scrollTop();
500
501        $(".menu a[href^='/#']").each(function () {
502            var hash = $(this).attr("href").replace('/', ' ');
503
504            var target = $(hash);
505
506            if (target.length) {
507                if (target.position().top - 100 <= scroll_top && target.position().top + target.outerHeight() > scroll_top) {
508                    $(".menu li.active").parent().removeClass("active");
509                    $(this).parent().addClass("active");
510                } else {
511                    $(this).parent().removeClass("active");
512                }
513            }
514        });
515    }
516
517
518    $(document).on("scroll", Scroll_block);
519
520    //     $("a[href^=#]").click(function(e){
521    //         e.preventDefault();
522
523    //         $(document).off("scroll");
524    //         $(".menu li.active").parent().removeClass("active");
525    //         $(this).parent().addClass("active");
526    //         var hash = $(this).attr("href");
527    //         var target = $(hash);
528
529    //         $("html, body").animate({
530    //             scrollTop: target.offset().top
531    //         }, 500, function(){
532    //             window.location.hash = hash;
533    //             $(document).on("scroll", Scroll_block);
534    //         });
535
536    //     });
537
538});

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.