1window.LocationFinder=function(data,el="#locatiezoeker",options={}){let lf={main:null,inputElement:null,listElement:null,listTemplate:null,searchElement:null,searchTemplate:null,selectedValue:null,defaultPageSize:options.pageSize??20,pageSize:options.pageSize??20,infiniteScroll:options.infiniteScroll??!0,onlyGoogleMatch:options.onlyGoogleMatch??!1,enableFuzzyMatch:!0,userPos:{},data,pc:[],callbackRun:!1,updateListCallBack:options.updateListCallBack||null,map:null,googleService:null,_googleSearchTimeout:null,_lastGoogleQuery:"",_googleDelay:300,_lang:window.locationFinderLang||[],lang(key){return this._lang[key]||key},init(el){this.main=document.querySelector(el);this.inputElement=this.main.querySelector(".locatiezoeker__search input");this.listElement=this.main.querySelector(".locatiezoeker__list");this.listTemplate=this.main.querySelector(".locatiezoeker__list template#location-tpl");this.locationDetailTemplate=this.main.querySelector(".locatiezoeker__list template#location-detail-tpl")||null;this.searchTemplate=this.main.querySelector(".locatiezoeker__list template#search-tpl");this.searchElement=this.main.querySelector(".locatiezoeker__search-result");this.selectedLocation=this.main.querySelector("#location_id")||null;if(window.sessionStorage.getItem("userPos")!==null){this.userPos=JSON.parse(window.sessionStorage.getItem("userPos"))} 2this.parseTimes();this.updateList();this.inputElement.addEventListener("input",()=>{this.updateList();this.listElement.scrollTop=0;this.pageSize=this.defaultPageSize});this.listElement.addEventListener("scroll",(evt)=>{if(this.infiniteScroll===!0){let scrollProgress=((this.listElement.scrollTop+this.listElement.clientHeight)/this.listElement.scrollHeight)*100;if(scrollProgress>90){this.pageSize+=this.defaultPageSize;this.updateList()}}});const gpsBtn=document.querySelector("#get-location");if(gpsBtn){gpsBtn.addEventListener("click",()=>{navigator.geolocation.getCurrentPosition((pos)=>{this.userPos=pos.coords;sessionStorage.setItem("userPos",JSON.stringify(this.userPos));this.updateList(!0);this.setLocation(this.userPos.latitude,this.userPos.longitude)},(e)=>{},{enableHighAccuracy:!0,timeout:10000})})}},setLocation(lat,lon,zoom=10){if(this.map!==null){this.map.setCenter({lat:parseFloat(lat),lng:parseFloat(lon)});this.map.setZoom(zoom);this.listElement.classList.add("has-selected");this.updateList(!0);if(this.googleService.userMarker!==null){this.googleService.userMarker.position={lat:parseFloat(lat),lng:parseFloat(lon)}}}},setUserLocation(details){this.userPos={latitude:details.geometry.location.lat(),longitude:details.geometry.location.lng(),details,};console.log(details) 3sessionStorage.setItem("userPos",JSON.stringify(this.userPos));this.setLocation(this.userPos.latitude,this.userPos.longitude,9);this.inputElement.value=details.formatted_address;this.updateList(!0)},updateList(silent=!1){const value=this.inputElement.value?.trim().toLowerCase()??"";const useFuzzy=this.enableFuzzyMatch===!0;let displayData;if(this.userPos.latitude&&this.userPos.longitude){displayData=this.data.map((loc)=>{const dist=Math.floor(this.getDistance(loc));return{...loc,address2:`${loc.address2} (~ ${dist}km)`,dist,}}).sort((a,b)=>a.dist-b.dist)}else if(window.lang){const prioCountry=window.lang==="fr"?"be":window.lang;displayData=[...this.data.filter((x)=>x.country?.toLowerCase()===prioCountry.toLowerCase()),...this.data.filter((x)=>x.country?.toLowerCase()!==prioCountry.toLowerCase()),];const pref=sessionStorage.getItem("userPrefferedOffice");if(pref){displayData=[...displayData.filter((x)=>x.cdn_id===pref),...displayData.filter((x)=>x.cdn_id!==pref)]}}else{displayData=[...this.data]} 4const fuzzyScore=(haystack,needle)=>{let h=0;for(let n=0;n<needle.length;n++){h=haystack.indexOf(needle[n],h);if(h===-1)return!1;h++} 5return!0};const getMatchScore=(item)=>{if(!value)return 0;const fields=[item.post_title,item.city].filter(Boolean).map((v)=>v.toLowerCase());if(fields.some((v)=>v.startsWith(value)))return 0;if(fields.some((v)=>v.includes(value)))return 1;if(useFuzzy&&fields.some((v)=>fuzzyScore(v,value)))return 2;return 3};let data=[...displayData].sort((a,b)=>{const scoreDiff=getMatchScore(a)-getMatchScore(b);if(scoreDiff!==0)return scoreDiff;if(a.dist!=null&&b.dist!=null){return a.dist-b.dist} 6return 0});data=[...new Map(data.map((m)=>[m.id??m.post_title,m])).values()].slice(0,this.pageSize);if(this.googleService!==null&&silent===!1){if(value.length>3||(value.length>=1&&this.onlyGoogleMatch===!0)){clearTimeout(this._googleSearchTimeout);if(value===this._lastGoogleQuery)return;this._googleSearchTimeout=setTimeout(()=>{this._lastGoogleQuery=value;this.googleService.searchPlace(value).then((result)=>{if(this.inputElement.value.trim().toLowerCase()!==value)return;const predictions=result?.predictions?.slice(0,3)??[];this.listElement.innerHTML=this.searchTemplate.innerHTML.interpolateArray(predictions);this.callbackRun=!1}).catch((err)=>{console.warn("Google search failed",err)})},this._googleDelay);return}} 7if(this.onlyGoogleMatch===!0&&!(this.userPos.latitude&&this.userPos.longitude)){return} 8this.listElement.innerHTML=this.listTemplate.innerHTML.interpolateArray(data);if(this.updateListCallBack!==null){this.updateListCallBack(data)}},oldupdateList(silent=!1){let value=this.inputElement.value?.trim()?.toLowerCase()??"";let displayData;if(this.userPos.latitude&&this.userPos.longitude){displayData=this.data.map((loc)=>{let dist=Math.floor(this.getDistance(loc));return{...loc,address2:`${loc.address2} (~ ${dist}km)`,dist}}).sort(function(a,b){return a.dist-b.dist})}else{if(window.lang){let prioCountry=window.lang==="fr"?"be":window.lang;displayData=[...this.data.filter((x)=>x.country.toLowerCase()===prioCountry.toLowerCase()),...this.data.filter((x)=>x.country.toLowerCase()!==prioCountry.toLowerCase()),];if(sessionStorage.getItem("userPrefferedOffice")!==null){displayData=[...displayData.filter((x)=>x.cdn_id===sessionStorage.getItem("userPrefferedOffice")),...displayData.filter((x)=>
8x.cdn_id!==sessionStorage.getItem("userPrefferedOffice")),]}}else{displayData=this.data}} 9let data=[...displayData.filter((x)=>x.post_title.toLowerCase().indexOf(value)!==-1||x.city.toLowerCase().indexOf(value)!==-1||x.address.toLowerCase().indexOf(value)!==-1),...displayData.filter((x)=>x.post_title.toLowerCase().indexOf(value)===-1||x.city.toLowerCase().indexOf(value)===-1||x.address.toLowerCase().indexOf(value)===-1),];data=[...new Map(data.map((m)=>[m.post_title,m])).values()].slice(0,this.pageSize);let searchResults="";if(this.googleService!==null&&silent===!1){if(value.length>3||(value.length>=1&&this.onlyGoogleMatch===!0)){clearTimeout(this._googleSearchTimeout);if(value===this._lastGoogleQuery){return} 10this._googleSearchTimeout=setTimeout(()=>{this._lastGoogleQuery=value;this.googleService.searchPlace(value).then((result)=>{if(this.inputElement.value!==value)return;const predictions=result?.predictions?.slice(0,3)??[];this.listElement.innerHTML=this.searchTemplate.innerHTML.interpolateArray(predictions);this.callbackRun=!1}).catch((err)=>{console.warn("Google search failed",err)})},this._googleDelay);return}else{searchResults=""}}else{searchResults=""} 11if(this.onlyGoogleMatch===!0&&!(this.userPos.latitude&&this.userPos.longitude)){return} 12if(this.updateListCallBack!==null){this.listElement.innerHTML=this.listTemplate.innerHTML.interpolateArray(data);this.updateListCallBack(data)}else{this.listElement.innerHTML=this.listTemplate.innerHTML.interpolateArray(data)}},select(id){let location=this.data.find((x)=>parseInt(x.id)===parseInt(id));if(this.selectedLocation!==null){this.selectedLocation.value=location.id} 13this.setLocation(location.lat,location.lon);sessionStorage.setItem("userPrefferedOffice",location.cdn_id);const el=document.querySelector("#gw-loc-"+id);if(el){el.click()} 14this.inputElement.value=location.post_title;this.updateList(!0)},parseTimes(){let weekday;const weekdays={nl:["zo","ma","di","wo","do","vr","za"],be:["zo","ma","di","wo","do","vr","za"],de:["so","mo","di","mi","do","fr","sa"],fr:["dim","lun","mar","mer","jeu","ven","sam"],};weekday=weekdays[window.lang]||weekdays.nl;const d=new Date();const doubleds=(n)=>(n<10?"0"+n:n);const todayShort=weekday[d.getDay()];const todayKey=`${d.getFullYear()}${doubleds(d.getMonth() + 1)}${doubleds(d.getDate())}`;const todayDateStr=`${d.getFullYear()}-${doubleds(d.getMonth() + 1)}-${doubleds(d.getDate())}`;const closedText=this.lang("gesloten").trim().toLowerCase();const getNextOpenDayInfo=(openingHours,currentTodayKey)=>{const sortedKeys=Object.keys(openingHours).sort();for(const key of sortedKeys){if(key!==currentTodayKey){const dayInfo=openingHours[key];if(dayInfo&&dayInfo.text?.toLowerCase()!==closedText){const time=dayInfo.from?.split(":")??["9","00"];return `${this.lang(dayInfo.day_long.toLowerCase())} ${this.lang("om")} ${time[0]}:${time[1]}`}}} 15return""};this.data=this.data.filter((loc)=>loc!==null&&loc.opening_hours!==null&&typeof loc.opening_hours==="object"&&loc.lat!==""&&loc.lon!=="").map((loc)=>{let todaysHours=loc.opening_hours[todayKey];if(!todaysHours){todaysHours=Object.values(loc.opening_hours).find((oh)=>oh?.day_short?.toLowerCase()===todayShort.toLowerCase())} 16if(!todaysHours||todaysHours.text?.toLowerCase()===closedText){return{...loc,openStateClass:"text--rood",openState:this.lang("gesloten"),openInfo:getNextOpenDayInfo(loc.opening_hours,todayKey),}} 17const fromTimeStr=todaysHours.from||"10:00";const toTimeStr=todaysHours.to||"17:00";const fromTime=new Date(`${todayDateStr} ${fromTimeStr}`);const toTime=new Date(`${todayDateStr} ${toTimeStr}`);const minutesUntilClose=Math.round((toTime.getTime()-d.getTime())/60000);const closeAtFormatted=`${toTime.getHours()}:${doubleds(toTime.getMinutes())}`;if(d>=fromTime&&d<toTime){const isClosingSoon=minutesUntilClose<=60;return{...loc,openStateClass:isClosingSoon?"text--cta-geel":"text--groen",openState:isClosingSoon?this.lang("sluit_binnenkort"):this.lang("geopend"),openInfo:isClosingSoon?`${this.lang("open_tot")} ${closeAtFormatted}`:`${this.lang("sluit_om")} ${closeAtFormatted}`,}}else if(d<fromTime){const time=fromTimeStr.split(":")??["9","00"];
17return{...loc,openStateClass:"text--rood",openState:this.lang("gesloten"),openInfo:`${this.lang(todaysHours.day_long.toLowerCase())} ${this.lang("om")} ${time[0]}:${time[1]}`,}}else{return{...loc,openStateClass:"text--rood",openState:this.lang("gesloten"),openInfo:getNextOpenDayInfo(loc.opening_hours,todayKey),}}})},getDistance(cord){const R=6371;const userLat=this.userPos.latitude;const userLon=this.userPos.longitude;const pointLat=cord.lat??cord.latitude;const pointLon=cord.lon??cord.longitude;if(!userLat||!userLon||!pointLat||!pointLon){return Infinity} 18if(userLat===pointLat&&userLon===pointLon){return 0} 19const toRad=(deg)=>deg*(Math.PI/180);const dLat=toRad(pointLat-userLat);const dLon=toRad(pointLon-userLon);const a=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.cos(toRad(userLat))*Math.cos(toRad(pointLat))*Math.sin(dLon/2)*Math.sin(dLon/2);const c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return R*c},};lf.init(el);return lf}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.