File size: 2,829 Bytes
bbd7f38 00b6923 bbd7f38 00b6923 bbd7f38 00b6923 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
// Función para cargar datos CSV
async function loadCSVData() {
try {
const response = await fetch('data/options.csv');
const csvData = await response.text();
const lines = csvData.split('\n');
const headers = lines[0].split(',');
// Crear objeto con arrays para cada columna
const data = {};
headers.forEach(header => {
data[header.trim()] = [];
});
// Llenar los arrays con los datos
for (let i = 1; i < lines.length; i++) {
const values = lines[i].split(',');
headers.forEach((header, index) => {
if (values[index]) {
data[header.trim()].push(values[index].trim());
}
});
}
// Llenar los selects con los datos correspondientes
Object.keys(data).forEach(key => {
const select = document.querySelector(`select[name="${key}"]`);
if (select) {
data[key].forEach(value => {
if (value) {
const option = document.createElement('option');
option.value = value;
option.textContent = value;
select.appendChild(option);
}
});
}
});
} catch (error) {
console.error('Error al cargar el archivo CSV:', error);
}
}
// Función para inicializar componentes
document.addEventListener('DOMContentLoaded', function() {
// Cargar datos del CSV
loadCSVData();
// Inicializar tooltips
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
tooltipTriggers.forEach(trigger => {
trigger.addEventListener('mouseenter', function() {
const tooltip = document.createElement('div');
tooltip.className = 'tooltip';
tooltip.textContent = this.getAttribute('data-tooltip');
const rect = this.getBoundingClientRect();
tooltip.style.position = 'absolute';
tooltip.style.left = `${rect.left + rect.width/2}px`;
tooltip.style.top = `${rect.top - 40}px`;
tooltip.style.transform = 'translateX(-50%)';
document.body.appendChild(tooltip);
this.addEventListener('mouseleave', function() {
tooltip.remove();
});
});
});
// Validación de formulario adicional
const form = document.getElementById('flightForm');
if (form) {
form.addEventListener('submit', function(e) {
// Validación adicional puede ir aquí
});
}
// Cargar feather icons
if (window.feather) {
feather.replace();
}
}); |