vueloenglobo.mx/public/assets/js/vuelos-en-globo.js

53 lines
1.8 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function () {
// Lazy loading de imágenes
const imageObserver = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const img = entry.target;
const dataSrc = img.getAttribute("data-src");
if (dataSrc && img.src !== dataSrc) {
img.src = dataSrc;
img.classList.add("loaded");
}
observer.unobserve(img);
}
});
},
{
threshold: 0.1,
rootMargin: "50px",
},
);
document.querySelectorAll(".flight-card__image img").forEach((img) => {
imageObserver.observe(img);
});
// Manejo de errores de imágenes
document.querySelectorAll(".flight-card__image img").forEach((img) => {
img.addEventListener("error", function () {
this.src = "assets/img/vuelos/entrega-de-anillo-vip/0.jpg";
this.classList.add("loaded");
});
});
});
function openChatbot(vueloNombre = null, vueloId = null) {
const chatbot = document.querySelector(".chatbot-container");
const chatbotInput = document.querySelector(".chatbot-input input");
if (chatbot && !chatbot.classList.contains("active")) {
const toggle = document.querySelector(".chatbot-toggle");
if (toggle) toggle.click();
}
setTimeout(() => {
if (chatbotInput && vueloNombre) {
chatbotInput.value = `Hola, quiero información sobre ${vueloNombre}`;
const sendBtn = document.querySelector(".chatbot-input button");
if (sendBtn) sendBtn.click();
}
}, 500);
}