/var/www/qr4y.com/server/delivery/api/controllers/qr/script
NameSizeModeActions
menu.js62340644editdlrm
Edit: /var/www/qr4y.com/server/delivery/api/controllers/qr/script/menu.js (6234B)
// Прокрутка к секции по клику на пункт меню document.addEventListener('DOMContentLoaded', function () { // После показа productDetails: function adjustProductImage() { const img = document.querySelector('.product-details .menu-header'); if (!img) return; // Создаём временное изображение для определения размеров const url = img.style.backgroundImage.replace(/^url\(["']?/, '').replace(/["']?\)$/, ''); const tempImg = new window.Image(); tempImg.onload = function () { if (this.naturalWidth > this.naturalHeight) { // Горизонтальное — cover img.style.backgroundSize = 'cover'; } else { // Вертикальное — contain img.style.backgroundSize = 'contain'; } }; tempImg.src = url; } const links = document.querySelectorAll('.group-menu-link'); links.forEach(link => { link.addEventListener('click', function (e) { e.preventDefault(); const id = this.getAttribute('href').substring(1); const section = document.getElementById(id); if (section) { const y = section.getBoundingClientRect().top + window.pageYOffset - document.getElementById('groupMenu').offsetHeight; window.scrollTo({ top: y, behavior: 'smooth' }); } }); }); // Подсветка активной группы при скролле const sections = Array.from(document.querySelectorAll('.group-section')); const menuLinks = Array.from(document.querySelectorAll('.group-menu-link')); function onScroll() { let current = 0; const scrollY = window.scrollY + document.getElementById('groupMenu').offsetHeight + 10; sections.forEach((section, idx) => { if (section.offsetTop <= scrollY) { current = idx; } }); menuLinks.forEach((link, idx) => { if (idx === current) { link.classList.add('active'); } else { link.classList.remove('active'); } }); } window.addEventListener('scroll', onScroll, { passive: true }); onScroll(); // Модальное окно для карточки товара // const modalHtml = \` // // \`; // document.body.insertAdjacentHTML('beforeend', modalHtml); // const modal = document.getElementById('productModal'); // const modalBody = document.getElementById('productModalBody'); // document.getElementById('productModalClose').onclick = () => modal.style.display = 'none'; // Открытие модального окна по клику на товар document.querySelectorAll('.product-card').forEach(card => { card.addEventListener('click', function () { const productData = JSON.parse(decodeURIComponent(this.getAttribute('data-product'))); const mainView = document.getElementById('mainView'); const details = document.getElementById('productDetails'); // Сохраняем текущую прокрутку window._menuScrollY = window.scrollY; details.innerHTML = '' +'' +'
' +'

'+ productData.name + '

' +'

' + productData.price + ' ' + productData.currency + '

' +'

'+ productData.description + '

' +'
' // +'' + productData.name
                // + '' // + '

'+ productData.name + '

' // + '

'+ productData.price + ' '+ productData.currency + '

' // + '

'+ productData.description + '

'; details.style.display = 'block'; mainView.style.display = 'none'; details.scrollIntoView({ behavior: 'smooth', block: 'center' }); // Кнопка назад document.getElementById('backToMenuBtn').onclick = function() { details.style.display = 'none'; document.getElementById('mainView').style.display = ''; // Восстанавливаем прокрутку if (typeof window._menuScrollY === 'number') { window.scrollTo({ top: window._menuScrollY, behavior: 'auto' }); } }; setTimeout(adjustProductImage, 0); }); }); // Закрытие по клику вне окна // modal.addEventListener('click', function(e) { // if (e.target === modal) modal.style.display = 'none'; // }); });