PageSourceSearch

https://www.voaok.org/wp-content/plugins/voa-housing-map//public/js/voa-custom-housing-map-public.js?ver=1.2

js voaok.org collected 2026-10-04 05:24:23 UTC 16,731 bytes, 486 lines download raw bytes

1(function( $ ) {
2
3
4    $( document ).ready(function() {
5
6        //Handle Check for zipcode or city
7        function isValidUSZip(sZip) {
8            return /^\d{5}(-\d{4})?$/.test(sZip);
9        }
10
11        //enable tool tips
12        $('[data-toggle="tooltip"]').tooltip();
13
14        var housing_locations = document.querySelectorAll('.housing-location');
15
16        var location_pins = [];
17        //set map marks are global array
18        var markers = []; 
19
20        //check and show map
21        if($('#housingMap').length > 0){
22
23            initMap();
24        }
25
26        $('#disabilities').on( 'click', function (event) {
27
28            event.preventDefault();
29
30            hideLocations('persons-with-disabilities');
31
32            $('.filter-buttons a').removeClass('opacity');
33            $('.filter-buttons a').addClass('opacity');
34            $(this).removeClass('opacity');
35        
36        });
37
38        $('#families').on( 'click', function (event) {
39
40            event.preventDefault();
41
42            hideLocations('families');
43
44
45            $('.filter-buttons a').removeClass('opacity');
46            $('.filter-buttons a').addClass('opacity');
47            $(this).removeClass('opacity');
48
49        });
50
51        $('#seniors').on( 'click', function (event) {
52            
53            event.preventDefault();
54
55            hideLocations('older-adults');
56
57            $('.filter-buttons a').removeClass('opacity');
58            $('.filter-buttons a').addClass('opacity');
59            $(this).removeClass('opacity');
60
61        });
62
63        $('#reset').on( 'click', function (event) {
64
65            event.preventDefault();
66
67            $('.housing-location').show();
68            $('.filter-buttons a').removeClass('opacity');
69            $('#reset').hide();
70
71            const PROPERTYCOUNT = $(`.housing-location`).length;
72
73            let propertyText = $(`.housing-location`).length > 1 ? 'Properties' : 'Property';
74
75            $('#totalLocations').text( PROPERTYCOUNT + " " + propertyText );
76
77            resetMap();
78
79        });
80
81        $('#resetSearch').on( 'click', function (event) {
82            
83            event.preventDefault();
84
85            resetLocations();
86            clearOverlays();
87            initMap();
88            $('#resetSearch').addClass('d-none');
89            $('.housing-location .housing-locations-distance').text('');
90
91        });
92
93        //HANDLE FORM SUBMIT WITH AJAX with BLUR
94        $('#thriftZipCode').blur( function() {
95
96            var location_names = [];
97
98            var thrift_locations = document.querySelectorAll('.housing-location');
99
100            thrift_locations.forEach( ( item , index ) => {
101
102                let location_name = item.getAttribute('data-location-name');
103
104                location_names.push(location_name);
105
106            });
107
108            var search = $('#thriftZipCode').val().trim();
109        
110            var distance = "250";
111        
112            //check if valid zip code
113            if ( isValidUSZip(search) ) {
114        
115                var zipRequest = JSON.stringify(search);
116
117                var locationNameRequest = JSON.stringify(location_names);
118
119                $('.error-message').text('');
120        
121            } else{
122                $('.error-message').text('Invalid Zip Code, please try again..');
123            }
124                    
125            if( search !== "" ) {
126        
127                $('#Error').html('<p></p>');
128                var searchDistance = JSON.stringify(distance);
129                var api_url = `${website_url}/api/TSL/`;
130                $.ajax({
131                    url:  `${api_url}`,
132                    type: "POST", 
133                    data : {
134                        action: 'run_ajax',
135                        zip: zipRequest,
136                        distance: searchDistance,
137                        location_names: locationNameRequest
138                    },
139                    success: function( response ) {
140        
141                        if ( response.results.length > 0 ) {
142                            resetLocations();
143                            let totalHousing = response.results.length;
144                            let property = totalHousing == 1 ? "Property" : "Properties";
145                            $('#totalLocations').text(` ${totalHousing} ${property}`);
146                            updateHousingLocationsByDistance(response);
147                            $("#resetSearch").removeClass('d-none');
148
149                        } else {
150                            resetLocations();
151                            clearOverlays();
152                            resetMap();
153                            $('.error-message').text('NO LOCATIONS FOUND, please try again');
154                            $("#resetSearch").removeClass('d-none');
155                            $('#resetSearch').addClass('d-none');
156                            $('.housing-location .housing-locations-distance').text('');
157
158                        }
159
160                    },
161                        error: function(error){
162                            console.log('error: ', error);
163                        }
164                })
165            }
166        });
167        
168        // MAP FUNCTIONS
169        function resetMap(){
170
171            clearOverlays();
172
173            createPins();
174
175            map.setCenter( {
176                lat: location_pins[0]['lat'],
177                lng: location_pins[0]['lng']
178            });
179
180            setMarkers(false);
181
182        }
183
184        //clear markers during map reset
185        function clearOverlays() {
186            if (markers) {
187                for (i in markers) {
188                    markers[i].setMap(null);
189                }
190            }
191        }
192
193        function resetLocations(){
194            //remove to get clean results
195            $('.housing-location').show();
196            $('.housing-location').data('data-position', '');
197            $('.housing-location').removeClass('valid-zip-location');
198            let totalHousing = $('.housing-location').length;
199            let property = totalHousing == 1 ? "Property" : "Properties";
200            $('#totalLocations').text(` ${totalHousing} ${property}`);
201        }
202
203        function updateHousingLocationsByDistance( response ) {
204
205            if( response.results.length > 0 ) {
206
207                location_pins = [];
208
209                let matching_locations = response.results;
210
211                for ( let i = 0; i < matching_locations.length; i++ ) {
212
213                    let position = i + 1;
214
215                    let distance = Math.round(matching_locations[i]['distance'],2);
216
217                    var thrift_locations = document.querySelectorAll('.housing-location');
218
219                    $('.housing-location').hide();
220
221                    thrift_locations.forEach( ( item , index ) => {
222
223                        let location_name = item.getAttribute('data-location-name');
224                        let google_maps_directions_url = '';
225                        
226                        if ( item.getAttribute('data-lat') !== '' || item.getAttribute('data-lng') !== '' ) {
227
228                            google_maps_directions_url = item.getAttribute('data-google-maps-directions-url');
229                        
230                        }
231                        
232                        if ( matching_locations[i]['name'] == location_name ) {
233
234                            item.classList.add('valid-zip-location');
235                            item.setAttribute('data-position', position);
236                            item.setAttribute('data-zip-distance', distance );
237
238                            let lat = item.getAttribute('data-lat');
239                            let lng = item.getAttribute('data-lng');
240
241                            let marker_data = ` <a href="${item.getAttribute('data-url')}">
242                                    <h3 class='small-heading'>${item.getAttribute('data-location-name')}</h3>
243                                </a>
244                                <p class='thrift-text'>${item.getAttribute('data-address-line-1')}<br>${item.getAttribute('data-address-line-2')}</p>
245                                <p class='thrift-text'>${item.getAttribute('data-phone')}</p>
246                                <p class='thrift-text'>${item.getAttribute('data-zip-distance')} Miles</p>`;
247
248                            if ( google_maps_directions_url !== '' ) {
249                                console.log(google_maps_directions_url);
250                                marker_data += `<a class='rollover-link-thrift' href="${google_maps_directions_url}" target="_blank">Get Directions ></a>`;
251
252                            }else {
253                                console.log('data google maps url is empty');
254                            }
255                
256                            location_pins.push({
257                                'lat': parseFloat(lat),
258                                'lng': parseFloat(lng),
259                                'marker_html': marker_data,
260                                'marker_label': { color:'#fff', 
261                                    fontSize: '18px', 
262                                    text: `${position} `, 
263                                },
264                
265                            })
266                        
267                        }
268        
269                    });
270
271                    $('.housing-location.valid-zip-location').each(function(){
272
273                        var distance = $(this).attr('data-zip-distance');
274                        $(this).find('.housing-locations-distance').text(`Distance: ${distance} miles`);
275                      });
276
277                    $('.housing-location.valid-zip-location').show();
278
279                    
280
281                    sortData();
282
283                    clearOverlays();
284
285                    map.setCenter( {
286                        lat: location_pins[0]['lat'],
287                        lng: location_pins[0]['lng']
288                    });
289        
290                    setMarkers(true);
291
292                    
293
294                }
295
296            }  else {
297                clearOverlays();
298                resetMap();
299            }
300
301        }
302
303        function comparator(a, b) {
304            if (a.dataset.position < b.dataset.position)
305                return -1;
306            if (a.dataset.position > b.dataset.position)
307                return 1;
308            return 0;
309        }
310        
311        // Function to sort Data
312        function sortData() {
313            var indexes = document.querySelectorAll(".housing-location.valid-zip-location");
314            var indexesArray = Array.from(indexes);
315            let sorted = indexesArray.sort(comparator);
316            sorted.forEach(e =>
317                document.querySelector(".housing-locations").appendChild(e));
318        }
319        
320        //hide locations based on which service you clicked
321        function hideLocations( filter ) {
322
323            const PROPERTYCOUNT = $(`.housing-location.${filter}`).length;
324
325            let propertyText = $(`.housing-location.${filter}`).length > 1 ? 'Properties' : 'Property';
326
327            $('.housing-location').hide();
328            $(`.housing-location.${filter}`).show();
329
330
331            //update location amount heading
332            $('#totalLocations').text( PROPERTYCOUNT + " " + propertyText );
333
334            //show reset locations button
335            $('#reset').removeClass('d-none');
336            $('#reset').show();
337
338            //update map marker pins
339
340            clearOverlays();
341
342            let filtered_locations  = document.querySelectorAll(`.housing-location.${filter}`);
343
344            location_pins = [];
345
346            filtered_locations.forEach( location => {
347
348                let lat = location.getAttribute('data-lat');
349                let lng = location.getAttribute('data-lng');
350
351                let google_maps_directions_url = '';
352
353                let marker_data = ` <a href="${location.getAttribute('data-url')}">
354                                        <h3 class='small-heading'>${location.getAttribute('data-location-name')}</h3>
355                                    </a>
356                                    <p class='thrift-text'>${location.getAttribute('data-address-line-1')}<br>${location.getAttribute('data-address-line-2')}</p>
357                                    <p class='thrift-text'>${location.getAttribute('data-phone')}</p>`
358 
359                if ( location.getAttribute('data-lat') !== '' || location.getAttribute('data-lng') !== '' ) {
360
361                    google_maps_directions_url = location.getAttribute('data-google-maps-directions-url');
362
363                    marker_data += `<a class='rollover-link-thrift' href="${google_maps_directions_url}" target="_blank">Get Directions ></a>`;
364                
365                }
366                
367                location_pins.push({
368                    'lat': parseFloat(lat),
369                    'lng': parseFloat(lng),
370                    'marker_html': marker_data,
371                })
372                
373                });
374
375                setMarkers(false);
376
377        }
378
379        //initializing Map creation
380        function initMap() {
381
382            createPins();
383
384            const housing_center = {    
385                lat: location_pins[0]['lat'],
386                lng: location_pins[0]['lng'] 
387            };
388
389            // The map, centered at First Housing Location
390            map = new google.maps.Map(document.getElementById("housingMap"), {
391            zoom: 7,
392            center: housing_center,
393            });
394
395            setMarkers(false);
396
397        }
398
399        //create map pins
400        function createPins(){
401            //set all pins
402            housing_locations.forEach( location => {
403
404                let lat = location.getAttribute('data-lat');
405                let lng = location.getAttribute('data-lng');
406                let google_maps_directions_url = location.getAttribute('data-google-maps-directions-url');
407  
408                if ( lat !== '' || lng !== '' ||  google_maps_directions_url !== '' ) {
409
410                    google_maps_directions_url = location.getAttribute('data-google-maps-directions-url');
411                
412                }
413
414                let marker_data = ` <a href="${location.getAttribute('data-url')}">
415                                            <h3 class='small-heading'>${location.getAttribute('data-location-name')}</h3>
416                                        </a>
417                                        <p class='thrift-text'>${location.getAttribute('data-address-line-1')}<br>${location.getAttribute('data-address-line-2')}</p>
418                                        <p class='thrift-text'>${location.getAttribute('data-phone')}</p>
419                                        <p class='thrift-text'>${location.getAttribute('data-zip-distance')}</p>`;
420
421                if ( google_maps_directions_url !== '' ) {
422                    marker_data += `<a class='rollover-link-thrift' href="${google_maps_directions_url}" target="_blank">Get Directions ></a>`;
423                }
424    
425                location_pins.push({
426                    'lat': parseFloat(lat),
427                    'lng': parseFloat(lng),
428                    'marker_html': marker_data,
429    
430                })
431                
432            });
433        }
434        //set markers for initial and map resets
435
436        function setMarkers( distance = false){
437
438            let infowindow = new google.maps.InfoWindow();
439            var bounds = new google.maps.LatLngBounds();
440            let label_info = '';
441            
442            //push all pins when loading in map
443
444            
445            for ( let i = 0; i < location_pins.length; i++ ) {
446
447                if ( distance == true ) {
448
449                    label_info = location_pins[i]['marker_label'];
450                
451                }
452
453                let marker = new google.maps.Marker( {
454                    position: {
455                        lat: location_pins[i]['lat'], 
456                        lng: location_pins[i]['lng'],
457                    },
458                    label: label_info,
459                    
460                    //icon: image_marker,
461                    map: map,
462                });
463
464                bounds.extend(marker.getPosition());
465
466                google.maps.event.addListener( marker, 'click', ( function( marker, i ) {
467                    return function() { 
468
469                        infowindow.setContent( location_pins[i]['marker_html'] );
470                        infowindow.open(map, marker);
471
472                    }
473                })(marker,i));
474                markers.push(marker);
475                map.fitBounds(bounds);
476                
477            }
478            if(location_pins.length == 1){
479                map.setZoom(14);
480            }
481        }
482        
483    });
484
485
486})( jQuery );

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.