Norway Train Routes | Domestic & International - NORWAY TRAINS (2024)

Norway Train Routes | Domestic & International - NORWAY TRAINS (1) Find your train and book train tickets with Rail.Ninja® - a global independent online reservation service agency for train tickets

`); }); if($('.train-search-block').hasClass('round-trip') && selectedDates.length === 1) { $('.date-wrapper').append(`

`); } } } }; let datePicker = $("#searchDate").flatpickr(flatpickrOptions); $('.date-wrapper .date').append(`${datePicker.formatDate(firstDate, "d")}${datePicker.formatDate(firstDate, "M")}`); const renderErrorMessage = () => { let messages = []; $('.search-error-message').remove(); Object.keys(errors).forEach(key => messages.push(errors[key])); $('.train-search-form').append(`

${errorsMessages.hasError} ${messages.join(', ')}

`); }; const removeErrorAndUpdate = ($element) => { $element.removeClass('error-validation'); delete errors[$element.attr('class')]; $('.search-error-message').remove(); if (Object.entries(errors).length !== 0) { renderErrorMessage(); } }; $('input[type=radio][name=form-mode]').change(function () { if (this.value === link.mode.basic) { if (datePicker.selectedDates.length === 2) { datePicker.selectedDates.pop(); } if (errors['search-date']) { removeErrorAndUpdate($('.search-date')); } datePicker.set('mode', 'single'); datePicker.set('showMonths', 1); datePicker.destroy(); flatpickrOptions.defaultDate = firstDate; datePicker = $("#searchDate").flatpickr(flatpickrOptions); $('.date-wrapper').html(''); $('.date-wrapper').append(`

${datePicker.formatDate(firstDate, "d")}${datePicker.formatDate(firstDate, "M")}

`); $('.train-search-block').removeClass('round-trip'); } else if (this.value === link.mode.roundtrip) { firstDate = datePicker.selectedDates[0]; datePicker.set('mode', 'range'); if ($(window).width() > 725) { datePicker.set('showMonths', 2); } if ($('.date-wrapper .date').length < 2) { datePicker.open(); $('.date-wrapper').append(`

`); } $('.train-search-block').addClass('round-trip'); } }); $('.search-date').click(function () { datePicker.open(); }); $('.passengers-value').click(function () { $('.passengers-dropdown').show(); }); const quantityMinus = $('.quantity-counter .counter-minus'); const quantityPlus = $('.quantity-counter .counter-plus'); let passengersCount = 1; const getChildrenAgeWrapper = (number) => { return `

Child ${number}

`; }; quantityMinus.click(function (e) { e.preventDefault(); const input = $(this).siblings('.counter-input'); const isAdultsQuantity = $(this).closest('.quantity').hasClass('quantity-adults'); let value = input.val(); let minValue = 0; if (isAdultsQuantity) { minValue = 1; } if (value > minValue && passengersCount > 1) { value--; passengersCount--; input.val(value); } if (isAdultsQuantity) { $('.passengers-value .adults').html('×' + value); } else { const childrenLabel = $('.passengers-value .children'); if (value === 0 && childrenLabel.length !== 0) { childrenLabel.remove(); } else { childrenLabel.html('×' + value); } $('.children-age-wrapper').last().remove(); } }); quantityPlus.click(function (e) { e.preventDefault(); const input = $(this).siblings('.counter-input'); const isAdultsQuantity = $(this).closest('.quantity').hasClass('quantity-adults'); let value = input.val(); if (passengersCount < 9) { value++; passengersCount++; input.val(value); if (isAdultsQuantity) { $('.passengers-value .adults').html('×' + value); } else { if ($('.passengers-value .children').length === 0) { $('.passengers-value').append(''); } $('.passengers-value .children').html('×' + value); $('.passengers-dropdown-column').last().append(getChildrenAgeWrapper(value)); let choicesChildrenAge = new Choices('.choice-children-age', { searchEnabled: false, itemSelectText: '', shouldSort: false, }); } } }); const getDefaultRoutesIds = () => { const routes = ['departureStation', 'arrivalStation'].map(routeId => { const routeElement = document.getElementById(routeId); return routeElement ? routeElement.innerText.toLocaleLowerCase() : null; }).filter(route => route); if (routes.length) { return routes.map(route => cities.find(city => city.label.toLocaleLowerCase() === route)?.value); } return []; }; const defaultRoutesIds = getDefaultRoutesIds();const route1 = defaultRoutesIds[0] || '';const route2 = defaultRoutesIds[1] || '';const getChoicesOptions = (placeholder, station1, station2) => { const filteredCities = cities .filter(city => city.value !== station2) .map(city => { if (city.value === station1) { return { ...city, selected: true }; } return city; }); return { itemSelectText: '', searchPlaceholderValue: placeholder, searchInputMoveToTop: true, shouldSort: false, choices: [ { label: '', value: '', placeholder: true, selected: true, disabled: true, }, ...filteredCities, ], };};const departureChoices = new Choices('.departure > .choice-station', getChoicesOptions('From', route1, route2));const arrivalChoices = new Choices('.arrival > .choice-station', getChoicesOptions('To', route2, route1)); $('.stations .choice-station').on('choice', function(event) { const citiesFilter = cities.filter(city => city.value !== event.detail.choice.value); if ($(this).closest('.choices').parent().hasClass('departure')) { arrivalChoices.setChoices(citiesFilter, 'value', 'label', true); } else { departureChoices.setChoices(citiesFilter, 'value', 'label', true); } }); function isTouchDevice() { return 'ontouchstart' in window || navigator.maxTouchPoints; } if (isTouchDevice()) { $('.search-inputs').on('touchstart', '.children-age-select .choices', function () { $(this).click(); }); } $('.search-inputs').on('change', '.search-date.error-validation, .stations.error-validation, .passengers.error-validation', function () { removeErrorAndUpdate($(this)); }); $('.search-inputs').on('click', '.passengers.error-validation .counter-minus, .passengers.error-validation .counter-plus', function () { removeErrorAndUpdate($('.passengers')); }); $('.train-search-form').submit(function (e) { e.preventDefault(); const formMode = $("input[name='form-mode']:checked").val(); const firstDateFormatted = datePicker.formatDate(firstDate, "Y-m-d"); let secondDateFormatted; if (formMode === link.mode.roundtrip) { if (datePicker.selectedDates[1]) { secondDateFormatted = datePicker.formatDate(datePicker.selectedDates[1], "Y-m-d"); } else { $('.search-date').addClass('error-validation'); errors['search-date'] = errorsMessages.noSecondDate; } } let stations = ''; const choicesStation = $('.choice-station option'); const departureStation = choicesStation.eq(0).attr('value'); const arrivalStation = choicesStation.eq(1).attr('value'); if (departureStation && arrivalStation) { stations = `&${link.departure(1)}=${departureStation}&${link.arrival(1)}=${arrivalStation}&${link.date(1)}=${firstDateFormatted}`; if (formMode === link.mode.roundtrip) { stations += `&${link.departure(2)}=${arrivalStation}&${link.arrival(2)}=${departureStation}&${link.date(2)}=${secondDateFormatted}` } } else { $('.stations').addClass('error-validation'); errors['stations'] = errorsMessages.noStations; } const adultsCount = $('input[name="adultsCounter"]').val(); const adults = `&${link.adults}=${adultsCount}`; let children = ''; let childrenAge = ''; const childrenCount = $('input[name="childrenCounter"]').val(); if (childrenCount > 0) { children = `&${link.children}=${childrenCount}`; const childrenWrappers = $('.children-age-wrapper'); for (let i = 0; i < childrenCount; i++) { const age = childrenWrappers.eq(i).find('.choices__item').attr('data-value'); if (age >= 0) { childrenAge += `&${link.childrenAge(i)}=${age}`; } else { $('.passengers').addClass('error-validation'); errors['passengers'] = errorsMessages.noChildrenAge; } } } const utmStations = `${$('.stations input.choices__input').eq(0).val()}-${$('.stations input.choices__input').eq(1).val()}`; const utmLink = `&query[${link.utmSource.name}]=${link.utmSource.value}&query[${link.utmMedium.name}]=${link.utmMedium.value}&query[${link.utmTerm.name}]=${utmStations}&query[${link.utmCampaign.name}]=${link.utmCampaign.value}`; if (Object.entries(errors).length !== 0) { renderErrorMessage(); return; } const redirectLink = `${domain}/?${link.mode.name}=` + formMode + stations + adults + children + childrenAge + utmLink; window.open(redirectLink, "_blank"); }); $('html, body').click(function (event) { if (!$(event.target).closest('.passengers').length && $('.passengers-dropdown').is(':visible')) { $('.passengers-dropdown').hide(); } }); $('.swap-stations').click(function () { const departureStation = $('.departure input.choices__input').val(); const departureCode = $('.departure select.choice-station option').val(); const arrivalStation = $('.arrival input.choices__input').val(); const arrivalCode = $('.arrival select.choice-station option').val(); $('.departure input.choices__input').val(arrivalStation); $('.arrival input.choices__input').val(departureStation); $('.departure select.choice-station option').val(arrivalCode); $('.arrival select.choice-station option').val(departureCode); const departureCitiesFilter = cities.filter(city => { if (city.value === +arrivalCode) { city.selected = true; } if (city.value !== +departureCode) { return city; } }); const arrivalCitiesFilter = cities.filter(city => { if (city.value === +departureCode) { city.selected = true; } if (city.value !== +arrivalCode) { return city; } }); departureChoices.setChoices(departureCitiesFilter, 'value', 'label', true); arrivalChoices.setChoices(arrivalCitiesFilter, 'value', 'label', true); }); $(window).resize(() => { let date = datePicker.selectedDates; if ($('#oneWayTrip').is(':checked')) { datePicker.set('mode', 'single'); datePicker.set('showMonths', 1); datePicker.destroy(); datePicker = $("#searchDate").flatpickr(flatpickrOptions); } else { if ($(window).width() > 725) { datePicker.set('showMonths', 2); } else { datePicker.set('showMonths', 1); datePicker.destroy(); datePicker = $("#searchDate").flatpickr(flatpickrOptions); } datePicker.set('mode', 'range'); } datePicker.setDate(date); }); });

Norway Train Routes | Domestic & International - NORWAY TRAINS (2024)

References

Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 5776

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.