1function initAutocomplete(endpoint) { 2 /* MaterializeCSS Autocomplete Search */ 3 4 var href, newData; 5 var autocomplete = $('.person-input'); 6 7 autocomplete.on('keyup', function (e) { 8 var val = $(this).val().toLowerCase(); 9 if(val.length > 2) { 10 var url = endpoint + "?search=" + val; 11 $.ajax({ 12 type: 'GET', 13 url: url, 14 success: function (data) { 15 if (!$.isEmptyObject(data)) { 16 newData = data.reduce(function (result, item) { 17 if (item.payload.image) { 18 result[item.text] = item.payload.image.url 19 } else { 20 result[item.text] = "/images/placeholder_per.svg" 21 } 22 return result; 23 }, {}); 24 href = data.reduce(function (result, item) { 25 if (item.payload.personId) { 26 result[item.text] = "/" + item.payload.personId 27 } else { 28 result[item.text] = "" 29 } 30 return result; 31 }, {}); 32 33 /* init all instances */ 34 const acs = document.querySelectorAll('.person-input'); 35 [].forEach.call(acs, function(ac) { 36 let instance = M.Autocomplete.getInstance(ac); 37 instance.updateData(newData) 38 }); 39 } 40 } 41 }); 42 } 43 if(val.length <= 3) { 44 href = null 45 newData = null 46 const acs = document.querySelectorAll('.person-input'); 47 [].forEach.call(acs, function(ac) { 48 let instance = M.Autocomplete.getInstance(ac); 49 instance.updateData(newData) 50 }); 51 } 52 }); 53 54 autocomplete.autocomplete({ 55 onAutocomplete: function(val) { 56 window.location.href = href[val]; 57 } 58 }); 59}
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.