From c8108c2234ec61a883ce9ba8e053b72d5984459a Mon Sep 17 00:00:00 2001 From: maksim Date: Fri, 13 Jun 2025 11:09:56 +0300 Subject: [PATCH] =?UTF-8?q?Task:=206767=20|=20=D0=B8=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D0=B0=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B2=D0=B5=D1=81=D0=B0=20=D0=B2=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=BE=D1=87=D0=BA=D0=B5=20=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/footer/assets/js/footer.js | 649 +++++++++--------- 1 file changed, 325 insertions(+), 324 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js b/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js index 16bf619..4a3b479 100644 --- a/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js +++ b/wp-content/themes/cosmopet/modules/footer/assets/js/footer.js @@ -3,292 +3,292 @@ (function ($) { const metaLocale = document.querySelector('meta[property="og:locale"]'); const localeValue = metaLocale.getAttribute('content'); - function wc_cart_summary_upd(){ - let total = 0 - $('.cart_item').each(function(){ - total += Number($(this).data('cost')) - }) - return total - } - $('[data-pname]').on('click', function(){ - $('#sub_product_name').val($(this).data('pname')) - }) - - $(document).on('submit', '.product-item__form, .detail-block__form', function (e) { - e.preventDefault(); - var $form = $(this) - var product_qty = $form.find('input[name=quantity]').val() || 1 - var product_id = $form.find('input[name=product_id]').val() - var variation_id = $form.find('input[name=variation_id]').val() || 0; - var title = $(this).data('name') - var data = { - action: 'woocommerce_ajax_add_to_cart', - product_id: product_id, - product_sku: '', - quantity: product_qty, - variation_id: variation_id, - }; - dataLayer.push({ - "ecommerce": { - "currencyCode": "RUB", - "add": { - "products": [ - { - "id": product_id, - "name": title, - "quantity": product_qty, - } - ] - } - } - }); - - return false; - }); - - $(document).on('submit', '.modal__form-sub', function (e) { - e.preventDefault(); - var email = $(this).find('input[name="email"]').val() - var data = $(this).serialize() - $.ajax({ - type: 'post', - url: woocommerce_params.ajax_url, - data: data, - beforeSend: function (response) { - // $thisbutton.removeClass('added').addClass('loading'); - }, - complete: function (response) { - // $thisbutton.addClass('added').removeClass('loading'); - }, - success: function (response) { - $('.modal__to-know').removeClass('active') - $('#sub-result-email').html(email) - $('.modal__to-know-submit').addClass('active').css('filter', 'blur(0px)') - }, - }); - }); - - $(document).on('submit', '.form--contact', function (e) { - e.preventDefault(); - var form = this; - var data = $(this).serialize() - $.ajax({ - type: 'post', - url: woocommerce_params.ajax_url, - data: data, - beforeSend: function (response) { - // $thisbutton.removeClass('added').addClass('loading'); - }, - complete: function (response) { - // $thisbutton.addClass('added').removeClass('loading'); - }, - success: function (response) { - $(form).addClass('submited') - }, - }); - }); + // function wc_cart_summary_upd(){ + // let total = 0 + // $('.cart_item').each(function(){ + // total += Number($(this).data('cost')) + // }) + // return total + // } + // $('[data-pname]').on('click', function(){ + // $('#sub_product_name').val($(this).data('pname')) + // }) - $('body').on('click', '.modal-basket__item-before', function(){ - var key = $(this).data('id') - var p_ID = $(this).data('pr'); - var var_ID = $(this).data('var'); - var quantity = $(this).closest('.modal-basket__item').find('.counter__input').val() - var layout = ` - - - - ` - if(localeValue == 'en_US'){ - var layout = ` - - - - ` - } + // $(document).on('submit', '.product-item__form, .detail-block__form', function (e) { + // e.preventDefault(); + // var $form = $(this) + // var product_qty = $form.find('input[name=quantity]').val() || 1 + // var product_id = $form.find('input[name=product_id]').val() + // var variation_id = $form.find('input[name=variation_id]').val() || 0; + // var title = $(this).data('name') + // var data = { + // action: 'woocommerce_ajax_add_to_cart', + // product_id: product_id, + // product_sku: '', + // quantity: product_qty, + // variation_id: variation_id, + // }; + // dataLayer.push({ + // "ecommerce": { + // "currencyCode": "RUB", + // "add": { + // "products": [ + // { + // "id": product_id, + // "name": title, + // "quantity": product_qty, + // } + // ] + // } + // } + // }); + + // return false; + // }); + + // $(document).on('submit', '.modal__form-sub', function (e) { + // e.preventDefault(); + // var email = $(this).find('input[name="email"]').val() + // var data = $(this).serialize() + // $.ajax({ + // type: 'post', + // url: woocommerce_params.ajax_url, + // data: data, + // beforeSend: function (response) { + // // $thisbutton.removeClass('added').addClass('loading'); + // }, + // complete: function (response) { + // // $thisbutton.addClass('added').removeClass('loading'); + // }, + // success: function (response) { + // $('.modal__to-know').removeClass('active') + // $('#sub-result-email').html(email) + // $('.modal__to-know-submit').addClass('active').css('filter', 'blur(0px)') + // }, + // }); + // }); + + // $(document).on('submit', '.form--contact', function (e) { + // e.preventDefault(); + // var form = this; + // var data = $(this).serialize() + // $.ajax({ + // type: 'post', + // url: woocommerce_params.ajax_url, + // data: data, + // beforeSend: function (response) { + // // $thisbutton.removeClass('added').addClass('loading'); + // }, + // complete: function (response) { + // // $thisbutton.addClass('added').removeClass('loading'); + // }, + // success: function (response) { + // $(form).addClass('submited') + // }, + // }); + // }); + + // $('body').on('click', '.modal-basket__item-before', function(){ + // var key = $(this).data('id') + // var p_ID = $(this).data('pr'); + // var var_ID = $(this).data('var'); + // var quantity = $(this).closest('.modal-basket__item').find('.counter__input').val() + // var layout = ` + // + + // + // ` + // if(localeValue == 'en_US'){ + // var layout = ` + // + + // + // ` + // } - var old_html = $(this).closest('.modal-basket__item').html() - $(this).closest('.modal-basket__item').addClass('.modal-basket__item--return').html(layout) - var title = $(this).closest('.cart_item').find('.modal-basket-item__title').html() + // var old_html = $(this).closest('.modal-basket__item').html() + // $(this).closest('.modal-basket__item').addClass('.modal-basket__item--return').html(layout) + // var title = $(this).closest('.cart_item').find('.modal-basket-item__title').html() - var timerVal = 5; + // var timerVal = 5; - var interval = setInterval(function(){ - timerVal -= 1; - if (timerVal > 0){ - $(`#${key}_timer`).html(timerVal) - } - else{ - - dataLayer.push({ - "ecommerce": { - "currencyCode": "RUB", - "remove": { - "products": [ - { - "id": p_ID, - "name": title, - "quantity": quantity, - } - ] - } - } - }); - var input = 0; - var productID = key; - - var data = { - action: 'get_cartprice', - quantity: input, - product: productID - }; - $.ajax({ - type: 'post', - url: '/wp-admin/admin-ajax.php', - data: data, - beforeSend: function (response) { - // $thisbutton.removeClass('added').addClass('loading'); - }, - complete: function (response) { - // $thisbutton.addClass('added').removeClass('loading'); - }, - success: function (response) { + // var interval = setInterval(function(){ + // timerVal -= 1; + // if (timerVal > 0){ + // $(`#${key}_timer`).html(timerVal) + // } + // else{ + + // dataLayer.push({ + // "ecommerce": { + // "currencyCode": "RUB", + // "remove": { + // "products": [ + // { + // "id": p_ID, + // "name": title, + // "quantity": quantity, + // } + // ] + // } + // } + // }); + // var input = 0; + // var productID = key; + + // var data = { + // action: 'get_cartprice', + // quantity: input, + // product: productID + // }; + // $.ajax({ + // type: 'post', + // url: '/wp-admin/admin-ajax.php', + // data: data, + // beforeSend: function (response) { + // // $thisbutton.removeClass('added').addClass('loading'); + // }, + // complete: function (response) { + // // $thisbutton.addClass('added').removeClass('loading'); + // }, + // success: function (response) { - if(response['cart_count'] > 0){ - $('.mini-profile__button--counter').removeClass('disabled').html(response['cart_count']) - } - else{ - $('.mini-profile__button--counter').addClass('disabled').html(response['cart_count']) - } - }, - }); - $(`#${key}_timer`).closest('.modal-basket__item').remove() - if (Number(wc_cart_summary_upd()) > 0){ - $('#cart_total').html(wc_cart_summary_upd()) - } - else{ - var tmpl = ` - - ` - - if(localeValue == 'en_US'){ - var tmpl = ` - - ` - } - $('.modal__basket').html(tmpl) - } - clearInterval(interval); - } - }, 1000) + // if(response['cart_count'] > 0){ + // $('.mini-profile__button--counter').removeClass('disabled').html(response['cart_count']) + // } + // else{ + // $('.mini-profile__button--counter').addClass('disabled').html(response['cart_count']) + // } + // }, + // }); + // $(`#${key}_timer`).closest('.modal-basket__item').remove() + // if (Number(wc_cart_summary_upd()) > 0){ + // $('#cart_total').html(wc_cart_summary_upd()) + // } + // else{ + // var tmpl = ` + + // ` + + // if(localeValue == 'en_US'){ + // var tmpl = ` + + // ` + // } + // $('.modal__basket').html(tmpl) + // } + // clearInterval(interval); + // } + // }, 1000) - $(`#${key}_return`).one('click', function(){ - $(this).closest('.modal-basket__item').removeClass('.modal-basket__item--return').html(old_html) - clearInterval(interval); - }) - }) + // $(`#${key}_return`).one('click', function(){ + // $(this).closest('.modal-basket__item').removeClass('.modal-basket__item--return').html(old_html) + // clearInterval(interval); + // }) + // }) - $('body').on('click', '.state__button', function(){ - var s = $(this).closest('.select') - var id = $(this).data('id') - var bc = $(this).data('bc') + // $('body').on('click', '.state__button', function(){ + // var s = $(this).closest('.select') + // var id = $(this).data('id') + // var bc = $(this).data('bc') - var form = $(this).closest('.product-item__form') + // var form = $(this).closest('.product-item__form') - $(form).find('input[name="variation_id"]').val(id) - $(form).find('.counter__input').data('maxcount', $(this).data('stock')).attr('data-maxcount', $(this).data('stock')) - if (Number($(form).find('.counter__input').val()) > Number($(form).find('.counter__input').data('maxcount'))){ - $(form).find('.counter__input').val($(form).find('.counter__input').data('maxcount')) - } - var input = $(form).find('.counter__input').val() - $(form).find('.product-item-overlay__price').data('basecost', bc).html(Number(bc) * Number(input)) - }) + // $(form).find('input[name="variation_id"]').val(id) + // $(form).find('.counter__input').data('maxcount', $(this).data('stock')).attr('data-maxcount', $(this).data('stock')) + // if (Number($(form).find('.counter__input').val()) > Number($(form).find('.counter__input').data('maxcount'))){ + // $(form).find('.counter__input').val($(form).find('.counter__input').data('maxcount')) + // } + // var input = $(form).find('.counter__input').val() + // $(form).find('.product-item-overlay__price').data('basecost', bc).html(Number(bc) * Number(input)) + // }) - $('body').on('click', '.btn-load-ajax', function(){ - var page = Number($(this).data('page')) + 1 - var maxpage = Number($(this).data('maxpage')) - var data = { - ajax_load: 'ajax', - }; - var btn = this - var baseUrl = jQuery(location).attr('origin') + jQuery(location).attr('pathname') - baseUrl += 'page/' + page + '/' - var searchUrl = baseUrl - if (jQuery(location).attr('search')){ - searchUrl += jQuery(location).attr('search') + '&ajax_search=ajax' - } - else{ - searchUrl += '?ajax_search=ajax' - } - $.ajax({ - type: 'get', - url: searchUrl, - data: data, - beforeSend: function (response) { - $(btn).attr('disabled', true) - $(btn).attr('data-page', page) - $(btn).data('page', page) - }, - complete: function (response) { - if (page >= maxpage){ - $(btn).remove() - } - else{ - $(btn).attr('disabled', false) - } - }, - success: function (response) { - $('.products').append(response) - initCounters() - initOverlay() - initSelect() - modalOpen('.open-to-know', '.modal__to-know'); - - /// РЕШЕНИЕ ДЛЯ СТЕНДА AJAX ДЛЯ ПОДГРУЗКИ AJAX - document.querySelectorAll('img').forEach(img => { - var str = img.attributes['src'].value.replace('https://cosmopet.good-production.xyz/', 'https://cosmopet.shop/') - checkImage(str, function(){ img.attributes['src'].value = str }); - if (img.attributes['srcset']){ - img.attributes['srcset'].value = img.attributes['srcset'].value.replace('cosmopet.good-production.xyz', '') - } - }) - // - }, - }); - }) + // $('body').on('click', '.btn-load-ajax', function(){ + // var page = Number($(this).data('page')) + 1 + // var maxpage = Number($(this).data('maxpage')) + // var data = { + // ajax_load: 'ajax', + // }; + // var btn = this + // var baseUrl = jQuery(location).attr('origin') + jQuery(location).attr('pathname') + // baseUrl += 'page/' + page + '/' + // var searchUrl = baseUrl + // if (jQuery(location).attr('search')){ + // searchUrl += jQuery(location).attr('search') + '&ajax_search=ajax' + // } + // else{ + // searchUrl += '?ajax_search=ajax' + // } + // $.ajax({ + // type: 'get', + // url: searchUrl, + // data: data, + // beforeSend: function (response) { + // $(btn).attr('disabled', true) + // $(btn).attr('data-page', page) + // $(btn).data('page', page) + // }, + // complete: function (response) { + // if (page >= maxpage){ + // $(btn).remove() + // } + // else{ + // $(btn).attr('disabled', false) + // } + // }, + // success: function (response) { + // $('.products').append(response) + // initCounters() + // initOverlay() + // initSelect() + // modalOpen('.open-to-know', '.modal__to-know'); + + // /// РЕШЕНИЕ ДЛЯ СТЕНДА AJAX ДЛЯ ПОДГРУЗКИ AJAX + // document.querySelectorAll('img').forEach(img => { + // var str = img.attributes['src'].value.replace('https://cosmopet.good-production.xyz/', 'https://cosmopet.shop/') + // checkImage(str, function(){ img.attributes['src'].value = str }); + // if (img.attributes['srcset']){ + // img.attributes['srcset'].value = img.attributes['srcset'].value.replace('cosmopet.good-production.xyz', '') + // } + // }) + // // + // }, + // }); + // }) // $('body').on('click', '.singular-w-btn', function(){ // var wg = $(this).data('wg') @@ -307,61 +307,62 @@ // }) // асинхронный запрос при отправке формы - $( '#ajaxform' ).on( 'submit',function( event ) { - event.preventDefault(); - - const form = $(this); - - $.ajax( { - type : 'POST', - url : woocommerce_params.ajax_url, - data : form.serialize(), - beforeSend : function( xhr ) { - $('.products').addClass('loading') - form.find('.button-submit').addClass('loading').attr('disabled', true) - }, - success : function( data ) { - $( '.products' ).html( data.products ); - $('.product__tag').html(data.tags); - $( '.btn-load-ajax' ).remove() - form.find('.button-submit').removeClass('loading').attr('disabled', false) - form.find('.modal__close').click() - $('.products').removeClass('loading') - if (data.err){ - $('.product__error-button').show() - } - else{ - $('.product__error-button').hide() - } - - initCounters() - initOverlay() - initSelect() - modalOpen('.open-to-know', '.modal__to-know'); - - document.querySelectorAll('img').forEach(img => { - var str = img.attributes['src'].value.replace('https://cosmopet.good-production.xyz/', 'https://cosmopet.shop/') - checkImage(str, function(){ img.attributes['src'].value = str }); - if (img.attributes['srcset']){ - img.attributes['srcset'].value = img.attributes['srcset'].value.replace('cosmopet.good-production.xyz', '') - } - }) - } - - } ); - - } ); - - - $('body').on('click', '.product-tag__item', function(){ - $('#tax_' + $(this).data('tag')).find('input').prop('checked', false) - $('#tax_' + $(this).data('tag')).removeClass('active'); - $(this).remove() - $('#ajaxform').submit() - }) + // $( '#ajaxform' ).on( 'submit',function( event ) { + // event.preventDefault(); + + // const form = $(this); + + // $.ajax( { + // type : 'POST', + // url : woocommerce_params.ajax_url, + // data : form.serialize(), + // beforeSend : function( xhr ) { + // $('.products').addClass('loading') + // form.find('.button-submit').addClass('loading').attr('disabled', true) + // }, + // success : function( data ) { + // $( '.products' ).html( data.products ); + // $('.product__tag').html(data.tags); + // $( '.btn-load-ajax' ).remove() + // form.find('.button-submit').removeClass('loading').attr('disabled', false) + // form.find('.modal__close').click() + // $('.products').removeClass('loading') + // if (data.err){ + // $('.product__error-button').show() + // } + // else{ + // $('.product__error-button').hide() + // } + + // initCounters() + // initOverlay() + // initSelect() + // modalOpen('.open-to-know', '.modal__to-know'); + + // document.querySelectorAll('img').forEach(img => { + // var str = img.attributes['src'].value.replace('https://cosmopet.good-production.xyz/', 'https://cosmopet.shop/') + // checkImage(str, function(){ img.attributes['src'].value = str }); + // if (img.attributes['srcset']){ + // img.attributes['srcset'].value = img.attributes['srcset'].value.replace('cosmopet.good-production.xyz', '') + // } + // }) + // } + + // } ); + + // } ); + + + // $('body').on('click', '.product-tag__item', function(){ + // $('#tax_' + $(this).data('tag')).find('input').prop('checked', false) + // $('#tax_' + $(this).data('tag')).removeClass('active'); + // $(this).remove() + // $('#ajaxform').submit() + // }) // Login + $('.login_popup').on('click', function(e){ e.preventDefault(); $('.login_modal').addClass('active');