diff --git a/static/index.js b/static/index.js
index ee41e0f..92d1d2c 100644
--- a/static/index.js
+++ b/static/index.js
@@ -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,59 +108,67 @@ function generateTable(schemas, pos, forms) {
return html;
}
-function generateHtml(data) {
+function generateHtml(word, data) {
let html = '';
- data.forEach(entry => {
- html += `
${entry.word} (${entry.pos})
`
- if('senses' in entry) {
- if('tags' in entry.senses[0]) {
- html += ''
- html += entry.senses[0].tags.map(tag => `${tag}`).join(', ');
- html += '
'
+ if(data.length === 0) {
+ html += `Not found: ${word}
`;
+ } else {
+ data.forEach(entry => {
+ html += `${entry.word} (${entry.pos})
`
+ if('senses' in entry) {
+ if('tags' in entry.senses[0]) {
+ html += ''
+ html += entry.senses[0].tags.map(tag => `${tag}`).join(', ');
+ html += '
'
+ }
+
+ html += 'Senses
';
+
+ html += '';
+ entry.senses.forEach(sense => {
+ html += '- '
+
+ if('form_of' in sense) {
+ let word = sense.form_of[0].word;
+ html += sense.glosses[0].replace(new RegExp(`of ${word}$`), '');
+ html += ` of ${word}`;
+ } else {
+ html += sense.glosses[0];
+ }
+
+ html += '
';
+ })
+ html += '
';
}
- html += 'Senses
';
+ if('forms' in entry) {
+ if(entry.pos === 'verb') {
+ let conjugation = entry.forms.filter(form =>
+ 'source' in form && form.source === 'Conjugation');
- html += '';
- entry.senses.forEach(sense => {
- html += '- '
+ if(conjugation.length > 0) {
+ html += '
Conjugation
';
- if('form_of' in sense) {
- let word = sense.form_of[0].word;
- html += sense.glosses[0].replace(new RegExp(`of ${word}$`), '');
- html += ` of ${word}`;
+ html += generateTable(polishSchemas, entry.pos, conjugation);
+ }
} else {
- html += sense.glosses[0];
- }
+ let declension = entry.forms.filter(form =>
+ 'source' in form && form.source === 'Declension');
- html += ' ';
- })
- html += '
';
- }
+ if(declension.length > 0) {
+ html += 'Declension
';
- if('forms' in entry) {
- if(entry.pos === 'verb') {
- let conjugation = entry.forms.filter(form =>
- 'source' in form && form.source === 'Conjugation');
-
- if(conjugation.length > 0) {
- html += 'Conjugation
';
-
- html += generateTable(polishSchemas, entry.pos, conjugation);
- }
- } else {
- let declension = entry.forms.filter(form =>
- 'source' in form && form.source === 'Declension');
-
- if(declension.length > 0) {
- html += 'Declension
';
-
- html += generateTable(polishSchemas, entry.pos, declension);
+ html += generateTable(polishSchemas, entry.pos, declension);
+ }
}
}
- }
- });
+ });
+ }
return html;
}
+
+$(document).ready(function() {
+ $('#search-bar').select();
+});