'use strict'; let controller = null; let selectedSites = []; let keyword; let map; let markersArray = []; let activeWindow; let monday, tuesday, wednesday, thursday, friday, saturday, sunday; let morning, midday, afternoon, evening, all_day; let date_check, time_check, date_input, time_input; let userAddress, userAddress_Lat, userAddress_Lon, userRange; let uuid = null; let uip = null; let ulat = null; let ulon = null; let ulang = null; let logTimer; function getInputs() { keyword = $('#keyword_input').val(); monday = $('#check_dm').is(':checked'); tuesday = $('#check_dtu').is(':checked'); wednesday = $('#check_dw').is(':checked'); thursday = $('#check_dth').is(':checked'); friday = $('#check_df').is(':checked'); saturday = $('#check_dsa').is(':checked'); sunday = $('#check_dsu').is(':checked'); morning = $('#check_tmo').is(':checked'); midday = $('#check_tmi').is(':checked'); afternoon = $('#check_taf').is(':checked'); evening = $('#check_tev').is(':checked'); all_day = $('#check_t24').is(':checked'); date_check = $('#check_date').is(':checked'); time_check = $('#check_time').is(':checked'); date_input = $("#Filter_Date").val(); time_input = $("#Filter_Time").val(); } function clearMarkers() { for (let i = 0; i < markersArray.length; i++) { markersArray[i].setMap(null); } markersArray = []; } function closeInfoWindows() { } function getInitial() { const urlParams = new URLSearchParams(window.location.search); keyword = urlParams.get('keyword'); monday = urlParams.has('dm'); tuesday = urlParams.has('dtu'); wednesday = urlParams.has('dw'); thursday = urlParams.has('dth'); friday = urlParams.has('df'); saturday = urlParams.has('dsa'); sunday = urlParams.has('dsu'); morning = urlParams.has('tmo'); midday = urlParams.has('tmi'); afternoon = urlParams.has('taf'); evening = urlParams.has('tev'); all_day = urlParams.has('t24'); date_check = urlParams.has('date'); time_check = urlParams.has('time'); date_input = urlParams.get('date'); time_input = urlParams.get('time'); } function setInitial() { const urlParams = new URLSearchParams(window.location.search); $('#keyword_input').val(keyword); $('#check_dm').prop('checked', monday); $('#check_dtu').prop('checked', tuesday); $('#check_dw').prop('checked', wednesday); $('#check_dth').prop('checked', thursday); $('#check_df').prop('checked', friday); $('#check_dsa').prop('checked', saturday); $('#check_dsu').prop('checked', sunday); $('#check_tmo').prop('checked', morning); $('#check_tmi').prop('checked', midday); $('#check_taf').prop('checked', afternoon); $('#check_tev').prop('checked', evening); $('#check_t24').prop('checked', all_day); $('#check_date').prop('checked', date_check); $('#check_time').prop('checked', time_check); $('#check_date').val(date_input); $('#check_time').val(time_input); $('#Filter_Date').val(date_input); $('#Filter_Time').val(time_input); $.each($("input:checkbox[filtercategory='People Served']"), function () { $(this).prop('checked', urlParams.has($(this).attr("name"))); }); $.each($("input:checkbox[filtercategory='Food Offered']"), function () { $(this).prop('checked', urlParams.has($(this).attr("name"))); }); } function getResults() { $("#HeaderStripe").addClass("progress-bar-striped progress-bar-animated"); getInputs(); let encodedKeyword = encodeURIComponent(keyword); let urlPart = encodedKeyword; if (monday) urlPart += '&dm=on'; if (tuesday) urlPart += '&dtu=on'; if (wednesday) urlPart += '&dw=on'; if (thursday) urlPart += '&dth=on'; if (friday) urlPart += '&df=on'; if (saturday) urlPart += '&dsa=on'; if (sunday) urlPart += '&dsu=on'; if (morning) urlPart += '&tmo=on'; if (midday) urlPart += '&tmi=on'; if (afternoon) urlPart += '&taf=on'; if (evening) urlPart += '&tev=on'; if (all_day) urlPart += '&t24=on'; if (date_check) urlPart += ('&date=' + date_input); if (time_check) urlPart += ('&time=' + time_input); $.each($("input:checkbox[filtercategory='People Served']:checked"), function () { urlPart += ('&' + $(this).attr("name") + '=on'); }); $.each($("input:checkbox[filtercategory='Food Offered']:checked"), function () { urlPart += ('&' + $(this).attr("name") + '=on') }); let apiURL = '/api/search?keyword=' + urlPart; let pageURL = '/?keyword=' + urlPart; if (controller !== null) controller.abort(); controller = new AbortController(); fetch(apiURL, { signal: controller.signal }) .then((res) => res.json()) .then((data) => { $("#HeaderStripe").removeClass("progress-bar-striped progress-bar-animated"); window.history.replaceState({}, '', pageURL); clearMarkers(); $("#site_results").empty(); data.json_list.forEach(site => { if (userAddress == null || (calculateDistance(userAddress_Lat, userAddress_Lon, site.latitude, site.longitude, 'K') <= userRange)) { // data sanitization to prevent XSS let name = $('').text(site.site_name).html(); let description = $('').text(site.description).html(); let food_offered = $('').text(site.food_offered).html(); let people_served = $('').text(site.people_served).html(); let accessibility_level = $('').text(site.accessibility_level).html(); let accessibility_info = $('').text(site.accessibility_info).html(); let calendar_string = `${site.calendar_string}` // let calendar_string = $(calendar_stringHTML).text(site.calendar_string).html(); let contactText = ''; let contact_name = " | Main Contact Name: " + site.main_contact_name; let phone = " | Phone: " + site.main_contact_phone; let email = " | Email: " + site.main_contact_email; if (site.main_contact_name) contactText += contact_name; if (site.main_contact_phone) contactText += phone; if (site.main_contact_email) contactText += email; contactText = contactText.substring(3); contactText = $('').text(contactText).html(); if (contactText !== '') contactText = `${contactText}`; let siteUrl = ''; let preSanitzedUrl = site.url if (preSanitzedUrl) { if (preSanitzedUrl.search(/http:/i) == -1 && preSanitzedUrl.search(/https:/i) == -1) { preSanitzedUrl = "http://" + preSanitzedUrl } } siteUrl = $('').text(site.url).html(); if (siteUrl) siteUrl = `Website: ${siteUrl}`; let address = $('').text(site.address).html(); let city = $('').text(site.city).html(); let state = $('').text(site.state).html(); let zip = $('').text(site.zip).html(); let concat_address = $('').text(site.concat_address).html(); if (keyword) name = name.replace(new RegExp(keyword, "gi"), (match) => `${match}`); if (keyword) description = description.replace(new RegExp(keyword, "gi"), (match) => `${match}`); if (keyword) concat_address = concat_address.replace(new RegExp(keyword, "gi"), (match) => `${match}`); let eventBadge = (site.resource_type == 'One-time Event') ? 'Event' : ''; let summerBadge = (site.resource_type == 'Summer Meal Site') ? 'Summer Meal Site' : ''; let openNowBadge = site.open_now ? 'Open Now' : ''; let contents = `
${name}
${eventBadge} ${summerBadge} ${openNowBadge}
${concat_address}
 ${calendar_string}
People Served: ${people_served}
Food Offered: ${food_offered}
${accessibility_level}
${accessibility_info}
${description}
${contactText}
${siteUrl}
`; // const siteElement = $('