1/** 2 * ESS Geolocation - Frontend JavaScript. 3 * City autocomplete, map toggle, and AJAX directory search. 4 */ 5jQuery(document).ready(function($) { 6 7 // City autocomplete using jQuery UI if available, fallback to simple AJAX. 8 if ($.fn.autocomplete) { 9 $('.ess-city-autocomplete').autocomplete({ 10 source: function(request, response) { 11 $.ajax({ 12 url: essGeo.ajaxUrl, 13 dataType: 'json', 14 data: { 15 action: 'ess_search_cities', 16 nonce: essGeo.nonce, 17 term: request.term 18 }, 19 success: function(data) { 20 response(data); 21 } 22 }); 23 }, 24 minLength: 2, 25 select: function(event, ui) { 26 $(this).val(ui.item.value); 27 return false; 28 } 29 }); 30 } else { 31 // Simple fallback: datalist-based autocomplete. 32 var $inputs = $('.ess-city-autocomplete'); 33 $inputs.each(function() { 34 var $input = $(this); 35 var listId = 'ess-cities-list-' + Math.random().toString(36).substr(2, 9); 36 var $datalist = $('<datalist id="' + listId + '"></datalist>'); 37 $input.attr('list', listId).after($datalist); 38 39 var timer; 40 $input.on('input', function() { 41 clearTimeout(timer); 42 var val = $input.val(); 43 if (val.length < 2) return; 44 45 timer = setTimeout(function() { 46 $.ajax({ 47 url: essGeo.ajaxUrl, 48 data: { 49 action: 'ess_search_cities', 50 nonce: essGeo.nonce, 51 term: val 52 }, 53 success: function(data) { 54 $datalist.empty(); 55 data.forEach(function(item) { 56 $datalist.append('<option value="' + item.value + '">'); 57 }); 58 } 59 }); 60 }, 300); 61 }); 62 }); 63 } 64 65 // Chosen.js initialization for multi-selects. 66 if ($.fn.chosen) { 67 $('.chosen-select').chosen({ 68 width: '100%', 69 no_results_text: 'Aucun résultat pour', 70 placeholder_text_multiple: ' ' 71 }); 72 } 73 74 // AJAX directory search widget. 75 $('.ess-directory-search-btn').on('click', function(e) { 76 e.preventDefault(); 77 var $widget = $(this).closest('.ess-directory-widget'); 78 var city = $widget.find('.ess-city-autocomplete').val(); 79 var thematic = $widget.data('thematic'); 80 81 $.ajax({ 82 url: essGeo.ajaxUrl, 83 data: { 84 action: 'ess_search_structures', 85 nonce: essGeo.nonce, 86 city: city, 87 areaKm: 30, 88 thematic: thematic ? [thematic] : [] 89 }, 90 success: function(data) { 91 var $results = $widget.find('.ess-directory-results'); 92 $results.empty(); 93 94 if (data.results && data.results.length) { 95 data.results.forEach(function(s) { 96 var html = '<div class="card mb-2"><div class="card-body p-2">'; 97 html += '<a href="' + s.url + '"><strong>' + s.title + '</strong></a>'; 98 if (s.locality) html += '<br><small class="text-muted">' + s.locality + '</small>'; 99 html += '</div></div>'; 100 $results.append(html); 101 }); 102 } else { 103 $results.html('<p>Aucune structure trouvée.</p>'); 104 } 105 } 106 }); 107 }); 108});
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.