|
|
@ -30,14 +30,28 @@ function rebuildSuggestions() { |
|
|
|
var trainNumber = trainNumberInput.value.trim() |
|
|
|
var trainNumber = trainNumberInput.value.trim() |
|
|
|
|
|
|
|
|
|
|
|
var suggestions = [] |
|
|
|
var suggestions = [] |
|
|
|
|
|
|
|
if (!trainNumber) { |
|
|
|
|
|
|
|
suggestions = knownTrains.slice() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
for (var i = 0; i < knownTrains.length; i++) { |
|
|
|
for (var i = 0; i < knownTrains.length; i++) { |
|
|
|
if (trainNumber) { |
|
|
|
|
|
|
|
if (!knownTrains[i].number.includes(trainNumber)) { |
|
|
|
if (!knownTrains[i].number.includes(trainNumber)) { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
suggestions.push(knownTrains[i]) |
|
|
|
suggestions.push(knownTrains[i]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
suggestions.sort((s1, s2) => { |
|
|
|
|
|
|
|
if (s1.number.indexOf(trainNumber) != s2.number.indexOf(trainNumber)) { |
|
|
|
|
|
|
|
return s1.number.indexOf(trainNumber) - s2.number.indexOf(trainNumber); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (s1.number.length != s2.number.length) { |
|
|
|
|
|
|
|
return s1.number.length - s2.number.length; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return s1.number.localeCompare(s2.number); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
suggestions.forEach(function (suggestion, index) { |
|
|
|
suggestions.forEach(function (suggestion, index) { |
|
|
|
var suggestionLi = document.createElement('li') |
|
|
|
var suggestionLi = document.createElement('li') |
|
|
|