PageSourceSearch

https://infosecbulletin.com/wp-content/plugins/eventin-pro/assets/js/etn-location.js

js infosecbulletin.com collected 2026-10-04 10:58:53 UTC 15,556 bytes, 410 lines download raw bytes

1(function($) {
2    "use strict";
3
4    $(document).ready(function() {
5        let map_parent              = ".etn-front-map";
6        let map_container           = "#etn-front-map-container";
7        let location_result_field   = ".etn-location-result";
8        let map_result_wrapper      = ".etn_map_and_result_wrapper";
9        let loader_wrapper          = ".etn_loader_wrapper";
10        
11        let location_data       = localStorage.getItem('etn_location');
12        let default_loc         = '';
13        if(location_data !== null) {
14            var location_data_parse = JSON.parse(location_data);
15            default_loc = location_data_parse.value;
16            $('#etn_loc_address').val(default_loc);
17        }
18 
19        var map_settings = {
20            map_parent                  : map_parent,
21            map_container               : map_container,
22            location_result_field       : location_result_field,
23            map_result_wrapper          : map_result_wrapper,
24            loader_wrapper              : loader_wrapper,
25            lat                         : $(map_parent).data('lat'),
26            long                        : $(map_parent).data('long'),
27            zoom                        : $(map_parent).data('zoom'),
28            radius                      : $(map_parent).data('radius'),
29            redirect_url                : $(map_parent).data('redirect_url'),
30            markers                     : [],
31            radiusCircle                : {},
32        };
33
34        let geocoder = new google.maps.Geocoder();
35        map_settings.geocoder = geocoder;
36
37        if( $(map_container).length > 0 ) {
38            map_functions.locationMapFunctionalities($, map_settings, true);
39            if(default_loc != '') {
40                $('.etn_loc_address_search').trigger('click');
41            }
42        }
43
44        /**
45         * Get user default position of user
46         */
47        $('#etn_loc_my_position').on('click', function(e){
48            e.preventDefault();
49            map_functions.getMyPosition($, map_settings);
50        });
51
52        
53        /**
54         * Get nearest location on type
55         */
56        var etn_loc_address = $("#etn_loc_address");
57        
58        $(etn_loc_address).on("keyup",function(){
59            var location_keys = $(this).val();
60            if ( location_keys.length >= 3 ) {
61                get_auto_complete("etn_loc_address")
62            }
63        });
64
65        /**
66         * Get Address from googl api response
67         * @param {*} search_input 
68         */
69        function get_auto_complete(search_input) {
70            var autocomplete;
71            autocomplete = new google.maps.places.Autocomplete((document.getElementById(search_input)), {
72                types: ['geocode']
73               
74            });
75            
76            google.maps.event.addListener(autocomplete, 'place_changed', function () {
77                var near_place = autocomplete.getPlace();
78                if( $('.etn_loc_address_search').length > 0 ) {
79                    $('.etn_loc_address_search').trigger('click');
80                }
81            });
82        }
83
84        /**
85         * Search button click to find location
86         */
87        $('.etn_loc_address_search').on('click', function(e){
88            let address_val    = $('#etn_loc_address').val();
89
90            if(address_val) {
91                geocoder.geocode( {address: address_val}, function (res, status) {
92                    if(status === google.maps.GeocoderStatus.OK){
93                        let outLatLong      = res[0].geometry.location;
94                        map_settings.lat    = outLatLong.lat();
95                        map_settings.long   = outLatLong.lng();
96                        map_functions.locationMapFunctionalities($, map_settings, false, true);
97                        map_functions.locationSearchResult($, map_settings);
98                    }
99                });
100            } else {
101                alert('Location field is empty.');
102            }
103        });
104    });
105})(jQuery);
106
107var map_functions = {
108    // all map initialization functionalities
109    locationMapFunctionalities: function($, map_settings, initial=false, ajax_time=false) {
110        let container       = $(map_settings.map_container);
111        let zoom            = parseInt(map_settings.zoom);
112        let lat             = (map_settings.lat).toString();
113        let long            = (map_settings.long).toString();
114        let lat_array = [lat];
115        let long_array = [long];
116        if(lat !== ''){
117            if (lat.indexOf(',') > -1){
118                lat_array = lat.split(",");
119                lat = lat_array[0];
120            }            
121        }
122
123        if(long !== ''){
124            if (long.indexOf(',') > -1){
125                long_array = long.split(",");
126                long = long_array[0];
127            }
128        }        
129
130        if( !isNaN(lat) && !isNaN(long) ) {
131
132            // map drawing
133            let map_params = {
134                zoom        : zoom,
135                center      : new google.maps.LatLng(lat, long),
136                scrollwheel : false,
137            };
138
139            let d_map                    = new google.maps.Map(container[0], map_params);
140            map_settings.map             = d_map;
141            map_settings.currentPosition = map_params.center;
142
143            
144            // delete old marker
145            if(!map_functions.isEmptyFunc(map_settings.marker)) {
146                map_settings.marker.setMap(null);
147            }
148
149            // marker generate
150            let marker_params = {
151                icon      : etn_pro_public_object.location_icon,
152                map       : map_settings.map,
153                position  : new google.maps.LatLng(lat, long),
154                draggable : false,
155            };
156
157            let d_marker = new google.maps.Marker(marker_params);
158            d_marker.setMap(map_settings.map); 
159
160            map_settings.marker = d_marker;
161
162            // create markers
163            for(let i= 0; i<lat_array.length; i++){
164                let location = {};
165                location.icon      = etn_pro_public_object.location_icon;
166                location.map       = map_settings.map;
167                location.position  = new google.maps.LatLng(lat_array[i], long_array[i]);
168
169                marker = new google.maps.Marker(location);
170                map_settings.markers.push(marker);
171            }            
172
173            map_settings.map.addListener('tilesloaded', function () {
174                if(!ajax_time) {
175                    $(map_settings.map_result_wrapper).removeClass('etn_map_loading');
176                    $(map_settings.loader_wrapper).css({ 'display': 'none' });
177                }
178            } );
179        }
180    },
181    /**
182     * Get default position
183     *
184     * @param {*} $
185     * @param {*} address_field =
186     */
187    getMyPosition: function($, map_settings) {
188        if (navigator.geolocation) {
189
190            var options = {
191                enableHighAccuracy: true,
192                timeout           : 5000,
193                maximumAge        : 0
194            };
195
196            navigator.geolocation.getCurrentPosition(function(position) {
197                let address_field = $('#etn_loc_address');
198
199                let pos_coords = position.coords;
200                let lat        = pos_coords.latitude;
201                let long       = pos_coords.longitude;
202                map_settings.lat    = lat;
203                map_settings.long   = long;
204                var currentPosition = new google.maps.LatLng(lat, long);
205
206                map_functions.latLongToAddress($, map_settings, currentPosition, address_field);
207
208            }, function(error) {
209                alert('Only secure origins(HTTPS sites, basically) are allowed. To know more https://goo.gl/Y0ZkNV');
210            }, options);
211        }
212    },
213
214    // convert current position's lat, long to address
215    latLongToAddress: function($, map_settings, currentPosition, address_field) {
216        let lat_lng = {
217            lat: currentPosition.lat(), 
218            lng: currentPosition.lng()
219        };
220
221        map_settings.geocoder.geocode({'location': lat_lng}, function(res, status) {
222            if (status === google.maps.GeocoderStatus.OK) {
223                if(res[1]) {
224                    let res1_address            = res[1].address_components;
225                    let new_formatted_address   = res1_address[1].short_name + ' ' + res1_address[5].short_name + ', ' + res1_address[4].long_name;
226
227                    // address_field.val(res[1].formatted_address);
228                    address_field.val(new_formatted_address);
229                    map_functions.locationMapFunctionalities($, map_settings, false)
230                } else {
231                    window.alert('No result found');
232                }
233            } else {
234                window.alert('An error occured due to Geocoder failed.');
235            }
236        });
237    },
238
239    // location search result functionalities
240    locationSearchResult: function($, map_settings) {
241        // draw the circle of the search area
242        // map_functions.drawRadiusCircleFunc($, map_settings, true);
243
244        // get search specific locations
245        map_functions.getLocations($, map_settings);
246    },
247
248    // dynamic way zoom level from radius
249    radiusToZoom: function(radius){
250        return Math.round(14-Math.log(radius)/Math.LN2);
251    },
252
253    // check is empty or not
254    isEmptyFunc: function(obj) {
255
256        if (obj == null)		return true;
257        if (obj.length > 0)		return false;
258        if (obj.length === 0)	return true;
259
260        for (var key in obj) {
261            if (hasOwnProperty.call(obj, key)) return false;
262        }
263
264        return true;
265    },
266
267    // draw circle area in map
268    drawRadiusCircleFunc: function($, map_settings, inital) {
269        let mapRadius;
270        var earthRadius = 6371;
271
272        map_settings.earthRadi_mt                       = 6378100;
273        map_settings.mapDrawRadiusCircleFillColor       = '#004de8';
274        map_settings.mapDrawRadiusCircleFillOpacity     = 27;
275        map_settings.mapDrawRadiusCircleStrokeColor     = '#004de8';
276        map_settings.mapDrawRadiusCircleStrokeOpacity   = 62;
277
278        if(!map_functions.isEmptyFunc(map_settings.radiusCircle) && typeof(map_settings.radiusCircle.setMap) !== "undefined") {
279            map_settings.radiusCircle.setMap(null);
280        }
281
282        map_settings.map.setZoom(10);
283
284        mapRadius = (map_settings.radius / earthRadius) * map_settings.earthRadi_mt;
285        map_settings.radiusCircle = new google.maps.Circle({
286            center: map_settings.currentPosition,
287            clickable: true,
288            draggable: false,
289            editable: false,
290            fillColor: map_settings.mapDrawRadiusCircleFillColor,
291            fillOpacity: map_settings.mapDrawRadiusCircleFillOpacity / 100,
292            map: map_settings.map,
293            radius: mapRadius,
294            strokeColor: map_settings.mapDrawRadiusCircleStrokeColor,
295            strokeOpacity: map_settings.mapDrawRadiusCircleStrokeOpacity / 100,
296            strokeWeight: 1
297        });
298
299        if(inital !== true) {
300            map_settings.map.fitBounds(map_settings.radiusCircle.getBounds());
301        }
302
303        if(!map_functions.isEmptyFunc(map_settings.radiusCircle)) {
304            map_settings.map.addListener('idle', function () {
305                $(map_settings.map_result_wrapper).removeClass('etn_map_loading');
306                $(map_settings.loader_wrapper).css({ 'display': 'none' });
307            } );
308        }
309    },
310
311    // ajax call to calculate and get store locations
312    getLocations: function($, map_settings) {
313        $.ajax({
314            url: etn_pro_public_object.ajax_url,
315            type: 'post',
316            dataType: 'JSON',
317            data: {
318                action          : 'get_events_by_location',
319                security        : etn_pro_public_object.location_map_nonce,
320                lat             : map_settings.lat,
321                lng             : map_settings.long,
322                radius          : map_settings.radius,
323                limit           : $( '.etn-menu-location-wrap' ).data( 'etn-location-limit' ),
324                redirect_url    : map_settings.redirect_url,
325            },
326            beforeSend: function() {
327                $(map_settings.map_result_wrapper).addClass('etn_map_loading');
328                $(map_settings.loader_wrapper).css({ 'display': 'block' });
329            },
330            success: function(res) {
331                if(res.success){
332                    let data                 = res.data.data;
333                    let locations            = data.locations;
334                    let locations_html       = data.locations_html;
335                    let locations_html_data  = data.locations_html_data;
336                    let all_events_lat_lng   = data.all_events_lat_lng;
337                    
338
339                    if(locations_html != ''){
340
341                    } else {
342                        locations_html = res.data.message;
343                    }
344
345                    $(map_settings.location_result_field).html(locations_html);
346                    map_functions.createLocationMarkers($, map_settings, locations, locations_html_data, all_events_lat_lng);
347                }
348
349                map_functions.drawRadiusCircleFunc($, map_settings, true);
350            },
351            error: function(jqXHR, textStatus, errorThrown) {
352                map_functions.drawRadiusCircleFunc($, map_settings, true);
353
354                alert('An Error Occured: ' + jqXHR.status + ' ' + errorThrown + '! Please contact System Administrator!');
355            }
356        });
357    },
358
359    // location marker show in map
360    createLocationMarkers: function($, map_settings, locations, locations_html_data, all_events_lat_lng) {
361
362        //console.log(all_events_lat_lng);
363
364        // clean existing all markers
365        while(map_settings.markers.length){
366            map_settings.markers.pop().setMap(null);
367        }
368
369        let loc_len = Object.keys(all_events_lat_lng).length;
370        if(loc_len>0) {
371            let i = 0;
372            let location;
373            let marker;
374            let map = map_settings.map;
375
376            let info_window = new google.maps.InfoWindow({
377                content: ""
378            });
379
380            // create markers
381            for(i; i<loc_len; i++){
382
383                location           = all_events_lat_lng[i];
384                location.icon      = etn_pro_public_object.location_icon;
385                location.map       = map;
386                location.position  = new google.maps.LatLng(all_events_lat_lng[i].lat, all_events_lat_lng[i].lng);
387
388                marker = new google.maps.Marker(location);
389                map_settings.markers.push(marker);
390
391                map_functions.createInfoWindow($, map_settings, marker, map, info_window, location, locations_html_data[i]);
392            }
393        }
394    },
395
396    // in map, clicking marker icon will toggle marker specific information
397    createInfoWindow: function($, map_settings, marker, map, info_window, location, location_html) {
398        marker.addListener('click', function() {
399            info_window.setContent(location_html);
400            info_window.open(map, this);
401
402            google.maps.event.addListener(map, 'click', function() {
403                info_window.close();
404            });
405            google.maps.event.addListener(map_settings.radiusCircle, 'click', function() {
406                info_window.close();
407            });
408        });
409    },
410};

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.