Add not found message

This commit is contained in:
Augusto Gunsch 2021-12-26 11:47:57 -03:00
parent 4c01f546b5
commit b81849a63a
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
1 changed files with 51 additions and 43 deletions

View File

@ -29,7 +29,7 @@ function getWord(word) {
url: '/langs/polish/words/' + word,
success: (data) => {
$('#ajax-content').html(generateHtml(data))
$('#ajax-content').html(generateHtml(word, data))
searchBar.autocomplete('close');
},
@ -108,9 +108,12 @@ function generateTable(schemas, pos, forms) {
return html;
}
function generateHtml(data) {
function generateHtml(word, data) {
let html = '';
if(data.length === 0) {
html += `<h1>Not found: <mark>${word}</mark></h1>`;
} else {
data.forEach(entry => {
html += `<h1>${entry.word} <span class="pos">(${entry.pos})</span></h1>`
if('senses' in entry) {
@ -161,6 +164,11 @@ function generateHtml(data) {
}
}
});
}
return html;
}
$(document).ready(function() {
$('#search-bar').select();
});