Advertisement
oscarviedma

vCardRestaurant-Codigo-Corregido-COP

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