/** * Global vars */ var map, geocoder; /** * Run on document load */ $(document).ready(function () { // set default course selection if (typeof SELECTED_COURSE !== 'undefined') { setCourse(SELECTED_COURSE); } if (typeof SELECTED_HOLES !== 'undefined') { setHoles(SELECTED_HOLES); } $('#tee-times-form #holes').on('change', function () { getLoops(); }) $('#tee-times-form select, #tee-times-form input').on('change', function () { $('#tee-times-form').submit(); }) }) /** * @param element */ function calculateNewTotal(element) { // calculate total price per person var $dataElement = $('#refundable'); var pricePerPerson = $dataElement.data('price-per-person'); var totalPersons = $dataElement.data('amount-persons'); var discount = $dataElement.data('amount-discount'); var cancellationFee = parseInt($dataElement.val()); // remove any discount if user has a subscription if (discount > 0) { pricePerPerson = pricePerPerson * ((100 - discount) / 100); } pricePerPerson = Math.floor(pricePerPerson); var total = pricePerPerson.toFixed(2) * totalPersons; // add cancellation fee if checked if ($dataElement.is(':checked')) { total = total + cancellationFee; } $('#price-per-person').html(formatPrice(pricePerPerson / 100)); $('#price-total').html(formatPrice(total / 100)); } /** * Format price to a Dutch string * @param price * @returns {string} */ function formatPrice(price) { var formattedPrice = price.toFixed(2); // formattedPrice = formattedPrice.replace('.00', '.-'); formattedPrice = formattedPrice.replace('.', ','); return '€ ' + formattedPrice; } /** * Open google maps in a nice modal */ function openGoogleMaps() { $('#modal-courses').remove(); $.get(URL_GET_MODAL, function (modal) { $('body').append(modal); $('#modal-courses').modal(); var mapOptions = { zoom: 8, scrollwheel: false, center: new google.maps.LatLng(52.091259, 5.122750), disableDefaultUI: true, zoomControl: true, styles: [ { "featureType": "administrative", "elementType": "labels.text.fill", "stylers": [ { "color": "#444444" } ] }, { "featureType": "administrative.country", "elementType": "geometry", "stylers": [ { "visibility": "on" } ] }, { "featureType": "administrative.country", "elementType": "labels.text", "stylers": [ { "weight": "0.01" }, { "saturation": "100" } ] }, { "featureType": "landscape", "elementType": "all", "stylers": [ { "color": "#f2f2f2" } ] }, { "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "road", "elementType": "all", "stylers": [ { "saturation": -100 }, { "lightness": 45 } ] }, { "featureType": "road.highway", "elementType": "all", "stylers": [ { "visibility": "simplified" } ] }, { "featureType": "road.arterial", "elementType": "labels.icon", "stylers": [ { "visibility": "off" } ] }, { "featureType": "transit", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "water", "elementType": "all", "stylers": [ { "color": "#99d4d4" }, { "visibility": "on" } ] } ] }; // load google maps geocoder = new google.maps.Geocoder(); map = new google.maps.Map(document.getElementById('modal-courses__map'), mapOptions); $(COURSES).each(function (key, course) { placeMarker(course); }); $('#modal-course__search').fadeIn('fast'); }) } /** * Place markers * @param course */ function placeMarker(course) { // if there is a lat/lng within the course - use that if (typeof course.data.lat !== 'undefined') { var marker = new google.maps.Marker({ position: {lat: course.data.lat, lng: course.data.lng}, icon: '/igolf/img/marker.svg', map: map }); var infowindow = getInfoWindow(course); marker.addListener('click', function () { infowindow.open(map, marker); }); // fetch location from Google API } else { var address = []; for (var key in course.data.address) { address.push(course.data.address[key]); } geocoder.geocode({'address': address.join(', ')}, function (results, status) { if (status === "OK") { var marker = new google.maps.Marker({ position: results[0].geometry.location, icon: '/igolf/img/marker.svg', map: map }); var infowindow = getInfoWindow(course); marker.addListener('click', function () { infowindow.open(map, marker); }); } }); } } /** * Position course map based on search */ function positionCourseMap() { $('#modal-course-keyword__error').remove(); geocoder.geocode({'address': $('#modal-course-keyword').val()}, function (results, status) { if (status === "OK") { map.setZoom(12); map.panTo(results[0].geometry.location) } else { $('#modal-course-keyword').after('