/
var
/
www
/
qr4y.com
/
server
/
delivery
/
api
/
controllers
/
qr
/
script
/
/var/www/qr4y.com/server/delivery/api/controllers/qr/script
mkdir
upload
Name
Size
Mode
Actions
menu.js
6234
0644
edit
dl
rm
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 = \` // <div id="productModal" style="display:none;position:fixed;z-index:9999;left:0;top:0;width:100vw;height:100vh;background:rgba(0,0,0,0.35);align-items:center;justify-content:center;"> // <div id="productModalContent" style="background:#fff;border-radius:16px;max-width:95vw;width:400px;box-shadow:0 8px 32px rgba(0,0,0,0.18);padding:24px 18px 18px 18px;position:relative;"> // <button id="productModalClose" style="position:absolute;top:10px;right:14px;background:none;border:none;font-size:1.8rem;line-height:1;color:#888;cursor:pointer;">×</button> // <div id="productModalBody"></div> // </div> // </div> // \`; // 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 = '<button id="backToMenuBtn" class="back-fab" aria-label="Назад к меню">' + '<svg width="28" height="28" viewBox="0 0 28 28" fill="none">' +'<polyline points="18,6 10,14 18,22" fill="none" stroke="#F1A815" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>' +'</svg>' +'</button>' +'<div class="menu-header" style="background: url(' + productData.imgFull + ') center/contain no-repeat;"></div>' +'<div class="product-title">' +'<h1 class="menu-header-h1">'+ productData.name + '</h1>' +'<p class="product-price">' + productData.price + ' ' + productData.currency + '</p>' +'<p class="product-desc">'+ productData.description + '</p>' +'</div>' // +'<img src="' + productData.imgFull // + '" alt="' + productData.name // + '" style="width:100%;height:220px;object-fit:contain;border-radius:12px;margin-bottom:18px;">' // + '<h2>'+ productData.name + '</h2>' // + '<p>'+ productData.price + ' '+ productData.currency + '</p>' // + '<p>'+ productData.description + '</p>'; 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'; // }); });
Save
cmd:
run