DOVE?
↓
Europa
Asia
Africa
America
Oceania
DESTINAZIONE
Scegli una destinazione
↓
QUANDO?
Scegli un mese
↓
CERCA
ORA
DISPONIBILI
ASIA
THAILANDIA
Isole, templi e nuove amicizie
ASIA
VIETNAM
Natura, cultura e libertà
ASIA
INDONESIA
Avventura, natura e spiritualità
Nessun viaggio trovato
Prova a modificare i filtri.
PROSSIMAMENTE
IN ARRIVO
EUROPA
ISLANDA
ASIA
GIAPPONE
AFRICA
MAROCCO
EUROPA
PORTOGALLO
ASIA
FILIPPINE
OCEANIA
AUSTRALIA
(function(){
function initNowhereDestinations(){
const root = document.querySelector('.nw-dest-page');
if(!root) return;
const fields = root.querySelectorAll('.nw-search-field');
const continentButtons = root.querySelectorAll('.nw-continent-button');
const destinationList = root.querySelector('.nw-destination-list');
const destinationField = root.querySelector('[data-field="destination"]');
const destinationValue = destinationField.querySelector( '.nw-selected-value' );
const monthValue = root.querySelector( '[data-field="month"] .nw-selected-value' );
const continentValue = root.querySelector( '[data-field="continent"] .nw-selected-value' );
const destinationButton = destinationField.querySelector( '.nw-search-value' );
const searchButton = root.querySelector('.nw-search-button');
const noResults = root.querySelector('.nw-no-results');
let selectedContinent = ''; let selectedDestination = ''; let selectedMonth = '';
const destinations = {
Europa:[ 'Islanda', 'Portogallo', 'Grecia', 'Norvegia' ],
Asia:[ 'Thailandia', 'Vietnam', 'Indonesia', 'Giappone', 'Filippine', 'India', 'Nepal' ],
Africa:[ 'Marocco', 'Tanzania', 'Kenya' ],
America:[ 'Messico', 'Costa Rica', 'Perù' ],
Oceania:[ 'Australia', 'Nuova Zelanda' ]
};
function closeFields(){
fields.forEach(function(field){
field.classList.remove('open');
});
}
function openField(field){
closeFields();
field.classList.add('open');
}
/* * APERTURA DEI CAMPI */
fields.forEach(function(field){
const button = field.querySelector('.nw-search-value');
button.addEventListener( 'click', function(event){
event.stopPropagation();
if(button.disabled) return;
if(field.classList.contains('open')){
field.classList.remove('open');
}else{
openField(field);
}
} );
});
/* * CONTINENTE */
continentButtons.forEach(function(button){
button.addEventListener( 'click', function(event){
event.stopPropagation();
selectedContinent = button.dataset.continent;
selectedDestination = '';
continentValue.textContent = selectedContinent;
destinationValue.textContent = 'Scegli una destinazione';
destinationButton.disabled = false;
continentButtons.forEach( function(item){
item.classList.remove( 'selected' );
} );
button.classList.add('selected');
destinationList.innerHTML = '';
destinations[ selectedContinent ].forEach(function(destination){
const option = document.createElement('button');
option.type = 'button';
option.className = 'nw-destination-option';
option.dataset.destination = destination;
option.textContent = destination;
option.addEventListener( 'click', function(event){
event.stopPropagation();
selectedDestination = destination;
destinationValue.textContent = destination;
destinationList .querySelectorAll( '.nw-destination-option' ) .forEach(function(item){
item.classList.remove( 'selected' );
});
option.classList.add( 'selected' );
closeFields();
openField( root.querySelector( '[data-field="month"]' ) );
} );
destinationList.appendChild( option );
});
openField( destinationField );
} );
});
/* * MESE */
root .querySelectorAll('.nw-month-button') .forEach(function(button){
button.addEventListener( 'click', function(event){
event.stopPropagation();
selectedMonth = button.textContent.trim();
monthValue.textContent = selectedMonth;
root .querySelectorAll( '.nw-month-button' ) .forEach(function(item){
item.classList.remove( 'selected' );
});
button.classList.add( 'selected' );
closeFields();
} );
});
/* * CERCA */
searchButton.addEventListener( 'click', function(){
const availableCards = root.querySelectorAll( '.nw-destination-card' );
const comingCards = root.querySelectorAll( '.nw-coming-card' );
let visibleCount = 0;
/* * DISPONIBILI */
availableCards.forEach( function(card){
let visible = true;
if( selectedContinent && card.dataset.continent !== selectedContinent ){
visible = false;
}
if( selectedDestination && card.dataset.destination !== selectedDestination ){
visible = false;
}
if( selectedMonth && card.dataset.month !== selectedMonth ){
visible = false;
}
if(visible){
card.classList.remove( 'nw-dest-hidden' );
visibleCount++;
}else{
card.classList.add( 'nw-dest-hidden' );
}
} );
/* * IN ARRIVO * * Se viene scelta una destinazione * non ancora disponibile, * mostriamo quella card. */
comingCards.forEach( function(card){
let visible = true;
if( selectedContinent && card.dataset.continent !== selectedContinent ){
visible = false;
}
if( selectedDestination && card.dataset.destination !== selectedDestination ){
visible = false;
}
if( selectedMonth ){
/* * Le destinazioni future * non hanno ancora un mese. * Quindi non vengono mostrate * quando è selezionato un mese. */
visible = false;
}
if(visible){
card.classList.remove( 'nw-dest-hidden' );
visibleCount++;
}else{
card.classList.add( 'nw-dest-hidden' );
}
} );
/* * SE NON CI SONO RISULTATI */
if(visibleCount === 0){
noResults.classList.add( 'visible' );
}else{
noResults.classList.remove( 'visible' );
}
closeFields();
root .querySelector('.nw-dest-content') .scrollIntoView({ behavior:'smooth', block:'start' });
} );
/* * CLICK FUORI */
document.addEventListener( 'click', function(event){
if( !root.contains(event.target) ){
closeFields();
}
} );
}
/* * AVVIO */
if( document.readyState === 'loading' ){
document.addEventListener( 'DOMContentLoaded', initNowhereDestinations );
}else{
initNowhereDestinations();
}
})();