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