Fix | js and layout bugs fix

pull/15/head
Your Name 3 months ago
parent e1fcc232b9
commit ceebd35a69
  1. 13
      wp-content/themes/cosmopet/functions.php
  2. 6
      wp-content/themes/cosmopet/modules/header/module-controller.php
  3. 3
      wp-content/themes/cosmopet/modules/layout/assets/img/svg/main/filter.svg
  4. 69
      wp-content/themes/cosmopet/modules/layout/assets/js/gp-main.js
  5. 21
      wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js
  6. 73
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-core.css
  7. 50
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-desktop.css
  8. 286
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/js/gp-form.js
  9. 156
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/js/gp-function.js
  10. 88
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/js/gp-main.js
  11. 129
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/js/single-product.js
  12. 1
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/js/tabs.js
  13. 1
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/js/toggle.js
  14. 13
      wp-content/themes/cosmopet/modules/shop/components/single-product/component-template.twig
  15. 7
      wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig
  16. 4
      wp-content/themes/cosmopet/woocommerce/assets/css/gp-style-desktop.css
  17. 55
      wp-content/themes/cosmopet/woocommerce/assets/js/gp-main.js

@ -957,3 +957,16 @@ function remove_view_cart_button_js() {
<?php
}
add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
$module_handles = [
'shop-single-product-tabs', // для tabs.js
'shop-single-product-toggle', // для toggle.js
];
if ( in_array( $handle, $module_handles ) ) {
return '<script type="module" src="' . esc_url( $src ) . '"></script>';
}
return $tag;
}, 10, 3 );

@ -41,7 +41,11 @@ add_filter('timber/context', function($context) {
if ($about_page) {
$context['about_url'] = '/o-kompanii/';
$context['about_url_en'] = '/en/about-us/';
} else {
}
else if (SITE_DOMAIN == 'AE'){
$context['about_url_en'] = '/en/about-us/';
}
else {
$context['about_url'] = 'https://cosmopet.shop/chto-takoe-entoprotein/';
$context['about_url_en'] = 'https://cosmopet.shop/en/about-2/';
}

@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6 3.25C6.41421 3.25 6.75 3.58579 6.75 4V7.35424C7.19755 7.48113 7.60976 7.72067 7.94454 8.05546C8.46027 8.57118 8.75 9.27065 8.75 10C8.75 10.7293 8.46027 11.4288 7.94454 11.9445C7.60976 12.2793 7.19755 12.5189 6.75 12.6458V20C6.75 20.4142 6.41421 20.75 6 20.75C5.58579 20.75 5.25 20.4142 5.25 20V12.6458C4.80245 12.5189 4.39024 12.2793 4.05546 11.9445C3.53973 11.4288 3.25 10.7293 3.25 10C3.25 9.27065 3.53973 8.57118 4.05546 8.05546C4.39024 7.72067 4.80245 7.48113 5.25 7.35424V4C5.25 3.58579 5.58579 3.25 6 3.25ZM12 3.25C12.4142 3.25 12.75 3.58579 12.75 4V13.3542C13.1975 13.4811 13.6098 13.7207 13.9445 14.0555C14.4603 14.5712 14.75 15.2707 14.75 16C14.75 16.7293 14.4603 17.4288 13.9445 17.9445C13.6098 18.2793 13.1975 18.5189 12.75 18.6458V20C12.75 20.4142 12.4142 20.75 12 20.75C11.5858 20.75 11.25 20.4142 11.25 20V18.6458C10.8025 18.5189 10.3902 18.2793 10.0555 17.9445C9.53973 17.4288 9.25 16.7293 9.25 16C9.25 15.2707 9.53973 14.5712 10.0555 14.0555C10.3902 13.7207 10.8025 13.4811 11.25 13.3542V4C11.25 3.58579 11.5858 3.25 12 3.25ZM18 3.25C18.4142 3.25 18.75 3.58579 18.75 4V4.35424C19.1975 4.48112 19.6098 4.72067 19.9445 5.05546C20.4603 5.57118 20.75 6.27065 20.75 7C20.75 7.72935 20.4603 8.42882 19.9445 8.94454C19.6098 9.27933 19.1975 9.51887 18.75 9.64576V20C18.75 20.4142 18.4142 20.75 18 20.75C17.5858 20.75 17.25 20.4142 17.25 20V9.64576C16.8025 9.51887 16.3902 9.27933 16.0555 8.94454C15.5397 8.42882 15.25 7.72935 15.25 7C15.25 6.27065 15.5397 5.57118 16.0555 5.05546C16.3902 4.72067 16.8025 4.48112 17.25 4.35424V4C17.25 3.58579 17.5858 3.25 18 3.25ZM18 5.75C17.6685 5.75 17.3505 5.8817 17.1161 6.11612C16.8817 6.35054 16.75 6.66848 16.75 7C16.75 7.33152 16.8817 7.64946 17.1161 7.88388C17.3505 8.1183 17.6685 8.25 18 8.25C18.3315 8.25 18.6495 8.1183 18.8839 7.88388C19.1183 7.64946 19.25 7.33152 19.25 7C19.25 6.66848 19.1183 6.35054 18.8839 6.11612C18.6495 5.8817 18.3315 5.75 18 5.75ZM6 8.75C5.66848 8.75 5.35054 8.8817 5.11612 9.11612C4.8817 9.35054 4.75 9.66848 4.75 10C4.75 10.3315 4.8817 10.6495 5.11612 10.8839C5.35054 11.1183 5.66848 11.25 6 11.25C6.33152 11.25 6.64946 11.1183 6.88388 10.8839C7.1183 10.6495 7.25 10.3315 7.25 10C7.25 9.66848 7.1183 9.35054 6.88388 9.11612C6.64946 8.8817 6.33152 8.75 6 8.75ZM12 14.75C11.6685 14.75 11.3505 14.8817 11.1161 15.1161C10.8817 15.3505 10.75 15.6685 10.75 16C10.75 16.3315 10.8817 16.6495 11.1161 16.8839C11.3505 17.1183 11.6685 17.25 12 17.25C12.3315 17.25 12.6495 17.1183 12.8839 16.8839C13.1183 16.6495 13.25 16.3315 13.25 16C13.25 15.6685 13.1183 15.3505 12.8839 15.1161C12.6495 14.8817 12.3315 14.75 12 14.75Z" fill="#121212"/>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

@ -156,35 +156,68 @@ toggleOpenX('.toggle', '.toggle__title', '.toggle__content', '.toggle__block-con
// toggle
// radio-button
let radioButtons = document.querySelectorAll('.radio-button');
// let radioButtons = document.querySelectorAll('.radio-button');
radioButtons.forEach(radioBlock => {
let buttons = radioBlock.querySelectorAll('.button');
// radioButtons.forEach(radioBlock => {
// let buttons = radioBlock.querySelectorAll('.button');
buttons.forEach(button => {
let input = radioBlock.querySelector('.radio-button__input');
// buttons.forEach(button => {
// let input = radioBlock.querySelector('.radio-button__input');
button.onclick = function (e) {
e.preventDefault();
// button.onclick = function (e) {
// e.preventDefault();
buttons.forEach(thisButton => {
if (thisButton.classList.contains('active')) {
thisButton.classList.remove('active')
}
})
// buttons.forEach(thisButton => {
// if (thisButton.classList.contains('active')) {
// thisButton.classList.remove('active')
// }
// })
let text = button.textContent.trim();
// let text = button.textContent.trim();
button.classList.toggle('active');
// button.classList.toggle('active');
input.value = text;
}
})
})
// input.value = text;
// }
// })
// })
// radio-button
// overlay
let products = document.querySelectorAll('.product__item');
products.forEach(productItem => {
let button = productItem.querySelector('.open-overlay'),
overlay = productItem.querySelector('.product-item__overlay');
if (button) {
button.onclick = function (e) {
console.log('Открытие overlay для товара', productItem);
document.querySelectorAll('.product__item').forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
}
});
document.querySelectorAll('.product-item__overlay').forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
}
});
productItem.classList.toggle('active');
overlay.classList.toggle('active');
console.log('overlay toggled', overlay.classList.contains('active'));
}
}
})
// overlay
// checkbox
let checkbox = document.querySelectorAll('.checkbox');

@ -278,6 +278,27 @@ jQuery(document).ready(function($) {
}
});
}
$('body').on('click', '.add_to_cart_button', function() {
var btn = $(this);
if (!btn.hasClass('loading')) {
btn.addClass('loading');
btn.data('original-text', btn.html());
btn.css('position', 'relative');
btn.html('<span class="spinner" style="width:20px;height:20px;display:inline-block;"><svg width="20" height="20" viewBox="0 0 50 50"><circle cx="25" cy="25" r="20" fill="none" stroke="#ffffff" stroke-width="5" stroke-linecap="round" stroke-dasharray="31.415, 31.415" transform="rotate(72.3246 25 25)"><animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.7s" repeatCount="indefinite"/></circle></svg></span>');
}
});
// Убираем спиннер после завершения ajax WooCommerce
$(document.body).on('added_to_cart', function(e, fragments, cart_hash, $button) {
if ($button && $button.length) {
$button.removeClass('loading');
if ($button.data('original-text')) {
$button.html($button.data('original-text'));
$button.removeData('original-text');
}
}
});
});

@ -17,79 +17,6 @@ a{
cursor: pointer;
}
/* Craftwork Grotesk */
@font-face {
font-family: "Craftwork Grotesk";
src: local("Craftwork Grotesk Bold"),
url("../fonts/craftwork/CraftworkGrotesk-SemiBold.woff2") format("woff2"),
url("../fonts/craftwork/CraftworkGrotesk-Bold.woff") format("woff"),
url("../fonts/craftwork/craftwork-grotesk-bold.ttf") format("ttf");
font-weight: 700;
}
@font-face {
font-family: "Craftwork Grotesk";
src: local("Craftwork Grotesk SemiBold"),
url("../fonts/craftwork/CraftworkGrotesk-SemiBold.woff2") format("woff2"),
url("../fonts/craftwork/CraftworkGrotesk-SemiBold.woff") format("woff"),
url("../fonts/craftwork/craftwork-grotesk-semi-bold.ttf") format("ttf");
font-weight: 600;
}
@font-face {
font-family: "Craftwork Grotesk";
src: local("Craftwork Grotesk Medium"),
url("../fonts/craftwork/CraftworkGrotesk-Medium.woff2") format("woff2"),
url("../fonts/craftwork/CraftworkGrotesk-Medium.woff") format("woff"),
url("../fonts/craftwork/craftwork-grotesk-medium.ttf") format("ttf");
font-weight: 500;
}
@font-face {
font-family: "Craftwork Grotesk";
src: local("Craftwork Grotesk Regular"),
url("../fonts/craftwork/CraftworkGrotesk-Regular.woff2") format("woff2"),
url("../fonts/craftwork/CraftworkGrotesk-Regular.woff") format("woff"),
url("../fonts/craftwork/craftwork-grotesk-regular.ttf") format("ttf");
font-weight: 400;
}
/* Craftwork Grotesk */
/* din 2014 */
@font-face {
font-family: "DIN 2014 Rounded";
src: local("DIN 2014 Rounded Demi"),
url("../fonts/din-2014/din-2014-rounded-demi.woff2") format("woff2"),
url("../fonts/din-2014/din-2014-rounded-demi.woff") format("woff"),
url("../fonts/din-2014/din-2014-rounded-demi.ttf") format("ttf");
font-weight: 600;
}
@font-face {
font-family: "DIN 2014 Rounded";
src: local("DIN 2014 Rounded Regular"),
url("../fonts/din-2014/din-2014-rounded-regular.woff2") format("woff2"),
url("../fonts/din-2014/din-2014-rounded-regular.woff") format("woff"),
url("../fonts/din-2014/din-2014-rounded-regular.ttf") format("ttf");
font-weight: 400;
}
/* din 2014 */
/* roboto */
@font-face {
font-family: "Roboto";
src: local("Roboto Medium"),
url("../fonts/roboto/Roboto-Medium.woff2") format("woff2"),
url("../fonts/roboto/Roboto-Medium.woff") format("woff"),
url("../fonts/roboto/roboto-medium.ttf") format("ttf");
font-weight: 500;
}
@font-face {
font-family: "Roboto";
src: local("Roboto Regular"),
url("../fonts/roboto/Roboto-Regular.woff2") format("woff2"),
url("../fonts/roboto/Roboto-Regular.woff") format("woff"),
url("../fonts/roboto/roboto-medium.ttf") format("ttf");
font-weight: 400;
}
/* roboto */
/* Глобальные переменные: */
:root {

@ -15,6 +15,20 @@
}
/* header end */
.product__item.active::before{
opacity: 0;
}
.product-item__overlay.active{
top: 0;
}
.gallery.active{
opacity: 1;
pointer-events: auto;
}
/* product */
.product__item{
margin: 12px;
@ -144,10 +158,34 @@
text-transform: uppercase;
color: var(--text-black);
}
.product-item__price p::after{
.detail__image--width-perc-100{
width: calc(100% - 24px);
height: 600px;
}
.detail__image--width-perc-50{
width: calc(50% - 24px);
height: 288px;
}
.detail__image--width-perc-100 img{
width: 90%;
height: 90%;
object-fit: contain;
}
.detail__image--width-perc-50 img{
width: 100%;
height: 100%;
object-fit: contain;
}
/* .product-item__price p::after{
content: '₽';
padding-left: 5px;
}
} */
.product-item__bye{
margin-top: 8px;
}
@ -333,9 +371,9 @@
line-height: 111%;
text-transform: uppercase;
}
.detail-block-price__price::after{
/* .detail-block-price__price::after{
content: '₽';
}
} */
.detail-block-price__sale{
margin-left: 22px;
@ -351,9 +389,9 @@
text-decoration: line-through;
color: var(--text-6);
}
.detail-block-price-sale__text::after{
/* .detail-block-price-sale__text::after{
content: '₽';
}
} */
.detail-block-price-sale__perc{
margin-left: 9px;

@ -0,0 +1,286 @@
'use strict';
inputPhone('.form-input__phone', '.form-input-phone__icon', '.form-input-phone__code', '.form-input-phone__input', '.form-input-phone__list', 'form-input-phone-list__item', '.form-input-phone-list-item__icon', '.form-input-phone-list-item__code', 'form-input-phone-list__search');
function inputPhone(main, mainFlag, mainCode, input, list, selects, selectIcon, selectCode, searchInput) {
let inputs = document.querySelectorAll(main);
inputs.forEach(e => {
let thisMainFlag = e.querySelector(mainFlag),
thisMainCode = e.querySelector(mainCode),
thisInput = e.querySelector(input),
thisList = e.querySelector(list),
thisSelects = e.querySelectorAll(`.${selects}`),
thisSearchInput = e.querySelector(`.${searchInput}`);
thisInput.onblur = function (input) {
if (!(input.relatedTarget != null && (input.relatedTarget.classList.contains(searchInput) || input.relatedTarget.classList.contains(selects)))) {
thisList.classList.remove('active');
}
}
e.onclick = function (event) {
if (!event.target.classList.contains(searchInput)) {
if (thisList.classList.contains('active')) {
thisList.classList.remove('active');
}
thisInput.focus();
thisList.classList.add('active');
}
}
thisSelects.forEach(e => {
let newIcon = e.querySelector(selectIcon),
newCode = e.querySelector(selectCode);
e.onclick = function (event) {
event.preventDefault();
thisMainFlag.style.cssText = `background-image:url("${newIcon.src}");`;
thisMainCode.textContent = newCode.textContent;
setTimeout(() => {
thisList.classList.remove('active');
}, 0);
}
})
})
}
if (document.querySelector('.form-input-phone__input')) {
checkPhone('.form-input-phone__input');
}
function checkPhone(input) {
document.querySelector(input).addEventListener('input', function(event) {
let text = event.target.value;
let length = text.length;
let newSymbol = event.data;
if (!(/^\d+$/.test(text.replaceAll(' ', '')))) {
event.target.value = text.slice(0, -1);
return;
}
if (length == 4 || length == 8) {
if (newSymbol != null) {
event.target.value = text.slice(0, -1) + ' ' + newSymbol;
}
}
})
}
inputTabs('.form-input__tabs', '.form-input-tabs__button');
inputTabs('.modal-map__control', '.modal-map-control__item');
function inputTabs(main, button) {
let mains = document.querySelectorAll(main);
mains.forEach(main => {
let buttons = main.querySelectorAll(button);
buttons.forEach(button => {
button.onclick = function () {
if (button.classList.contains('active')) {
return ;
}
main.querySelector('.active').classList.remove('active');
button.classList.add('active');
if (button.querySelector('input')){
button.querySelector('input').click();
}
}
})
})
}
inputRadio('.form-input__radio', '.form-input-radio__item', '.form-input-radio__title', '.form-input-radio__input')
function inputRadio(main ,item, textClass, input) {
let inputRadios = document.querySelectorAll(main);
inputRadios.forEach(inputRadio => {
let items = inputRadio.querySelectorAll(item),
thisInput = inputRadio.querySelector(input);
items.forEach(radio => {
let thisText = radio.querySelector(textClass).textContent;
radio.onclick = function (event) {
event.preventDefault();
if (inputRadio.querySelector(`${item}.active`)) {
inputRadio.querySelector(`${item}.active`).classList.remove('active');
}
thisInput.value = thisText;
radio.classList.add('active');
}
})
})
}
listInputRadio('.form-input__list' ,'.form-input-list__item', '.form-input-list-item__text', '.form-input-list__input', '.form-input-list__content', '.form-input-list__block-content');
function listInputRadio(main ,item, textClass, input, content, block) {
let listInputRadios = document.querySelectorAll(main);
listInputRadios.forEach(listInputRadio => {
let thisInput = listInputRadio.querySelector(input),
items = listInputRadio.querySelectorAll(item),
thisContent = listInputRadio.querySelector(content),
thisBlock = listInputRadio.querySelector(block);
thisInput.onclick = function () {
thisBlock.classList.add('active');
thisBlock.style.height = '192px';
}
thisInput.onblur = function(){
thisBlock.classList.remove('active');
thisBlock.style.height = '0px';
};
items.forEach(item => {
item.onclick = function (event) {
event.preventDefault();
let newText = item.querySelector(textClass).textContent;
thisInput.value = newText;
if (thisContent.querySelector('.active')) {
thisContent.querySelector('.active').classList.remove('active');
}
item.classList.add('active');
}
})
})
}
remoteControl('.form-input__remote-control', '.form-input-tabs__button');
remoteControl('.modal-map__control', '.modal-map-control__item');
function remoteControl(main, button) {
let mains = document.querySelectorAll(main);
mains.forEach(main => {
let subjectClass = main.dataset.content,
subject = document.querySelector(`.${subjectClass}`),
buttons = Array.from(main.querySelectorAll(button));
main.addEventListener('click', function (eventMain) {
setTimeout(() => {
let indexActive = buttons.findIndex((button, index) => {
if (button.classList.contains('active')) {
return true;
}
});
if(subject.children[indexActive].classList.contains('active')){
return ;
}
subject.querySelector('.remote-control__item.active').classList.remove('active');
subject.children[indexActive].classList.add('active');
let mandatorys = subject.querySelectorAll('.mandatory');
mandatorys.forEach(mandatory => {
if (mandatory.required) {
mandatory.required = false;
}else{
mandatory.required = true;
}
})
}, 0);
})
})
}
formCheck('.modal-form__content', 'input[type=submit]');
formCheck('.modal-map__form', 'input[type=submit]');
function formCheck(form, submit) {
let forms = document.querySelectorAll(form);
forms.forEach(form => {
let thisSubmit = form.querySelector(submit);
thisSubmit.onclick = function () {
form.classList.add('check')
}
})
}
inputPhoneNoFlag('.no-flag');
function inputPhoneNoFlag(input){
let inputs = document.querySelectorAll(input);
inputs.forEach(input => {
let code = '+' + input.dataset.code;
input.onfocus = function () {
if (input.value == '') {
input.value = code;
}
}
input.addEventListener('input', function(event) {
let text = event.target.value;
let length = text.length;
let newSymbol = event.data;
if (isNaN(event.data) || event.data == ' ') {
event.target.value = text.slice(0, -1);
return;
}
if (length == 3 || length == 7 || length == 11) {
if (newSymbol != null) {
event.target.value = text.slice(0, -1) + ' ' + newSymbol;
}
}
})
})
}
inputCheck('.form-agreement__check');
function inputCheck(className) {
let checks = document.querySelectorAll(className);
checks.forEach(check => {
let square = check.querySelector('.form-agreement__square'),
input = check.querySelector('input');
square.onclick = function () {
input.click();
}
})
}
inputRead('.input-read');
function inputRead(className) {
let inputs = document.querySelectorAll(className);
inputs.forEach(input => {
input.addEventListener("input", function (event) {
let text = event.target.value;
event.target.value = text.slice(0, -1);
})
})
}

@ -0,0 +1,156 @@
'use strict';
// function
function modalOpen(buttonElement, contentElement){
let modal = document.querySelector('.modal'),
aside = document.querySelector('.modal__aside'),
elements = document.querySelectorAll(buttonElement),
device = window.screen.width;
elements.forEach(e => {
let thisContentElement = document.querySelector(contentElement);
e.onclick = function () {
modal.classList.add('active');
thisContentElement.classList.add('active');
let width = thisContentElement.clientWidth;
setTimeout(() => {
if (device <= 720) {
aside.style.width = `${device}px`;
thisContentElement.style.opacity = 1;
thisContentElement.style.filter = 'blur(0px)';
}else{
aside.style.width = `${width}px`;
thisContentElement.style.opacity = 1;
thisContentElement.style.filter = 'blur(0px)';
}
}, 10);
}
})
}
function modalClose(buttonElement) {
let modal = document.querySelector('.modal'),
aside = document.querySelector('.modal__aside'),
asideItems = document.querySelectorAll('.modal__item'),
elements = document.querySelectorAll(buttonElement);
elements.forEach(e => {
e.onclick = function () {
aside.style.width = '0px';
asideItems.forEach(e => {
if (e.classList.contains('active')) {
e.style.filter = 'blur(10px)';
}
});
setTimeout(() => {
asideItems.forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
}
});
modal.classList.remove('active');
}, 300);
}
})
}
function closeModalForm(close){
let buttons = document.querySelectorAll(close),
modal = document.querySelector('.modal');
buttons.forEach(button => {
button.onclick = function (buttonEvent) {
modal.classList.remove('active');
if (!modal.querySelector('.modal-map.active')) {
modal.querySelector('.modal-form.active').classList.remove('active');
}else{
modal.querySelector('.modal-map.active').classList.remove('active');
}
}
})
}
function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement, close) {
let elements = document.querySelectorAll(mainElement);
elements.forEach(e => {
let thisMainElement = e,
thisButtonElement = e.querySelector(buttonElement),
thisHeightElement = e.querySelector(heightElement),
thisContentElement = e.querySelector(contentElement);
thisButtonElement.onclick = function (e) {
let height = thisHeightElement.clientHeight;
if (close == true && !thisMainElement.classList.contains('active')) {
elements.forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
e.querySelector(contentElement).style.height = null
}
})
}
if (!thisMainElement.classList.contains('active')) {
thisContentElement.style.height = `${height}px`;
thisMainElement.classList.add('active');
}else{
thisContentElement.style.height = null;
thisMainElement.classList.remove('active');
}
}
});
}
function toggleHeader(button, content, blockheight, removeBlock, removeClass) {
let thisButton = document.querySelector(button),
thisContent = document.querySelector(content),
thisRemoveBlock = document.querySelector(removeBlock) || '',
thisBlockheight = document.querySelector(blockheight);
thisButton.onclick = function () {
let height = thisBlockheight.clientHeight;
if (!thisContent.classList .contains('open')) {
thisContent.style.height = `${height}px`;
thisContent.classList .add('open');
if (removeBlock) {
thisRemoveBlock.classList.remove(removeClass);
}
}else{
thisContent.style.height = null;
thisContent.classList .remove('open');
if (removeBlock) {
if (window.scrollY <= 25) {
thisRemoveBlock.classList.add(removeClass);
}
}
}
}
}
function modalFormOpen(formOrNotification) {
let buttons = document.querySelectorAll(formOrNotification),
modal = document.querySelector('.modal');
buttons.forEach(button => {
button.onclick = function (eventButton) {
let classOpenForm = button.dataset.form,
form = modal.querySelector(`.${classOpenForm}`);
form.classList.add('active');
modal.classList.add('active');
}
})
}
// function

@ -1,5 +1,6 @@
'use strict';
console.log('gp-main.js загружен');
// header
toggleOpenX('.lang', '.lang__open', '.lang__list', '.lang__content', false);
toggleHeader('#pc-menu','.header__menu-block','.header__pc-menu', '.white', 'white');
@ -12,20 +13,21 @@ modalOpen('.basket-open', '.modal__basket');
modalOpen('.open-to-know', '.modal__to-know');
modalClose('.modal__close');
let modal = document.querySelector('.modal');
let modalElement = document.querySelector('.modal');
modal.onclick = function (event) {
modalElement.onclick = function (event) {
let target = event.target;
console.log('Клик по modalElement', target);
if (target.classList.contains('modal')) {
let aside = target.querySelector('.modal__aside'),
modalItem = target.querySelector('.modal__item.active');
console.log('Закрытие модального окна');
aside.style.width = '0px';
setTimeout(() => {
modalItem.style.cssText = '';
modalItem.classList.remove('active');
target.classList.remove('active');
console.log('Модальное окно закрыто');
}, 300);
}
}
@ -36,33 +38,34 @@ modal.onclick = function (event) {
toggleOpenX('.toggle', '.toggle__title', '.toggle__content', '.toggle__block-content', true);
// toggle
// // radio-button
// let radioButtons = document.querySelectorAll('.radio-button');
// radio-button
let radioButtons = document.querySelectorAll('.radio-button');
// radioButtons.forEach(radioBlock => {
// let buttons = radioBlock.querySelectorAll('.button');
radioButtons.forEach(radioBlock => {
let buttons = radioBlock.querySelectorAll('.button');
// buttons.forEach(button => {
// let input = radioBlock.querySelector('.radio-button__input');
// button.onclick = function (e) {
// e.preventDefault();
buttons.forEach(button => {
let input = radioBlock.querySelector('.radio-button__input');
// buttons.forEach(thisButton => {
// if (thisButton.classList.contains('active')) {
// thisButton.classList.remove('active')
// }
// })
button.onclick = function (e) {
e.preventDefault();
console.log('Клик по radio-button', button.textContent.trim());
buttons.forEach(thisButton => {
if (thisButton.classList.contains('active')) {
thisButton.classList.remove('active')
}
})
// let text = button.textContent.trim();
let text = button.textContent.trim();
// button.classList.toggle('active');
button.classList.toggle('active');
// input.value = text;
// }
// })
// })
// // radio-button
input.value = text;
console.log('radio-button value:', input.value);
}
})
})
// radio-button
// overlay
let products = document.querySelectorAll('.product__item');
@ -74,6 +77,7 @@ products.forEach(productItem => {
if (button) {
button.onclick = function (e) {
console.log('Открытие overlay для товара', productItem);
document.querySelectorAll('.product__item').forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
@ -86,7 +90,8 @@ products.forEach(productItem => {
});
productItem.classList.toggle('active');
overlay.classList.toggle('active');
overlay.classList.toggle('active');
console.log('overlay toggled', overlay.classList.contains('active'));
}
}
@ -109,7 +114,7 @@ selects.forEach(select => {
e.onclick = function (event) {
event.preventDefault();
console.log('Клик по select', button.textContent.trim());
buttons.forEach(element => {
if (element.classList.contains('active')) {
element.classList.remove('active');
@ -122,6 +127,7 @@ selects.forEach(select => {
button.classList.add('active');
content.style.height = 0;
select.classList.remove('active');
console.log('select value:', state.value);
}
})
})
@ -137,21 +143,21 @@ counters.forEach(e => {
minus.onclick = function (e) {
e.preventDefault();
let number = input.value;
console.log('Клик по минусу', number);
if (number >= 2){
input.value = Number(number) - 1;
console.log('Новое значение counter:', input.value);
}
}
plus.onclick = function (e) {
e.preventDefault();
let number = input.value;
console.log('Клик по плюсу', number);
if (number <= 99) {
input.value = Number(number) + 1;
console.log('Новое значение counter:', input.value);
}
}
})
@ -163,13 +169,14 @@ let checkbox = document.querySelectorAll('.checkbox');
checkbox.forEach(e => {
e.onclick = function (event) {
let input = e.querySelector('.checkbox__input');
console.log('Клик по checkbox', input.checked);
if (!e.classList.contains('active')) {
input.checked = 1;
}else{
input.checked = 0;
}
e.classList.toggle('active');
console.log('checkbox теперь', input.checked);
}
})
// checkbox
@ -186,6 +193,7 @@ function modalOpen(buttonElement, contentElement){
let thisContentElement = document.querySelector(contentElement);
e.onclick = function () {
console.log('Открытие модального окна', contentElement);
modal.classList.add('active');
thisContentElement.classList.add('active');
@ -201,6 +209,7 @@ function modalOpen(buttonElement, contentElement){
thisContentElement.style.opacity = 1;
thisContentElement.style.filter = 'blur(0px)';
}
console.log('Модальное окно открыто', contentElement);
}, 10);
}
})
@ -213,7 +222,8 @@ function modalClose(buttonElement) {
elements = document.querySelectorAll(buttonElement);
elements.forEach(e => {
e.onclick = function () {
e.onclick = function () {
console.log('Закрытие модального окна через кнопку', buttonElement);
aside.style.width = '0px';
asideItems.forEach(e => {
@ -230,6 +240,7 @@ function modalClose(buttonElement) {
});
modal.classList.remove('active');
console.log('Модальное окно закрыто через кнопку', buttonElement);
}, 300);
}
})
@ -246,7 +257,7 @@ function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement,
thisButtonElement.onclick = function (e) {
let height = thisHeightElement.clientHeight;
console.log('toggleOpenX', mainElement, 'active:', thisMainElement.classList.contains('active'));
if (close == true && !thisMainElement.classList.contains('active')) {
elements.forEach(e => {
if (e.classList.contains('active')) {
@ -259,9 +270,11 @@ function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement,
if (!thisMainElement.classList.contains('active')) {
thisContentElement.style.height = `${height}px`;
thisMainElement.classList.add('active');
console.log('toggleOpenX открыт', mainElement);
}else{
thisContentElement.style.height = null;
thisMainElement.classList.remove('active');
console.log('toggleOpenX закрыт', mainElement);
}
}
@ -276,7 +289,7 @@ function toggleHeader(button, content, blockheight, removeBlock, removeClass) {
thisButton.onclick = function () {
let height = thisBlockheight.clientHeight;
console.log('toggleHeader', button, 'active:', thisContent.classList.contains('open'));
if (!thisContent.classList .contains('open')) {
thisContent.style.height = `${height}px`;
thisContent.classList .add('open');
@ -301,7 +314,7 @@ function toggleHeader(button, content, blockheight, removeBlock, removeClass) {
// resize
window.addEventListener('resize', (e) => {
let width = window.screen.width;
console.log('resize', width);
// media
modalOpen('.button--filter', '.modal__filter');
modalOpen('.basket-open', '.modal__basket');
@ -323,6 +336,7 @@ window.addEventListener('resize', (e) => {
aside.style.width = `${newWidth}px`
}
console.log('resize modal aside', aside.style.width);
}
})
// }
@ -336,7 +350,7 @@ if (document.querySelector('.header').classList.contains('white')) {
window.addEventListener("scroll", function (e) {
let header = document.querySelector('.header');
let scroll = window.scrollY;
console.log('scroll', scroll);
if (scroll >= 25) {
header.classList.remove('white')
}else{

@ -1,129 +0,0 @@
jQuery(document).ready(function($) {
// Инициализация слайдера для мобильной галереи
const mobileGallerySwiper = new Swiper('.detail__images-phone', {
slidesPerView: 1,
spaceBetween: 10,
pagination: {
el: '.swiper-pagination',
clickable: true
}
});
// Инициализация слайдера для полноэкранной галереи
const gallerySwiper = new Swiper('.gallery__slider', {
slidesPerView: 1,
spaceBetween: 10,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
el: '.swiper-pagination',
clickable: true
}
});
// Инициализация слайдера для рекомендованных товаров
const recommendedSwiper = new Swiper('.detail__catalot .detail-catalot__content', {
slidesPerView: 1,
spaceBetween: 20,
navigation: {
nextEl: '.detail-catalot__control .next',
prevEl: '.detail-catalot__control .prev',
},
breakpoints: {
768: {
slidesPerView: 2,
},
1024: {
slidesPerView: 3,
},
1280: {
slidesPerView: 4,
}
}
});
// Обработка переключения веса продукта
$('.detail-block-form__item--radio button').on('click', function(e) {
e.preventDefault();
const variationId = $(this).data('variation-id');
// Убираем активный класс у всех кнопок
$('.detail-block-form__item--radio button').removeClass('active');
// Добавляем активный класс текущей кнопке
$(this).addClass('active');
// Отправляем AJAX запрос для получения данных вариации
$.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
data: {
action: 'get_variation_data',
variation_id: variationId
},
success: function(response) {
if (response.success) {
// Обновляем цену
$('.detail-block-price__price').text(response.data.price);
// Обновляем скидку если есть
if (response.data.regular_price !== response.data.price) {
$('.detail-block-price__sale').html(`
<p class="detail-block-price-sale__text">${response.data.regular_price}</p>
<p class="detail-block-price-sale__perc">${response.data.discount_percentage}</p>
`);
} else {
$('.detail-block-price__sale').empty();
}
}
}
});
});
// Обработка открытия/закрытия аккордеона
$('.toggle__title').on('click', function() {
const content = $(this).next('.toggle__block-content');
const isOpen = content.is(':visible');
// Закрываем все открытые блоки
$('.toggle__block-content').slideUp();
// Если текущий блок был закрыт, открываем его
if (!isOpen) {
content.slideDown();
}
});
// Обработка открытия галереи
$('.detail__image').on('click', function() {
const imageIndex = $(this).data('count-img');
// Открываем галерею
$('.gallery').addClass('active');
// Устанавливаем активный слайд
gallerySwiper.slideTo(imageIndex);
// Добавляем активный класс соответствующей миниатюре
$('.gallery-pagination__item').removeClass('active');
$(`.gallery-pagination__item[data-count-img="${imageIndex}"]`).addClass('active');
});
// Обработка закрытия галереи
$('.gallery__close').on('click', function() {
$('.gallery').removeClass('active');
});
// Обработка клика по миниатюрам в галерее
$('.gallery-pagination__item').on('click', function() {
const imageIndex = $(this).data('count-img');
// Переключаем слайд
gallerySwiper.slideTo(imageIndex);
// Обновляем активную миниатюру
$('.gallery-pagination__item').removeClass('active');
$(this).addClass('active');
});
});

@ -64,4 +64,3 @@ class TabsCollection {
}
}
export default TabsCollection;

@ -86,4 +86,3 @@ class TogglesCollection{
}
}
export default TogglesCollection;

@ -75,16 +75,16 @@
<div class="detail__block-price">
<p class="detail-block-price__price">
{{ product.get_price }}
{{ product.get_price }} {{ fn('get_woocommerce_currency_symbol') }}
</p>
{% if product.is_on_sale() %}
<div class="detail-block-price__sale">
<p class="detail-block-price-sale__text">
{{ product.get_regular_price }}
{{ product.get_regular_price }} {{ fn('get_woocommerce_currency_symbol') }}
</p>
<p class="detail-block-price-sale__perc">
{{ ((product.get_regular_price - product.get_price) / product.get_regular_price * 100)|round }}
{{ ((product.get_regular_price - product.get_price) / product.get_regular_price * 100)|round }} {{ fn('get_woocommerce_currency_symbol') }}
</p>
</div>
{% endif %}
@ -111,8 +111,9 @@
<div class="detail-block-form__items">
<input type="submit" value="{{ function('pll_e', 'Добавить в корзину') }}" class="button button--gradient button--high detail-block-form__submit">
</div>
<a href="?add-to-cart={{ product.id }}" class="button button--gradient button--high add_to_cart_button ajax_add_to_cart" data-product_id="{{ product.id }}" data-quantity="1">
{{ function('pll_e', 'Добавить в корзину') }}
</a> </div>
</form>
<div class="detail__toggle">
@ -312,7 +313,7 @@
</div>
<a href="{{ wc_product.get_permalink() }}" class="product-item__title">{{ wc_product.get_name() }}</a>
<div class="product-item__price">
<p>{{ wc_product.get_price() }}</p>
<p>{{ wc_product.get_price() }} {{ fn('get_woocommerce_currency_symbol') }}</p>
</div>
<div class="product-item__bye">
<button class="button button--white button--100-perc open-overlay">

@ -29,9 +29,9 @@
<a href="/compound/{{ term.slug }}" class="compound__item">{{ term.name }}</a>
{% endfor %}
</div>
<a href="#" class="product-item__title">{{ post.title }}</a>
<a href="{{ post.link }}" class="product-item__title">{{ post.title }}</a>
<div class="product-item__price">
<p>{{ post._price() }}</p>
<p>{{ post._price() }} {{ fn('get_woocommerce_currency_symbol') }}</p>
</div>
<div class="product-item__bye">
<button class="button button--white button--100-perc open-overlay">
@ -41,7 +41,8 @@
</div>
<div class="product-item__overlay">
<div class="product-item-overlay__header">
<a href="#" class="product-item__title">{{ post.title }}</a>
<a href="{{ post.link }}" class="product-item__title">{{ post.title }}</a>
<ul class="product-item-overlay__tags">
{% set features = fn('wc_get_product_terms', post.id, 'pa_features') %}
{% for option in features %}

@ -547,10 +547,10 @@ main{
text-transform: uppercase;
color: var(--text-black);
}
.product-item__price p::after{
/* .product-item__price p::after{
content: '₽';
padding-left: 5px;
}
} */
.product-item__price span{
margin-left: 9px;
font-family: var(--font-family);

@ -29,6 +29,10 @@ jQuery(document).ready(function ($) {
evt.preventDefault();
let product = $(this).closest('.product__item');
let price = parseFloat(product.find('.select__state').data('product_price'));
if (!price || isNaN(price)) {
let priceText = product.find('.product-item__price p').text();
price = parseFloat(priceText.replace(/[^0-9\.,]/g, '').replace(',', '.'));
}
let qty = product.find('.counter__input');
if ($(this).hasClass('minus') && parseInt(qty.val()) >= 2) {
@ -39,7 +43,8 @@ jQuery(document).ready(function ($) {
}
}
product.find('.product-item-overlay__price').html(price * qty.val() + ' ');
product.find('.product-item-overlay__button a').attr('data-quantity', qty.val())
product.find('.product-item-overlay__price').html((price * qty.val()) + ' ');
})
$('.product__main').on('click', '.select__state', function(evt) {
@ -190,34 +195,34 @@ radioButtons.forEach(radioBlock => {
})
// radio-button
// overlay
// let products = document.querySelectorAll('.product__item');
overlay
let products = document.querySelectorAll('.product__item');
// products.forEach(productItem => {
// let button = productItem.querySelector('.open-overlay'),
// overlay = productItem.querySelector('.product-item__overlay');
products.forEach(productItem => {
let button = productItem.querySelector('.open-overlay'),
overlay = productItem.querySelector('.product-item__overlay');
// if (button) {
// button.onclick = function (e) {
// document.querySelectorAll('.product__item').forEach(e => {
// if (e.classList.contains('active')) {
// e.classList.remove('active');
// }
// });
// document.querySelectorAll('.product-item__overlay').forEach(e => {
// if (e.classList.contains('active')) {
// e.classList.remove('active');
// }
// });
if (button) {
button.onclick = function (e) {
document.querySelectorAll('.product__item').forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
}
});
document.querySelectorAll('.product-item__overlay').forEach(e => {
if (e.classList.contains('active')) {
e.classList.remove('active');
}
});
// productItem.classList.toggle('active');
// overlay.classList.toggle('active');
// }
// }
productItem.classList.toggle('active');
overlay.classList.toggle('active');
}
}
// })
// overlay
})
overlay
// select
@ -478,3 +483,5 @@ if (document.querySelector('.header').classList.contains('white')) {
});
}
// scroll

Loading…
Cancel
Save