This commit is contained in:
2026-04-06 18:44:02 +05:00
commit d775fbb9ba
431 changed files with 31234 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
// Универсальный AJAX для добавления в корзину
document.addEventListener('DOMContentLoaded', function () {
const cartForms = document.querySelectorAll('form[action*="cart/add"]');
cartForms.forEach(form => {
form.addEventListener('submit', async function (e) {
e.preventDefault();
const submitBtn = this.querySelector('button[type="submit"]');
if (!submitBtn) return;
const originalText = submitBtn.textContent;
submitBtn.disabled = true;
submitBtn.textContent = 'Добавление...';
// Получаем данные формы
const variationId = this.querySelector('input[name="variation_id"]')?.value;
const quantity = this.querySelector('input[name="quantity"]')?.value || 1;
try {
const response = await fetch(this.action, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({
variation_id: variationId,
quantity: quantity
})
});
// Проверяем, что ответ JSON
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
throw new Error('Сервер вернул HTML вместо JSON');
}
const data = await response.json();
if (data.success) {
// Обновляем счетчик корзины
const cartCountElements = document.querySelectorAll('.cart-count');
cartCountElements.forEach(el => {
el.textContent = data.cart_count;
el.classList.add('cart-bump');
setTimeout(() => el.classList.remove('cart-bump'), 300);
});
submitBtn.textContent = '✓ Добавлено';
showNotification(data.message, 'success');
setTimeout(() => {
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}, 1500);
} else {
showNotification(data.message || 'Ошибка', 'error');
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}
} catch (error) {
console.error('Error:', error);
showNotification('Ошибка при добавлении в корзину', 'error');
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}
});
});
function showNotification(message, type = 'success') {
const oldNotification = document.querySelector('.notification');
if (oldNotification) oldNotification.remove();
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: ${type === 'success' ? '#2c5e2e' : '#dc3545'};
color: white;
padding: 12px 24px;
border-radius: 8px;
z-index: 9999;
animation: slideIn 0.3s ease;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
// Добавляем CSS анимации
if (!document.querySelector('#cart-animations')) {
const style = document.createElement('style');
style.id = 'cart-animations';
style.textContent = `
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(100%); opacity: 0; }
}
@keyframes cartBump {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.cart-bump {
animation: cartBump 0.3s ease;
display: inline-block;
}
`;
document.head.appendChild(style);
}
});

View File

@@ -0,0 +1,78 @@
document.addEventListener('DOMContentLoaded', function () {
const searchInput = document.getElementById('input_search');
let searchTimeout;
if (searchInput) {
let suggestionsContainer = document.createElement('div');
suggestionsContainer.className = 'search-suggestions';
suggestionsContainer.style.cssText = `
position: absolute;
top: 100%;
left: 0;
right: 0;
background: white;
border: 1px solid #ddd;
border-radius: 8px;
max-height: 400px;
overflow-y: auto;
z-index: 1000;
display: none;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
`;
searchInput.parentNode.style.position = 'relative';
searchInput.parentNode.appendChild(suggestionsContainer);
searchInput.addEventListener('input', function () {
clearTimeout(searchTimeout);
const query = this.value.trim();
if (query.length < 2) {
suggestionsContainer.style.display = 'none';
return;
}
searchTimeout = setTimeout(() => {
fetch(`/search/ajax?q=${encodeURIComponent(query)}`)
.then(response => response.json())
.then(data => {
if (data.products.length > 0 || data.brands.length > 0) {
let html = '';
if (data.brands.length > 0) {
html += '<div class="p-2 bg-light fw-semibold">Бренды</div>';
data.brands.forEach(brand => {
html += `
<a href="/brands/${brand.slug}" class="d-block p-2 text-decoration-none text-dark hover-bg-light">
<i class="bi bi-building me-2"></i> ${brand.name}
</a>
`;
});
}
if (data.products.length > 0) {
html += '<div class="p-2 bg-light fw-semibold">Товары</div>';
data.products.forEach(product => {
html += `
<a href="/product/${product.slug}" class="d-block p-2 text-decoration-none text-dark hover-bg-light">
<i class="bi bi-box me-2"></i> ${product.name}
</a>
`;
});
}
suggestionsContainer.innerHTML = html;
suggestionsContainer.style.display = 'block';
} else {
suggestionsContainer.style.display = 'none';
}
});
}, 300);
});
document.addEventListener('click', function (e) {
if (!searchInput.parentNode.contains(e.target)) {
suggestionsContainer.style.display = 'none';
}
});
}
});

View File

@@ -0,0 +1,9 @@
function insertCurrentYear() {
const elements = document.querySelectorAll('.current-year');
const currentYear = new Date().getFullYear();
elements.forEach(element => {
element.textContent = currentYear;
});
}
insertCurrentYear();

2
public/assets/js/jquery-3.7.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
/*
jQuery Masked Input Plugin
Copyright (c) 2007 - 2015 Josh Bush (digitalbush.com)
Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
Version: 1.4.1
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a<g.placeholder.length?a:0)}function q(a){for(;++a<n&&!j[a];);return a}function r(a){for(;--a>=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(o&&o.length&&o.length>a.length){for(A(!0);b.begin>0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.begin<l&&!j[b.begin];)b.begin++;B.caret(b.begin,b.begin)}else{for(A(!0);b.begin<n&&!j[b.begin];)b.begin++;B.caret(b.begin,b.begin)}h()}function v(){A(),B.val()!=E&&B.change()}function w(a){if(!B.prop("readonly")){var b,c,e,f=a.which||a.keyCode;o=B.val(),8===f||46===f||d&&127===f?(b=B.caret(),c=b.begin,e=b.end,e-c===0&&(c=46!==f?r(c):e=q(c-1),e=46===f?q(e):e),y(c,e),s(c,e-1),a.preventDefault()):13===f?v.call(this,a):27===f&&(B.val(E),B.caret(0,A()),a.preventDefault())}}function x(b){if(!B.prop("readonly")){var c,d,e,g=b.which||b.keyCode,i=B.caret();if(!(b.ctrlKey||b.altKey||b.metaKey||32>g)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++<e.length;)if(c=e.charAt(d-1),j[b].test(c)){C[b]=c,f=b;break}if(d>e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){B.get(0)===document.activeElement&&(z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a))},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})});

1
public/assets/js/nouislider.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
$(document).ready(function() {
$('#phone-mask').mask('+7(999)-999-99-99');
});

View File

@@ -0,0 +1,8 @@
function updateCartCount(count) {
const cartCountElements = document.querySelectorAll('.cart-count');
cartCountElements.forEach(el => {
el.textContent = count;
el.classList.add('cart-bump');
setTimeout(() => el.classList.remove('cart-bump'), 300);
});
}