|
|
|
@ -4,7 +4,7 @@ document.addEventListener("DOMContentLoaded", (event) => { |
|
|
|
|
|
|
|
|
|
Fancybox.bind("[data-fancybox]"); |
|
|
|
|
|
|
|
|
|
document.body.addEventListener('submit', function(e) { |
|
|
|
|
document.body.addEventListener('submit', function (e) { |
|
|
|
|
const form = e.target; |
|
|
|
|
if (form.matches('.add-to-cart-form')) { |
|
|
|
|
e.preventDefault(); |
|
|
|
@ -14,7 +14,7 @@ document.addEventListener("DOMContentLoaded", (event) => { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
cartForm?.addEventListener('submit', function(e) { |
|
|
|
|
cartForm?.addEventListener('submit', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopImmediatePropagation(); |
|
|
|
|
|
|
|
|
@ -25,7 +25,7 @@ document.addEventListener("DOMContentLoaded", (event) => { |
|
|
|
|
|
|
|
|
|
function cartCheckout(formElement) { |
|
|
|
|
|
|
|
|
|
if(!formElement) return; |
|
|
|
|
if (!formElement) return; |
|
|
|
|
|
|
|
|
|
const formData = new FormData(formElement); |
|
|
|
|
const submitButton = formElement.querySelector('button[type=submit]'); |
|
|
|
@ -47,7 +47,8 @@ function addToCart(formElement) { |
|
|
|
|
submitButton.classList.add('is-loading'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fetch(window.location.href, { |
|
|
|
|
fetch(formElement.getAttribute('action'), { // чтоб работало по action формы
|
|
|
|
|
// fetch(window.location.href, {
|
|
|
|
|
method: 'POST', |
|
|
|
|
body: formData |
|
|
|
|
}) |
|
|
|
@ -192,7 +193,7 @@ function updateHistoryUI(history, containerId, inputId) { |
|
|
|
|
}); |
|
|
|
|
// Повторить поиск по истории
|
|
|
|
|
container.querySelectorAll('.header__search-btn--again').forEach(btn => { |
|
|
|
|
btn.addEventListener('click', function(e) { |
|
|
|
|
btn.addEventListener('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
const val = this.getAttribute('data-value'); |
|
|
|
|
const input = document.getElementById(inputId); |
|
|
|
@ -201,7 +202,7 @@ function updateHistoryUI(history, containerId, inputId) { |
|
|
|
|
}); |
|
|
|
|
// Удалить элемент истории
|
|
|
|
|
container.querySelectorAll('.header__search-btn--remove').forEach(btn => { |
|
|
|
|
btn.addEventListener('click', function(e) { |
|
|
|
|
btn.addEventListener('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
const idx = +this.getAttribute('data-idx'); |
|
|
|
|
history.splice(idx, 1); |
|
|
|
@ -223,12 +224,12 @@ function setupSearchHistory(formId, inputId, containerId, clearBtnId) { |
|
|
|
|
const clearBtn = document.getElementById(clearBtnId); |
|
|
|
|
|
|
|
|
|
if (form && input) { |
|
|
|
|
form.addEventListener('submit', function(e) { |
|
|
|
|
form.addEventListener('submit', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
const val = input.value.trim(); |
|
|
|
|
if (!val) return; |
|
|
|
|
// Не дублируем подряд одинаковые
|
|
|
|
|
if (!history.length || history[history.length-1] !== val) { |
|
|
|
|
if (!history.length || history[history.length - 1] !== val) { |
|
|
|
|
history.push(val); |
|
|
|
|
if (history.length > 10) history = history.slice(-10); // максимум 10
|
|
|
|
|
setCookie(containerId, JSON.stringify(history)); |
|
|
|
@ -239,7 +240,7 @@ function setupSearchHistory(formId, inputId, containerId, clearBtnId) { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if (clearBtn) { |
|
|
|
|
clearBtn.addEventListener('click', function(e) { |
|
|
|
|
clearBtn.addEventListener('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
history = []; |
|
|
|
|
setCookie(containerId, JSON.stringify(history)); |
|
|
|
@ -277,7 +278,7 @@ function ajaxSearch(inputId, blockId, historyBlockId) { |
|
|
|
|
const input = document.getElementById(inputId); |
|
|
|
|
const historyBlock = document.getElementById(historyBlockId); |
|
|
|
|
if (!input) return; |
|
|
|
|
input.addEventListener('input', function() { |
|
|
|
|
input.addEventListener('input', function () { |
|
|
|
|
const val = input.value.trim(); |
|
|
|
|
clearSearchResults(blockId); |
|
|
|
|
if (historyBlock) { |
|
|
|
@ -298,7 +299,7 @@ function ajaxSearch(inputId, blockId, historyBlockId) { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
// Скрывать результаты при потере фокуса
|
|
|
|
|
input.addEventListener('blur', function() { |
|
|
|
|
input.addEventListener('blur', function () { |
|
|
|
|
setTimeout(() => clearSearchResults(blockId), 200); |
|
|
|
|
if (historyBlock && input.value.trim().length === 0) { |
|
|
|
|
historyBlock.style.display = ''; |
|
|
|
@ -310,10 +311,10 @@ function setupSearchBlockFocus(inputId, blockId) { |
|
|
|
|
const input = document.getElementById(inputId); |
|
|
|
|
const block = document.getElementById(blockId); |
|
|
|
|
if (!input || !block) return; |
|
|
|
|
input.addEventListener('focus', function() { |
|
|
|
|
input.addEventListener('focus', function () { |
|
|
|
|
block.classList.add('active'); |
|
|
|
|
}); |
|
|
|
|
input.addEventListener('blur', function() { |
|
|
|
|
input.addEventListener('blur', function () { |
|
|
|
|
setTimeout(() => block.classList.remove('active'), 200); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -323,7 +324,7 @@ function toggleSearchTopAndHistory(inputId, topId, historiesId) { |
|
|
|
|
const top = document.getElementById(topId); |
|
|
|
|
const histories = document.getElementById(historiesId); |
|
|
|
|
if (!input || !top || !histories) return; |
|
|
|
|
input.addEventListener('input', function() { |
|
|
|
|
input.addEventListener('input', function () { |
|
|
|
|
if (input.value.trim().length > 0) { |
|
|
|
|
top.style.display = 'none'; |
|
|
|
|
histories.style.display = 'none'; |
|
|
|
@ -332,7 +333,7 @@ function toggleSearchTopAndHistory(inputId, topId, historiesId) { |
|
|
|
|
histories.style.display = ''; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
input.addEventListener('blur', function() { |
|
|
|
|
input.addEventListener('blur', function () { |
|
|
|
|
if (input.value.trim().length === 0) { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
top.style.display = ''; |
|
|
|
@ -347,7 +348,7 @@ function addToHistory(query, containerId, inputId) { |
|
|
|
|
try { |
|
|
|
|
history = JSON.parse(getCookie(containerId) || '[]'); |
|
|
|
|
} catch (e) { history = []; } |
|
|
|
|
if (!history.length || history[history.length-1] !== query) { |
|
|
|
|
if (!history.length || history[history.length - 1] !== query) { |
|
|
|
|
history.push(query); |
|
|
|
|
if (history.length > 10) history = history.slice(-10); |
|
|
|
|
setCookie(containerId, JSON.stringify(history)); |
|
|
|
@ -356,7 +357,7 @@ function addToHistory(query, containerId, inputId) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function setupResultClickToHistory(inputId, containerId) { |
|
|
|
|
document.addEventListener('click', function(e) { |
|
|
|
|
document.addEventListener('click', function (e) { |
|
|
|
|
const target = e.target.closest('.search-result-item'); |
|
|
|
|
if (target) { |
|
|
|
|
const input = document.getElementById(inputId); |
|
|
|
@ -370,7 +371,7 @@ function setupResultClickToHistory(inputId, containerId) { |
|
|
|
|
}, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
document.addEventListener('DOMContentLoaded', function () { |
|
|
|
|
setupSearchHistory('header-search-form', 'header-search-input', 'header-search-histories', 'header-search-clear'); |
|
|
|
|
setupSearchHistory('mobile-search-form', 'mobile-search-input', 'mobile-search-histories', 'mobile-search-clear'); |
|
|
|
|
ajaxSearch('header-search-input', 'header-search-history-block', 'header-search-histories'); |
|
|
|
@ -384,6 +385,11 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Открытие попапа для local/components/era/calculator/templates/.default/ajax.php
|
|
|
|
|
function openCartPopupForProduct(productName) { |
|
|
|
|
document.querySelector('.cart-popup__wrapper').classList.remove('cart-popup__wrapper--hidden'); |
|
|
|
|
document.getElementById('fast_product').value = productName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// From main.js
|
|
|
|
|