Advertisement
oscarviedma

vCardRestaurant-Codigo-Corregido-EUROS

Mar 29th, 2025
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 23.50 KB | None | 0 0
  1. <div id="preloader" class="loadingio-spinner-rolling-zt8qwybayi">
  2.   <div class="ldio-pk6mhbe1fco">
  3.     <div></div>
  4.   </div>
  5. </div>
  6.  
  7. <section id="ov-listado-menu">
  8. <!-- Aquí es donde se cargará el contenido dinámico -->
  9. </section>
  10.  
  11. <script>
  12.   // Función para actualizar la pestaña activa y hacer scroll horizontal según la posición de scroll
  13.   function updateActiveTab() {
  14.     var tabLinks = document.querySelectorAll('#tabs a');
  15.     var sections = document.querySelectorAll('.titulo-seccion');
  16.     var scrollPosition = document.querySelector('.contenido').scrollTop;
  17.     var offset = -50;
  18.     sections.forEach(function(section, index) {
  19.       var sectionTop = section.offsetTop;
  20.       var sectionHeight = section.offsetHeight;
  21.       if (scrollPosition >= sectionTop - offset && scrollPosition < sectionTop + sectionHeight - offset) {
  22.        tabLinks.forEach(function(link) {
  23.          link.classList.remove('active');
  24.         });
  25.         tabLinks[index].classList.add('active');
  26.         // Hacer scroll horizontal para mostrar la pestaña activa
  27.         var tabsContainer = document.getElementById('tabs');
  28.         var activeTab = tabLinks[index];
  29.         var tabLeft = activeTab.offsetLeft;
  30.         var tabWidth = activeTab.offsetWidth;
  31.         var tabsWidth = tabsContainer.offsetWidth;
  32.         var tabsScrollLeft = tabsContainer.scrollLeft;
  33.         if (tabLeft < tabsScrollLeft) {
  34.          tabsContainer.scrollTo({
  35.            left: tabLeft,
  36.            behavior: 'smooth'
  37.          });
  38.        } else if (tabLeft + tabWidth > tabsScrollLeft + tabsWidth) {
  39.           tabsContainer.scrollTo({
  40.             left: tabLeft + tabWidth - tabsWidth,
  41.             behavior: 'smooth'
  42.           });
  43.         }
  44.       }
  45.     });
  46.   }
  47.  
  48.   // Función para mostrar el precargador
  49.   function showPreloader() {
  50.     document.getElementById('preloader').style.display = 'block';
  51.     document.getElementById('ov-listado-menu').style.display = 'none';
  52.   }
  53.  
  54.   // Función para ocultar el precargador y mostrar el contenido
  55.   function hidePreloader() {
  56.     document.getElementById('preloader').style.display = 'none';
  57.     document.getElementById('ov-listado-menu').style.display = 'block';
  58.   }
  59.  
  60.   // Mostrar el precargador al cargar la página
  61.   showPreloader();
  62.  
  63.   var cartItems = [];
  64.     var currency = "EUR"; // CAMBIAR MONEDA
  65.     var currencySymbol = ""; // CAMBIAR SIMBOLO MONEDA
  66.  
  67.     var appScriptUrl = 'https://script.google.com/macros/s/AKfycbxjEq46zgfhLEPmBZWp21r9cH6wLp7tFcdykYh7e8-YGTQ9cUmRv7WybmjNl-7pufjszg/exec'; // INSERTAR URL APPSCRIPT
  68.     var whatsappNumber = '+34636593115'; // INSERTAR NÚMERO WHATSAPP CON PREFIJO DE PAÍS
  69.  
  70.     // Función para generar el HTML del menú
  71.     function generateMenuHTML(menuData) {
  72.       var html = '';
  73.       var tabs = '';
  74.  
  75.       for (var section in menuData) {
  76.         var sectionId = section.toLowerCase().replace(/\s+/g, '-');
  77.         tabs += '<a href="#' + sectionId + '">' + section + '</a>\n';
  78.         html += '<h2 id="' + sectionId + '" class="titulo-seccion">' + section + '</h2>';
  79.  
  80.         menuData[section].forEach(function(dish) {
  81.           // Asegúrate de que el precio se maneje como un número
  82.           var price = parseFloat(dish.price);
  83.           html += '<div class="card-menu" data-dish="' + encodeURIComponent(JSON.stringify({ ...dish, price: price })) + '">' +
  84.             '<div class="img-cover">' +
  85.               '<img src="' + dish.image + '" alt="' + dish.name + '">' +
  86.             '</div>' +
  87.             '<div class="info-menu">' +
  88.               '<h3 class="titulo">' + dish.name + '</h3>' +
  89.               '<p class="descripcion">' + dish.description + '</p>' +  
  90.               '<p class="menu-precio">' + currencySymbol + price.toFixed(2) + ' ' + currency + '</p>' +
  91.             '</div>' +
  92.           '</div>';
  93.         });
  94.       }
  95.  
  96.       // Insertar las pestañas en el contenedor de pestañas
  97.       document.getElementById('tabs').innerHTML = tabs;
  98.  
  99.       return html;
  100.     }
  101.  
  102.     // Función para generar el HTML de las opciones extras
  103.     function generateOptionsHTML(options) {
  104.       var html = '';
  105.  
  106.       for (var optionTitle in options) {
  107.         html += '<div class="option-group">';
  108.         html += '<h4>' + optionTitle + '</h4>';
  109.  
  110.         options[optionTitle].forEach(function(option) {
  111.           var optionName = option.name;
  112.           var optionPrice = option.price;
  113.  
  114.           html += '<div class="option-item">';
  115.           html += '<input type="checkbox" id="' + optionName + '" value="' + optionPrice + '">';
  116.           html += '<label for="' + optionName + '">' + optionName + (optionPrice ? ' ' + currencySymbol + optionPrice : '') + '</label>';
  117.           html += '</div>';
  118.         });
  119.  
  120.         html += '</div>';
  121.       }
  122.  
  123.       return html;
  124.     }
  125.  
  126.     // Función para abrir el pop-up de detalles del producto
  127.     function openPopup(dish) {
  128.       var price = parseFloat(dish.price);
  129.       var popupHtml = '<div class="popup">' +
  130.         '<div class="popup-content">' +
  131.           '<div class="popup-left">' +
  132.             '<img src="' + dish.image + '" alt="' + dish.name + '">' +
  133.           '</div>' +
  134.           '<div class="popup-right">' +
  135.             '<div class="popup-content-wrapper">' +
  136.               '<h3>' + dish.name + '</h3>' +
  137.               '<p>' + dish.description + '</p>' +
  138.               '<div class="options-container">' + generateOptionsHTML(dish.options) + '</div>' +
  139.             '</div>' +
  140.             '<div class="quantity-control-container">' +
  141.               '<div class="quantity-control">' +
  142.                 '<button class="decrement-quantity">-</button>' +
  143.                 '<input type="text" class="quantity" value="1" data-price="' + price + '">' +
  144.                 '<button class="increment-quantity">+</button>' +
  145.               '</div>' +
  146.               '<button class="agregar-al-carrito" data-dish="' + encodeURIComponent(JSON.stringify({...dish, price: price})) + '">Agregar <span class="precio">' + currencySymbol + price.toFixed(2) + ' ' + currency + '</span></button>' +
  147.             '</div>' +
  148.           '</div>' +
  149.           '<i class="fas fa-times icono-cerrar"></i>' +
  150.         '</div>' +
  151.       '</div>';
  152.       document.body.insertAdjacentHTML('beforeend', popupHtml);
  153.       setTimeout(function() {
  154.         document.querySelector('.popup').classList.add('show');
  155.       }, 50);
  156.  
  157.       document.querySelectorAll('.option-item input[type="checkbox"], .quantity').forEach(input => {
  158.         input.addEventListener('change', updatePopupPrice);
  159.       });
  160.  
  161.       document.querySelector('.agregar-al-carrito').addEventListener('click', () => {
  162.         updatePopupPrice();
  163.         addToCart(JSON.parse(decodeURIComponent(document.querySelector('.agregar-al-carrito').getAttribute('data-dish'))));
  164.         closePopup();
  165.       });
  166.     }
  167.  
  168.     function updatePopupPrice() {
  169.       const dish = JSON.parse(decodeURIComponent(document.querySelector('.agregar-al-carrito').getAttribute('data-dish')));
  170.       const selectedOptions = Array.from(document.querySelectorAll('.option-item input[type="checkbox"]:checked'));
  171.       const quantity = parseInt(document.querySelector('.quantity').value);
  172.       let totalPrice = parseFloat(dish.price) * quantity;
  173.  
  174.       selectedOptions.forEach(option => {
  175.         const optionPrice = parseFloat(option.value);
  176.         if (!isNaN(optionPrice)) {
  177.           totalPrice += optionPrice * quantity;
  178.         }
  179.       });
  180.  
  181.       document.querySelector('.popup .precio').textContent = currencySymbol + totalPrice.toFixed(2) + ' ' + currency;
  182.     }
  183.  
  184.     // Función para cerrar el pop-up
  185.     function closePopup() {
  186.       var popup = document.querySelector('.popup');
  187.       if (popup) {
  188.         popup.classList.remove('show');
  189.         setTimeout(function() {
  190.           popup.remove();
  191.         }, 300);
  192.       }
  193.     }
  194.  
  195.     // Evento de clic para cerrar el pop-up al hacer clic en el overlay
  196.     document.addEventListener('click', function(e) {
  197.       if (e.target.classList.contains('popup')) {
  198.         closePopup();
  199.       }
  200.     });
  201.  
  202.     // Evento de teclado para cerrar los pop-ups con la tecla ESC
  203.     document.addEventListener('keydown', function(e) {
  204.       if (e.key === 'Escape') {
  205.         closePopup();
  206.       }
  207.     });
  208.  
  209.     // Función para añadir un producto al carrito
  210.     function addToCart(dish) {
  211.       var quantity = parseInt(document.querySelector('.quantity').value);
  212.       var selectedOptions = Array.from(document.querySelectorAll('.option-item input[type="checkbox"]:checked'));
  213.  
  214.       var dishWithOptions = {
  215.         ...dish,
  216.         price: parseFloat(dish.price), // Asegúrate de que el precio sea un número
  217.         quantity: quantity,
  218.         selectedOptions: selectedOptions.map(function(option) {
  219.           return {
  220.             name: option.nextElementSibling.textContent.split(' ' + currencySymbol)[0].trim(),
  221.             price: parseFloat(option.value) // Asegúrate de que el precio de la opción sea un número
  222.           };
  223.         })
  224.       };
  225.  
  226.       cartItems.push(dishWithOptions);
  227.  
  228.       updateCartCount();
  229.       updateCartPopup();
  230.     }
  231.  
  232.     // Función para actualizar el contador del carrito
  233.     function updateCartCount() {
  234.       var cartCount = document.querySelector('.cart-count');
  235.       cartCount.textContent = cartItems.reduce(function(total, item) {
  236.         return total + item.quantity;
  237.       }, 0);
  238.     }
  239.  
  240.     // Función para actualizar el contenido del pop-up del carrito
  241.     function updateCartPopup() {
  242.       var cartPopup = document.querySelector('.cart-popup');
  243.       if (cartPopup) {
  244.         var cartList = cartPopup.querySelector('ul');
  245.         var cartTotal = calculateCartTotal(cartItems);
  246.         listItems = cartItems.map(function(item) {
  247.           var optionsText = item.selectedOptions.map(function(option) {
  248.             return '- ' + option.name + ' ' + (option.price ? currencySymbol + option.price.toFixed(2) : '');
  249.           }).join('<br>');
  250.  
  251.           var itemTotal = calculateItemTotal(item);
  252.           var basePrice = parseFloat(item.price);
  253.  
  254.           return '<li>' +
  255.             '<div class="cart-item">' +
  256.               '<img src="' + item.image + '" alt="' + item.name + '">' +
  257.               '<div class="cart-item-details">' +
  258.                 '<h4>' + item.name + '</h4>' +
  259.                 '<p class="list-cantidad">Cantidad: ' + item.quantity + '</p>' +
  260.                 '<p class="list-precio">Precio base: ' + currencySymbol + basePrice.toFixed(2) + ' ' + currency + '</p>' +
  261.                 (optionsText ? '<p class="list-opciones"><b>Opciones:</b><br>' + optionsText + '</p>' : '') +
  262.                 '<p class="list-item-total"><b>Total: ' + currencySymbol + itemTotal.toFixed(2) + ' ' + currency + '</b></p>' +
  263.               '</div>' +
  264.               '<i class="fas fa-trash remove-item" data-dish="' + encodeURIComponent(JSON.stringify(item)) + '"></i>' +
  265.             '</div>' +
  266.           '</li>';
  267.         }).join('');
  268.         cartList.innerHTML = listItems;
  269.         cartPopup.querySelector('.cart-total').textContent = cartTotal;
  270.  
  271.         if (cartItems.length === 0) {
  272.           cartPopup.querySelector('.cart-empty').style.display = 'block';
  273.           cartPopup.querySelector('#complete-order').disabled = true;
  274.         } else {
  275.           cartPopup.querySelector('.cart-empty').style.display = 'none';
  276.           cartPopup.querySelector('#complete-order').disabled = false;
  277.         }
  278.       }
  279.     }
  280.  
  281.     // Función para calcular el total de cada item del carrito
  282.     function calculateItemTotal(item) {
  283.       var itemPrice = parseFloat(item.price);
  284.       item.selectedOptions.forEach(function(option) {
  285.         var optionPrice = option.price ? parseFloat(option.price) : 0;
  286.         itemPrice += optionPrice;
  287.       });
  288.       return itemPrice * item.quantity;
  289.     }
  290.  
  291.     // Función para abrir el pop-up del carrito
  292.     function openCartPopup() {
  293.       var cartTotal = calculateCartTotal(cartItems);
  294.       var popupHtml = '<div class="popup">' +
  295.         '<div class="cart-popup">' +
  296.           '<div class="cart-content">' +
  297.             '<h2>Mi Pedido</h2>' +
  298.             '<ul></ul>' +
  299.             '<div class="cart-empty" style="display: ' + (cartItems.length === 0 ? 'block' : 'none') + '">El carrito está vacío.</div>' +
  300.           '</div>' +
  301.           '<div class="cart-actions">' +
  302.             '<div class="cart-total">Total: ' + cartTotal + '</div>' +
  303.             '<button class="empty-cart">Vaciar carrito</button>' +
  304.             '<button id="complete-order" ' + (cartItems.length === 0 ? 'disabled' : '') + '>Completar pedido</button>' +
  305.           '</div>' +
  306.           '<i class="fas fa-times icono-cerrar"></i>' +
  307.         '</div>' +
  308.       '</div>';
  309.      
  310.       document.body.insertAdjacentHTML('beforeend', popupHtml);
  311.       setTimeout(function() {
  312.         document.querySelector('.popup').classList.add('show');
  313.       }, 50);
  314.       updateCartPopup();
  315.     }
  316.  
  317.     // Función para eliminar un producto del carrito
  318.     function removeFromCart(dish) {
  319.       var index = cartItems.findIndex(function(item) {
  320.         return JSON.stringify(item) === JSON.stringify(dish);
  321.       });
  322.       if (index !== -1) {
  323.         cartItems.splice(index, 1);
  324.         updateCartCount();
  325.         updateCartPopup();
  326.       }
  327.     }
  328.  
  329.     // Función para vaciar el carrito
  330.     function emptyCart() {
  331.       cartItems = [];
  332.       updateCartCount();
  333.       var popup = document.querySelector('.popup');
  334.       if (popup) {
  335.         popup.classList.remove('show');
  336.         setTimeout(function() {
  337.           popup.remove();
  338.         }, 300);
  339.       }
  340.     }
  341.  
  342.     // Función para calcular el total del carrito
  343.     function calculateCartTotal(items) {
  344.       var total = 0;
  345.       items.forEach(function(item) {
  346.         var itemPrice = parseFloat(item.price);
  347.         item.selectedOptions.forEach(function(option) {
  348.           var optionPrice = option.price ? parseFloat(option.price) : 0;
  349.           itemPrice += optionPrice;
  350.         });
  351.         total += itemPrice * item.quantity;
  352.       });
  353.       return 'Total Pedido: ' + currencySymbol + total.toFixed(2) + ' ' + currency;
  354.     }
  355.  
  356.     // Función para mostrar el formulario de información del pedido
  357.     function showOrderForm() {
  358.       var formHtml = '<div class="order-form">' +
  359.         '<a id="back-to-cart"><i class="fas fa-arrow-left"></i> Regresar al carrito</a>' +
  360.         '<h2>Completa tu pedido</h2>' +
  361.         '<form>' +
  362.           '<label for="name">Nombre:</label>' +
  363.           '<input type="text" id="name" required>' +
  364.                   '<label for="name">Teléfono:</label>' +
  365.                   '<input type="text" id="phone" required>' +
  366.           '<label for="delivery">Opciones de entrega:</label>' +
  367.           '<select id="delivery" required>' +
  368.             '<option value="">Selecciona una opción</option>' +
  369.             '<option value="Domicilio">Envío a domicilio</option>' +
  370.             '<option value="Local">Recoger en local</option>' +
  371.           '</select>' +
  372.           '<div id="address-field" style="display: none;">' +
  373.             '<label for="address">Dirección:</label>' +
  374.             '<textarea id="address" required></textarea>' +
  375.           '</div>' +
  376.           '<label for="payment">Formas de pago:</label>' +
  377.           '<select id="payment" required>' +
  378.             '<option value="">Selecciona una opción</option>' +
  379.             '<option value="Efectivo">Efectivo</option>' +
  380.             '<option value="Tarjeta">Tarjeta</option>' +
  381.           '</select>' +
  382.           '<label for="note">Nota adicional:</label>' +
  383.           '<textarea id="note"></textarea>' +
  384.           '<div class="terminos">' +
  385.             '<input type="checkbox" id="terms" required>' +
  386.             '<label for="terms">Acepto los <a href="#" target="_blank">términos y condiciones</a>.</label>' +
  387.           '</div>' +
  388.           '<button type="submit" id="submit-order"><i class="fab fa-whatsapp"></i> Enviar pedido</button>' +
  389.         '</form>' +
  390.       '</div>';
  391.  
  392.       var cartPopup = document.querySelector('.cart-popup');
  393.       var cartDetails = cartPopup.querySelector('.cart-content');
  394.       var cartActions = cartPopup.querySelector('.cart-actions');
  395.       cartDetails.style.display = 'none';
  396.       cartActions.style.display = 'none';
  397.       cartPopup.insertAdjacentHTML('beforeend', formHtml);
  398.       setTimeout(function() {
  399.         document.querySelector('.popup').classList.add('show');
  400.       }, 50);
  401.  
  402.       var backButton = document.getElementById('back-to-cart');
  403.         backButton.addEventListener('click', function(e) {
  404.           e.preventDefault();
  405.           var popup = document.querySelector('.popup');
  406.           popup.classList.remove('show');
  407.           setTimeout(function() {
  408.             var orderForm = document.querySelector('.order-form');
  409.             orderForm.remove();
  410.             cartDetails.style.display = 'block';
  411.             cartActions.style.display = 'block';
  412.             setTimeout(function() {
  413.               popup.classList.add('show');
  414.             }, 50);
  415.           }, 300);
  416.         });
  417.  
  418.       var deliverySelect = document.getElementById('delivery');
  419.       var addressField = document.getElementById('address-field');
  420.  
  421.       deliverySelect.addEventListener('change', function() {
  422.         if (deliverySelect.value === 'Domicilio') {
  423.           addressField.style.display = 'block';
  424.           addressField.querySelector('#address').required = true;
  425.         } else {
  426.           addressField.style.display = 'none';
  427.           addressField.querySelector('#address').required = false;
  428.         }
  429.       });
  430.     }
  431.  
  432.     // Evento de clic para los "card-menu"
  433.     document.addEventListener('click', function(e) {
  434.       if (e.target.closest('.card-menu')) {
  435.         var dish = JSON.parse(decodeURIComponent(e.target.closest('.card-menu').getAttribute('data-dish')));
  436.         openPopup(dish);
  437.       }
  438.     });
  439.  
  440.     // Evento de clic para el icono de cierre del pop-up
  441.     document.addEventListener('click', function(e) {
  442.       if (e.target.classList.contains('icono-cerrar')) {
  443.         closePopup();
  444.       }
  445.     });
  446.  
  447.     // Evento de clic para el icono del carrito
  448.     document.getElementById('cart-icon').addEventListener('click', function() {
  449.       openCartPopup();
  450.     });
  451.  
  452.     // Evento de clic para el botón "Completar pedido"
  453.     document.addEventListener('click', function(e) {
  454.       if (e.target.id === 'complete-order') {
  455.         if (cartItems.length === 0) {
  456.           alert('Para completar el pedido, debes agregar productos al carrito.');
  457.         } else {
  458.           var popup = document.querySelector('.popup');
  459.           popup.classList.remove('show');
  460.           setTimeout(function() {
  461.             showOrderForm();
  462.           }, 300);
  463.         }
  464.       }
  465.     });
  466.  
  467.     // Evento de clic para el icono de eliminar producto del carrito
  468.     document.addEventListener('click', function(e) {
  469.       if (e.target.classList.contains('remove-item')) {
  470.         var dish = JSON.parse(decodeURIComponent(e.target.getAttribute('data-dish')));
  471.         removeFromCart(dish);
  472.       }
  473.     });
  474.  
  475.     // Evento de clic para el botón "Vaciar carrito"
  476.     document.addEventListener('click', function(e) {
  477.       if (e.target.classList.contains('empty-cart')) {
  478.         emptyCart();
  479.       }
  480.     });
  481.  
  482.     // Evento de clic para los botones de incremento y decremento de cantidad
  483.     document.addEventListener('click', function(e) {
  484.       if (e.target.classList.contains('increment-quantity')) {
  485.         var quantityInput = e.target.previousElementSibling;
  486.         var currentQuantity = parseInt(quantityInput.value);
  487.         quantityInput.value = currentQuantity + 1;
  488.         updatePopupPrice();
  489.       } else if (e.target.classList.contains('decrement-quantity')) {
  490.         var quantityInput = e.target.nextElementSibling;
  491.         var currentQuantity = parseInt(quantityInput.value);
  492.         if (currentQuantity > 1) {
  493.           quantityInput.value = currentQuantity - 1;
  494.           updatePopupPrice();
  495.         }
  496.       }
  497.     });
  498.  
  499.     // Evento de envío del formulario de información del pedido
  500.     document.addEventListener('submit', function(e) {
  501.       if (e.target.closest('.order-form')) {
  502.         e.preventDefault();
  503.         var name = document.getElementById('name').value;
  504.         var delivery = document.getElementById('delivery').value;
  505.         var payment = document.getElementById('payment').value;
  506.         var note = document.getElementById('note').value;
  507.  
  508.         if (name === '' || delivery === '' || payment === '') {
  509.           alert('Por favor, completa todos los campos obligatorios del formulario.');
  510.           return;
  511.         }
  512.  
  513.         var addressField = document.getElementById('address');
  514.         var address = addressField.value;
  515.  
  516.         if (delivery === 'Domicilio' && address === '') {
  517.          alert('Por favor, ingresa tu dirección para el envío a domicilio.');
  518.           return;
  519.         }
  520.  
  521.         var cartTotal = calculateCartTotal(cartItems);
  522.         var message = '¡NUEVO PEDIDO!\n\n' +
  523.         `Nombre: ${document.getElementById('name').value}\n` +
  524.         `Opciones de entrega: ${document.getElementById('delivery').value}\n` +
  525.         (document.getElementById('delivery').value === 'Domicilio' ? `Dirección: ${addressField.value}\n` : '') +
  526.         `Formas de pago: ${document.getElementById('payment').value}\n` +
  527.         `Nota adicional: ${document.getElementById('note').value}\n` +
  528.           'Productos:\n' +
  529.           cartItems.map(function(item) {
  530.             var itemPrice = parseFloat(item.price);
  531.             var optionsText = item.selectedOptions.map(function(option) {
  532.               var optionPrice = parseFloat(option.price);
  533.               return '  - ' + option.name + ' ' + (optionPrice ? currencySymbol + optionPrice.toFixed(2) : '');
  534.             }).join('\n');
  535.             return '- ' + item.name + ' (' + item.quantity + ') ' + currencySymbol + itemPrice.toFixed(2) + ' ' + currency + '\n' + optionsText;
  536.           }).join('\n\n') + '\n\n' +
  537.           cartTotal;
  538.         var whatsappUrl = 'https://wa.me/' + whatsappNumber + '?text=' + encodeURIComponent(message);
  539.         window.open(whatsappUrl, '_blank');
  540.       }
  541.     });
  542.  
  543.     // Hacer una solicitud GET a la URL de la aplicación web de Google Apps Script
  544.     fetch(appScriptUrl)
  545.     .then(response => response.json())
  546.     .then(data => {
  547.       // Convertir precios a números
  548.       for (let section in data) {
  549.         data[section] = data[section].map(dish => ({
  550.           ...dish,
  551.           price: parseFloat(dish.price)
  552.         }));
  553.       }
  554.       // Llamar a la función para generar el HTML del menú con los datos obtenidos
  555.       document.getElementById('ov-listado-menu').innerHTML = generateMenuHTML(data);
  556.  
  557.      // Agregar evento de clic a las pestañas para el desplazamiento suave
  558.      var tabLinks = document.querySelectorAll('#tabs a');
  559.       tabLinks.forEach(function(link) {
  560.         link.addEventListener('click', function(e) {
  561.           e.preventDefault();
  562.           var target = document.querySelector(this.getAttribute('href'));
  563.           var contenido = document.querySelector('.contenido');
  564.           var targetPosition = target.offsetTop - contenido.offsetTop + 145;
  565.           contenido.scrollTo({
  566.             top: targetPosition,
  567.             behavior: 'smooth'
  568.           });
  569.         });
  570.       });
  571.  
  572.       // Agregar evento de scroll al contenedor ".contenido"
  573.       document.querySelector('.contenido').addEventListener('scroll', updateActiveTab);
  574.  
  575.       // Ocultar el precargador y mostrar el contenido
  576.       hidePreloader();
  577.     })
  578.     .catch(error => {
  579.       console.error('Error al obtener los datos:', error);
  580.     });
  581.   </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement