PageSourceSearch

https://recruitandco.com/wp-content/plugins/wp-jobsearch/js/jquery.location-autocomplete.js?ver=3.3.8

js recruitandco.com collected 2026-10-06 06:46:42 UTC 22,317 bytes, 434 lines download raw bytes

1var jobsearch_autosugg_ajxreq;
2jQuery.fn.extend({
3    cityAutocomplete: function (options) {
4
5        if (jobsearch_plugin_vars.locmap_type == 'mapbox') {
6
7            var mapbox_acces_token = jobsearch_plugin_vars.mapbox_token;
8            var mapbox_style_url = jobsearch_plugin_vars.mapbox_style;
9            if (mapbox_acces_token != '' && mapbox_style_url != '') {
10
11                
12            }
13
14        } else if (jobsearch_plugin_vars.locmap_type == 'openstreet') {
15            return this.each(function() {
16                var input = jQuery(this);
17                var predictionsDropDown = jQuery('<div class="jobsearch_location_autocomplete" class="city-autocomplete"></div>').appendTo(jQuery(this).parent());
18                var request_var = 1;
19
20                input.off('keyup');
21                input.on('keyup', function() {
22                    jQuery(this).parent(".jobsearch_searchloc_div").find('.loc-loader').html("<i class='fa fa-refresh fa-spin'></i>");
23                    if (request_var == 1) {
24                        var searchStr = jQuery(this).val();
25                        // Min Number of characters
26                        var num_of_chars = 0;
27                        if (searchStr.length > num_of_chars) {
28                            updateLeafletPredictions(input);
29                        } else {
30                            jQuery(".jobsearch_searchloc_div").find('.loc-loader').html('');
31                        }
32                    }
33                });
34
35                predictionsDropDown.delegate('div', 'click', function() {
36                    // Informational rows (geocoding error) must not fill the input.
37                    if (jQuery(this).hasClass('jobsearch-locsugg-error')) {
38                        predictionsDropDown.hide();
39                        return;
40                    }
41                    if (jQuery(this).text() != jobsearch_plugin_vars.var_address_str && jQuery(this).text() != jobsearch_plugin_vars.var_other_locs_str) {
42                        var jobsearch_address_html = jQuery(this).text();
43                        var jobsearch_address_slug = jQuery(this).find('span').html();
44                        jQuery(this).find('span').remove();
45                        input.val(jQuery(this).text());
46                        input.trigger('change');
47                        input.next('.loc_search_keyword').val(jobsearch_address_slug);
48                        predictionsDropDown.hide();
49                        input.next('.loc_search_keyword').closest("form.side-loc-srch-form").submit();
50                    }
51                });
52
53                jQuery(document).mouseup(function(e) {
54                    predictionsDropDown.hide();
55                });
56
57                jQuery(window).resize(function() {
58                    updatePredictionsDropDownDisplay(predictionsDropDown, input);
59                });
60
61                updatePredictionsDropDownDisplay(predictionsDropDown, input);
62
63                function updateLeafletPredictions(input) {
64                    if (typeof jobsearch_autosugg_ajxreq !== undefined && jobsearch_autosugg_ajxreq != undefined) {
65                        jobsearch_autosugg_ajxreq.abort();
66                    }
67                    predictionsDropDown.empty();
68
69                    // Use Nominatim (OpenStreetMap) for geocoding
70                    var nominatimUrl = 'https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(input.val()) + '&limit=5';
71
72                    jobsearch_autosugg_ajxreq = jQuery.ajax({
73                        type: "GET",
74                        url: nominatimUrl,
75                        dataType: "json",
76                        beforeSend: function() {
77                            jQuery(".jobsearch_searchloc_div").find('.loc-loader').html("<i class='fa fa-refresh fa-spin'></i>");
78                        }
79                    });
80
81                    jobsearch_autosugg_ajxreq.done(function(data) {
82                        jQuery(".jobsearch_searchloc_div").find('.loc-loader').html('');
83                        predictionsDropDown.empty();
84                        
85                        if (data && data.length > 0) {
86                            var osm_results = '<div class="address_headers"><h5>' + jobsearch_plugin_vars.var_address_str + '</h5></div>';
87                            
88                            jQuery.each(data, function(index, item) {
89                                var display_name = item.display_name;
90                                if (display_name.length > 50) {
91                                    display_name = display_name.substring(0, 50) + '...';
92                                }
93                                osm_results += '<div class="jobsearch_google_suggestions"><i class="icon-location-arrow"></i> ' + 
94                                    display_name + '<span style="display:none">
94' + item.lat + ',' + item.lon + '</span></div>';
95                            });
96                            
97                            predictionsDropDown.append(osm_results);
98                        } else {
99                            predictionsDropDown.append('<div class="no-results">No results found</div>');
100                        }
101                        
102                        request_var = 1;
103                    });
104
105                    jobsearch_autosugg_ajxreq.fail(function(jqXHR, textStatus) {
106                        jQuery(".jobsearch_searchloc_div").find('.loc-loader').html('');
107                        predictionsDropDown.append('<div class="error-results">Error fetching results</div>');
108                    });
109
110                    predictionsDropDown.show();
111                }
112
113                return input;
114            });
115        } else {
116
117            return this.each(function () {
118                var input = jQuery(this);
119                var predictionsDropDown = jQuery('<div class="jobsearch_location_autocomplete" class="city-autocomplete"></div>').appendTo(jQuery(this).parent());
120                var request_var = 1;
121
122                input.off('keyup');
123
124                input.on('keyup', function () {
125
126                    jQuery(this).parent(".jobsearch_searchloc_div").find('.loc-loader').html("<i class='fa fa-refresh fa-spin'></i>");
127                    if (request_var == 1) {
128                        var searchStr = jQuery(this).val();
129                        // Min Number of characters
130                        var num_of_chars = 0;
131                        if (searchStr.length > num_of_chars) {
132                            updatePredictions(input);
133                        } else {
134                            jQuery(".jobsearch_searchloc_div").find('.loc-loader').html('');
135                        }
136                    }
137                });
138                predictionsDropDown.delegate('div', 'click', function () {
139                    // The geocoding error row is informational only: never put it in
140                    // the input, just close the suggestions box.
141                    if (jQuery(this).hasClass('jobsearch-locsugg-error')) {
142                        predictionsDropDown.hide();
143                        return;
144                    }
145                    if (jQuery(this).text() != jobsearch_plugin_vars.var_address_str && jQuery(this).text() != jobsearch_plugin_vars.var_other_locs_str) {
146                        var loc_lat = jQuery(this).attr('data-lat');
147                        var loc_lng = jQuery(this).attr('data-lng');
148                        // address with slug
149                        var jobsearch_address_html = jQuery(this).text();
150                        // slug only
151                        var jobsearch_address_slug = jQuery(this).find('span').html();
152                        // remove slug
153                        jQuery(this).find('span').remove();
154                        input.val(jQuery(this).text());
155                        input.trigger('change');
156                        input.next('.loc_search_keyword').val(jobsearch_address_slug);
157                        predictionsDropDown.hide();
158                        input.next('.loc_search_keyword').closest("form.side-loc-srch-form").submit();
159                        if (input.next('.jobsearch-hiden-latlng').length) {
160                            input.next('.jobsearch-hiden-latlng').val(loc_lat + ',' + loc_lng);
161                        } else {
162                            input.after('<input type="hidden" class="jobsearch-hiden-latlng" value="' + loc_lat + ',' + loc_lng + '">');
163                        }
164                    }
165                });
166                jQuery(document).mouseup(function (e) {
167                    predictionsDropDown.hide();
168                });
169                jQuery(window).resize(function () {
170                    updatePredictionsDropDownDisplay(predictionsDropDown, input);
171                });
172                updatePredictionsDropDownDisplay(predictionsDropDown, input);
173                function updatePredictions(input) {
174
175                    if (typeof jobsearch_autosugg_ajxreq !== undefined && jobsearch_autosugg_ajxreq != undefined) {
176                        jobsearch_autosugg_ajxreq.abort();
177                    }
178                    predictionsDropDown.empty();
179                    // AJAX GET Locations
180                    var dataString = 'action=jobsearch_get_google_autocomplete_locations&_nonce=' + jobsearch_comon_script_vars.nonce + '&keyword=' + input.val();
181                    var plugin_url = jobsearch_plugin_vars.ajax_url;
182                    jobsearch_autosugg_ajxreq = jQuery.ajax({
183                        type: "POST",
184                        url: plugin_url,
185                        data: dataString,
186                    });
187
188                    jobsearch_autosugg_ajxreq.done(function (data) {
189                        jQuery(".jobsearch_searchloc_div").find('.loc-loader').html('');
190                        var result = jQuery.parseJSON(data);
191                        var loc_results = result.locs;
192                        var gloc_results = result.glocs;
193                        predictionsDropDown.empty();
194                        if (gloc_results != '') {
195                            var google_results = '<div class="address_headers"><h5>' + jobsearch_plugin_vars.var_address_str + '</h5></div>';
196                            jQuery(gloc_results).each(function (key, gplace_obj) {
197                                let value = gplace_obj.description;
198                                let plc_lat = gplace_obj.lat;
199                                let plc_lng = gplace_obj.lng;
200                                google_results += '<div class="jobsearch_google_suggestions" data-lat="' + plc_lat + '" data-lng="' + plc_lng + '"><i class="icon-location-arrow"></i> ' + value + '<span style="display:none">
200' + value + '</span></div>';
201                            });
202                            predictionsDropDown.append(google_results);
203                        }
204                        if (loc_results != '') {
205                            predictionsDropDown.append('<div class="address_headers"><h5>' + jobsearch_plugin_vars.var_address_str + '</h5></div>');
206                            jQuery(loc_results).each(function (key, value) {
207                                if (value.hasOwnProperty('child')) {
208                                    jQuery(value.child).each(function (child_key, child_value) {
209                                        predictionsDropDown.append('<div class="jobsearch_location_child">' + child_value.value + '<span style="display:none">' + child_value.slug + '</span></div');
210                                    })
211                                } else {
212                                    predictionsDropDown.append('<div class="jobsearch_location_parent">' + value.value + '<span style="display:none">' + value.slug + '</span></div');
213                                }
214                            });
215                        }
216                        // Show the geocoding error (e.g. "This IP ... is not authorized to
217                        // use this API key") inside the same suggestions box. It is a
218                        // MESSAGE ONLY: it uses its own class so the suggestion click
219                        // handlers never pick it up / append it to the address field, and
220                        // clicking it just closes the box.
221                        var geo_err = (typeof result.geo_err !== 'undefined' && result.geo_err) ? result.geo_err : '';
222                        if (typeof geo_err === 'string' && geo_err !== '') {
223                            predictionsDropDown.append('<div class="jobsearch-locsugg-error">' + geo_err + '</div>');
224                        }
225                        request_var = 1;
226                    });
227
228                    jobsearch_autosugg_ajxreq.fail(function (jqXHR, textStatus) {
229                        jQuery(".jobsearch_searchloc_div").find('.loc-loader').html('');
230                    });
231
232                    predictionsDropDown.show();
233                }
234                return input;
235            });
236        }
237    }
238});
239
240// Clicking the geocoding error message only closes the suggestions box — it is
241// informational and must never be appended to the address field.
242jQuery(document).on('click', '.jobsearch-locsugg-error', function (e) {
243    e.stopPropagation();
244    jQuery(this).closest('.jobsearch_location_autocomplete').hide();
245});
246
247function updatePredictionsDropDownDisplay(dropDown, input) {
248    if (typeof (input.offset()) !== 'undefined') {
249        dropDown.css({
250            'width': input.outerWidth(),
251            'left': input.offset().left,
252            'top': input.offset().top + input.outerHeight()
253        });
254    }
255}
256
257function jobsearch_fulladres_to_city_contry(geoData) {
258    // debugger;
259    var region, countryName, placeName, returnStr;
260    if (geoData.context) {
261        $.each(geoData.context, function (i, v) {
262            if (v.id.indexOf('region') >= 0) {
263                region = v.text;
264            }
265            if (v.id.indexOf('country') >= 0) {
266                countryName = v.text;
267            }
268        });
269    }
270    if (region && countryName) {
271        returnStr = region + ", " + countryName;
272    } else {
273        returnStr = geoData.place_name;
274    }
275    return returnStr;
276}
277
278jQuery(document).on('click', '.jobsearch_search_location_field', function() {
279    jQuery('.jobsearch_search_location_field').cityAutocomplete();
280});
281jQuery(document).on('click', '.jobsearch_searchloc_div', function () {
282    jQuery('.jobsearch_search_location_field').prop('disabled', false);
283});
284jQuery(document).on('change', '.jobsearch_search_location_field', function () {
285    var this_new_loc = jQuery(this).val();
286
287    //if (typeof jobsearch_listing_dataobj !== 'undefined') {
288        var locMapType = jobsearch_plugin_vars.locmap_type;
289        if (locMapType == 'mapbox') {
290            var mapbox_access_token = jobsearch_plugin_vars.mapbox_token;
291            var map_addrapi_uri = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + encodeURI(this_new_loc) + '.json?access_token=' 
291+ mapbox_access_token;
292            jobsearch_common_getJSON(map_addrapi_uri, function (new_loc_status, new_loc_response) {
293                if (typeof new_loc_response === 'object') {
294                    var new_cords = new_loc_response.features[0].geometry.coordinates;
295                    if (new_cords !== 'undefined') {
296                        jobsearch_listing_map.flyTo({
297                            center: new_cords,
298                        });
299                    }
300                }
301            });
302        } else if (locMapType == 'openstreet') {
303            var nominatimUrl = 'https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(this_new_loc) + '&limit=1';
304            
305            jobsearch_common_getJSON(nominatimUrl, function(new_loc_status, new_loc_response) {
306                if (new_loc_response.length > 0) {
307                    var new_cords = [parseFloat(new_loc_response[0].lat), parseFloat(new_loc_response[0].lon)];
308                    if (typeof jobsearch_listing_map !== 'undefined') {
309                        jobsearch_listing_map.flyTo(new_cords, jobsearch_listing_map.getZoom());
310                        
311                        // Update marker position if needed
312                        if (typeof markers !== 'undefined' && markers.length > 0) {
313                            markers[0].setLatLng(new_cords);
314                        } else {
315                            // Create new marker if none exists
316                            var marker = L.marker(new_cords).addTo(jobsearch_listing_map);
317                            markers = [marker];
318                        }
319                        
320                        // Update hidden fields if they exist
321                        if (typeof rand_num !== 'undefined') {
322                            document.getElementById("jobsearch_location_lat_" + rand_num).value = new_cords[0];
323                            document.getElementById("jobsearch_location_lng_" + rand_num).value = new_cords[1];
324                        }
325                    }
326                }
327            });
328        } else {
329            //console.log(map);
330            if (typeof map !== 'undefined') {
331                jobsearch_on_google_addr_change_setcenter(map, this_new_loc, jQuery(this));
332            }
333            if (typeof jobsearch_listing_map !== 'undefined') {
334                jobsearch_on_google_addr_change_setcenter(jobsearch_listing_map, this_new_loc, jQuery(this));
335            }
336        }
337    //}
338});
339
340function jobsearch_on_google_addr_change_setcenter(mapobj, new_addr_str, $input) {
341
342    setTimeout(function() {
343        var hid_latlng_field = $input.next('.jobsearch-hiden-latlng');
344        // console.log(hid_latlng_field);
345        // console.log(hid_latlng_field.attr('class'));
346        // console.log($input.attr('class'));
347        if (hid_latlng_field.length && hid_latlng_field.val() != '') {
348            var [new_latitude, new_longitude] = hid_latlng_field.val().split(',').map(coord => parseFloat(coord));
349
350            if (typeof rand_num !== 'undefined') {
351                document.getElementById("jobsearch_location_lat_" + rand_num).value = new_latitude;
352                document.getElementById("jobsearch_location_lng_" + rand_num).value = new_longitude;
353            }
354            //
355            var newLatLng = {lat: new_latitude, lng: new_longitude};
356            mapobj.setCenter(newLatLng);//center the map over the result
357
358            if (typeof markers !== 'undefined') {
359                // clear markers
360                for (var i = 0; i < markers.length; i++) {
361                    markers[i].setMap(null);
362                }
363
364                //place a marker at the location
365                var marker = new google.maps.marker.AdvancedMarkerElement({
366                    map: mapobj,
367                    position: newLatLng,
368                    gmpDraggable: true,
369                });
370
371                markers.push(marker);
372
373                google.maps.event.addListener(marker, 'dragend', function (event) {
374                    if (typeof rand_num !== 'undefined') {
375                        document.getElementById("jobsearch_location_lat_" + rand_num).value = this.getPosition().lat();
376                        document.getElementById("jobsearch_location_lng_" + rand_num).value = this.getPosition().lng();
377                    }
378                });
379            }
380        }
381    }, 400);
382}
383
384function jobsearch_on_google_addr_change_setcenter__bkup(mapobj, new_addr_str) {
385    var geocoder = new google.maps.Geocoder();
386    geocoder.geocode({address: new_addr_str}, function (results, status) {
387
388        //console.log(status);
389        if (status == google.maps.GeocoderStatus.OK) {
390            var new_latitude = results[0].geometry.location.lat();
391            var new_longitude = results[0].geometry.location.lng();
392            if (typeof rand_num !== 'undefined') {
393                document.getElementById("jobsearch_location_lat_" + rand_num).value = new_latitude;
394                document.getElementById("jobsearch_location_lng_" + rand_num).value = new_longitude;
395            }
396            //
397            mapobj.setCenter(results[0].geometry.location);//center the map over the result
398
399            if (typeof markers !== 'undefined') {
400                // clear markers
401                for (var i = 0; i < markers.length; i++) {
402                    markers[i].setMap(null);
403                }
404
405                //place a marker at the location
406                var marker = new google.maps.marker.AdvancedMarkerElement({
407                    map: mapobj,
408                    position: results[0].geometry.location,
409                    gmpDraggable: true,
410                });
411
412                markers.push(marker);
413
414                google.maps.event.addListener(marker, 'dragend', function (event) {
415                    if (typeof rand_num !== 'undefined') {
416                        document.getElementById("jobsearch_location_lat_" + rand_num).value = this.getPosition().lat();
417                        document.getElementById("jobsearch_location_lng_" + rand_num).value = this.getPosition().lng();
418                    }
419                });
420            }
421        }
422    });
423}
424
425jQuery(document).on('click', 'form', function () {
426    var src_loc_val = jQuery(this).find('.jobsearch_search_location_field');
427    src_loc_val.next('.loc_search_keyword').val(src_loc_val.val());
428    //
429    if (jQuery('.jobsearch-filter-keywordsrch').length > 0) {
430        var srch_keyword_val = jQuery(this).find('.jobsearch-keywordsrch-inp-field').val();
431        jQuery('.jobsearch-filter-keywordsrch').find('.jobsearch-keywordsrch-filinp-field').val(srch_keyword_val);
432        jQuery('.jobsearch-filter-keywordsrch').find('.jobsearch-keywordsrch-filinp-field').attr('value', srch_keyword_val);
433    }
434});

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.