1 2jQuery(function($) { 3 4 // Recherche par mot clé 5 function highlightWords( line, word ) { 6 var regex = new RegExp( '(' + word + ')', 'gi' ); 7 return line.replace( regex, "<strong style=\"color:#277f8b;\">$1</strong>" ); 8 } 9 10 11 12 var search_val; 13 var input_search_val; 14 15 if($('#motscle, #keywords_annuaire').length > 0) { 16 input_search_val = $('#motscle, #keywords_annuaire'); 17 18 input_search_val.keyup(function(e){ 19 e.preventDefault(); 20 search_val = input_search_val.val(); 21 }); 22 23 24 var listeMotCle = $('#formContacts .keywords'); 25 26 input_search_val.autocomplete({ 27 minLength: 2, 28 appendTo: listeMotCle, 29 delay: 500, 30 source: function(req, add){ 31 $('#formContacts .keywords input').addClass('loader'); 32 $.ajax({ 33 type: 'POST', 34 dataType: 'json', 35 url: ajaxurl_website, 36 data: { 37 action: 'mot_cle_contacts', 38 term: search_val 39 }, 40 success: function (data) { 41 $('#formContacts .no-results').hide(); 42 $('#formContacts .keywords input').removeClass('loader'); 43 if(data.length == 0) { 44 $('#formContacts .ui-autocomplete').hide(); 45 $('#formContacts .keywords input').removeClass('loader'); 46 $('#formContacts .no-results').show().delay(5000).fadeIn(400); 47 } else { 48 var suggestions = []; 49 $.each(data, function(i, val){ 50 suggestions.push({"label": val.label, "link": val.link, "cat": val.cat}); 51 }); 52 //pass array to callback 53 add(suggestions); 54 } 55 }, 56 error: function (data) { 57 $('#formContacts .keywords input').removeClass('loader'); 58 $('#formContacts .no-results').show().delay(5000).fadeIn(400); 59 } 60 }); 61 }, 62 select: function(event, ui) { 63 if(ui.item.link != '#'){ 64 window.open(ui.item.link); 65 } 66 } 67 }).data( "ui-autocomplete" )._renderMenu = function(ul, items) { 68 var that = this; 69 currentCategory = ""; 70 $.each( items, function( index, item ) { 71 var li; 72 if ( item.cat != currentCategory && item.cat != "") { 73 ul.append( "<div class='ui-autocomplete-category'><span>" + item.cat + " :</span></div>" ); 74 currentCategory = item.cat; 75 } 76 li = that._renderItemData( ul, item ); 77 if ( item.cat ) { 78 var html = highlightWords(item.label, search_val); 79 li.attr( "aria-label", item.cat + " : " + html ); 80 li.find('a').empty().html(html); 81 } 82 }); 83 }; 84 } 85 86});
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.