This commit is contained in:
Robbie Andrew
2024-07-08 15:23:10 +02:00
parent 63db8a4bba
commit 6fca0266d0
2 changed files with 13 additions and 5 deletions

View File

@@ -729,7 +729,7 @@
},
"United Kingdom": {
"isoCode":"GBR",
"variants":["United Kingdom of Great Britain and Northern Ireland (the)","Royaume-Uni de Grande-Bretagne et d'Irlande du Nord (le)","Reino Unido de Gran Bretaña e Irlanda del Norte (el)","Соединенное Королевство Великобритании и Северной Ирландии","大不列颠及北爱尔兰联合王国","المملكة المتحدة لبريطانيا العظمى وأيرلندا الشمالية","the United Kingdom of Great Britain and Northern Ireland","le Royaume-Uni de Grande-Bretagne et d'Irlande du Nord","el Reino Unido de Gran Bretaña e Irlanda del Norte","Соединенное Королевство Великобритании и Северной Ирландии","大不列颠及北爱尔兰联合王国","المملكة المتحدة لبريطانيا العظمى وأيرلندا الشمالية"]
"variants":["United Kingdom of Great Britain and Northern Ireland (the)","Royaume-Uni de Grande-Bretagne et d'Irlande du Nord (le)","Reino Unido de Gran Bretaña e Irlanda del Norte (el)","Соединенное Королевство Великобритании и Северной Ирландии","大不列颠及北爱尔兰联合王国","المملكة المتحدة لبريطانيا العظمى وأيرلندا الشمالية","the United Kingdom of Great Britain and Northern Ireland","le Royaume-Uni de Grande-Bretagne et d'Irlande du Nord","el Reino Unido de Gran Bretaña e Irlanda del Norte","Соединенное Королевство Великобритании и Северной Ирландии","大不列颠及北爱尔兰联合王国","المملكة المتحدة لبريطانيا العظمى وأيرلندا الشمالية","UK"]
},
"Tanzania": {
"isoCode":"TZA",

View File

@@ -14,7 +14,7 @@ fetch('https://robbieandrew.github.io/data/countryData.json')
([code, data]) => ({
mainName: code,
isoCode: data.isoCode,
variants: [code, ...data.variants]
variants: [code, data.isoCode, ...data.variants]
})
);
// Initialize autocomplete after data is loaded
@@ -160,8 +160,16 @@ function autocomplete(inp) {
let currentFocus = -1;
const showResults = debounce((inputValue) => {
const lowerInput = inputValue.toLowerCase();
const listContainer = document.getElementById("autocomplete-list");
// Clear the list and hide it if the input is empty
if (!inputValue.trim()) {
listContainer.innerHTML = '';
listContainer.style.display = 'none';
return;
}
const lowerInput = inputValue.toLowerCase();
// Score and sort the matches
const scoredMatches = flatCountryData
.map(item => {
@@ -176,11 +184,11 @@ function autocomplete(inp) {
.sort((a, b) => b.score - a.score)
.slice(0, MAX_RESULTS);
const listContainer = document.getElementById("autocomplete-list");
listContainer.innerHTML = '';
currentFocus = -1;
if (scoredMatches.length > 0) {
listContainer.style.display = 'block';
const fragment = document.createDocumentFragment();
scoredMatches.forEach((item, index) => {
const div = document.createElement("div");