Download script.js from adryanTMC/comboios-replica-express: direct link, hf CLI and curl.
- Browser
- Download file 5.94 kB
-
https://huggingface.co/spaces/adryanTMC/comboios-replica-express/resolve/main/script.js
- Command line
-
hf download hf://spaces/adryanTMC/comboios-replica-express/script.js
-
curl -L -o script.js https://huggingface.co/spaces/adryanTMC/comboios-replica-express/resolve/main/script.js
5.94 kB
| // Main JavaScript file for Comboios de Portugal Replica | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize Feather Icons | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| // Mobile menu toggle | |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); | |
| const mobileMenu = document.getElementById('mobile-menu'); | |
| if (mobileMenuButton && mobileMenu) { | |
| mobileMenuButton.addEventListener('click', function() { | |
| mobileMenu.classList.toggle('hidden'); | |
| mobileMenu.classList.toggle('mobile-menu-enter'); | |
| }); | |
| } | |
| // Booking widget functionality | |
| initializeBookingWidget(); | |
| // Smooth scroll for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const target = document.querySelector(this.getAttribute('href')); | |
| if (target) { | |
| target.scrollIntoView({ | |
| behavior: 'smooth', | |
| block: 'start' | |
| }); | |
| } | |
| }); | |
| }); | |
| // Sticky navigation on scroll | |
| const nav = document.querySelector('nav'); | |
| let lastScroll = 0; | |
| window.addEventListener('scroll', () => { | |
| const currentScroll = window.pageYOffset; | |
| if (currentScroll > 100) { | |
| nav?.classList.add('shadow-md'); | |
| } else { | |
| nav?.classList.remove('shadow-md'); | |
| } | |
| lastScroll = currentScroll; | |
| }); | |
| }); | |
| // Booking Widget Logic | |
| function initializeBookingWidget() { | |
| // Swap origin and destination | |
| const swapButton = document.getElementById('swap-stations'); | |
| const originInput = document.getElementById('origin'); | |
| const destinationInput = document.getElementById('destination'); | |
| if (swapButton && originInput && destinationInput) { | |
| swapButton.addEventListener('click', function() { | |
| // Add rotation animation | |
| this.classList.add('swap-animation'); | |
| // Swap values | |
| const temp = originInput.value; | |
| originInput.value = destinationInput.value; | |
| destinationInput.value = temp; | |
| // Trigger change events if needed | |
| originInput.dispatchEvent(new Event('change')); | |
| destinationInput.dispatchEvent(new Event('change')); | |
| // Remove animation class after completion | |
| setTimeout(() => { | |
| this.classList.remove('swap-animation'); | |
| }, 300); | |
| }); | |
| } | |
| // Date validation - ensure return date is after departure | |
| const departureDate = document.getElementById('departure-date'); | |
| const returnDate = document.getElementById('return-date'); | |
| if (departureDate && returnDate) { | |
| // Set min date to today | |
| const today = new Date().toISOString().split('T')[0]; | |
| departureDate.min = today; | |
| returnDate.min = today; | |
| departureDate.addEventListener('change', function() { | |
| returnDate.min = this.value; | |
| if (returnDate.value && returnDate.value < this.value) { | |
| returnDate.value = this.value; | |
| } | |
| }); | |
| } | |
| // Search form submission | |
| const searchForm = document.getElementById('booking-form'); | |
| if (searchForm) { | |
| searchForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const searchButton = document.getElementById('search-button'); | |
| const originalText = searchButton.innerHTML; | |
| // Show loading state | |
| searchButton.disabled = true; | |
| searchButton.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> A pesquisar...'; | |
| searchButton.classList.add('search-button-loading'); | |
| feather.replace(); | |
| // Simulate API call | |
| setTimeout(() => { | |
| searchButton.disabled = false; | |
| searchButton.innerHTML = originalText; | |
| searchButton.classList.remove('search-button-loading'); | |
| feather.replace(); | |
| // Show alert (in real app, would redirect to results) | |
| alert('Pesquisa simulada: De ' + originInput.value + ' para ' + destinationInput.value); | |
| }, 1500); | |
| }); | |
| } | |
| // Trip type toggle (Ida e volta / Só ida) | |
| const tripTypeRadios = document.querySelectorAll('input[name="trip-type"]'); | |
| const returnDateContainer = document.getElementById('return-date-container'); | |
| if (tripTypeRadios.length && returnDateContainer) { | |
| tripTypeRadios.forEach(radio => { | |
| radio.addEventListener('change', function() { | |
| if (this.value === 'one-way') { | |
| returnDateContainer.classList.add('hidden'); | |
| returnDateContainer.classList.remove('block'); | |
| } else { | |
| returnDateContainer.classList.remove('hidden'); | |
| returnDateContainer.classList.add('block'); | |
| } | |
| }); | |
| }); | |
| } | |
| } | |
| // Utility function for debouncing | |
| function debounce(func, wait) { | |
| let timeout; | |
| return function executedFunction(...args) { | |
| const later = () => { | |
| clearTimeout(timeout); | |
| func(...args); | |
| }; | |
| clearTimeout(timeout); | |
| timeout = setTimeout(later, wait); | |
| }; | |
| } | |
| // Station autocomplete simulation | |
| const stations = [ | |
| 'Lisboa - Oriente', | |
| 'Lisboa - Santa Apolónia', | |
| 'Porto - Campanhã', | |
| 'Porto - São Bento', | |
| 'Braga', | |
| 'Aveiro', | |
| 'Coimbra', | |
| 'Faro', | |
| 'Évora', | |
| 'Guimarães' | |
| ]; | |
| function filterStations(query) { | |
| return stations.filter(station => | |
| station.toLowerCase().includes(query.toLowerCase()) | |
| ); | |
| } |