Usability fixes

This commit is contained in:
Augusto Gunsch 2021-12-26 14:46:40 -03:00
parent ef4043b07c
commit 5a84789c7b
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
2 changed files with 174 additions and 166 deletions

View File

@ -16,7 +16,7 @@
<div class="containter" id="main">
<form class="sticky-top" id="search-form">
<div class="ui-widget" id="search-widget">
<input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none">
<input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none" autofocus>
</div>
<button type="submit" class="ui-button ui-widget ui-button-icon-only" id="search">
<span class="ui-icon ui-icon-search"></span>

View File

@ -1,10 +1,20 @@
$(document).ready(() => {
let polishSchemas = null;
$.ajax({
url: '/static/schemas/polish.json',
success: data => polishSchemas = data
success: data => {
polishSchemas = data
if(window.location.hash) {
getWord();
}
}
});
window.onhashchange = () => {
getWord();
};
let searchBar = $('#search-bar');
searchBar.autocomplete({
@ -16,9 +26,8 @@ searchBar.autocomplete({
}
});
let bar = $('#search-bar')
bar.click((e) => {
bar[0].select();
$('#search-bar').on('focus', e => {
setTimeout(() => e.currentTarget.select(), 100);
});
$('#search-form').on('submit', (e) => {
@ -26,16 +35,18 @@ $('#search-form').on('submit', (e) => {
let word = e.target[0].value
getWord(word);
window.location.hash = `#${word}`;
});
function getWord(word) {
function getWord() {
let word = window.location.hash.replace('#', '');
$.ajax({
url: '/langs/polish/words/' + word,
success: (data) => {
$('#ajax-content').html(generateHtml(word, data))
searchBar.autocomplete('close');
window.scrollTo(0, 0);
},
error: err => console.error(err)
@ -145,7 +156,7 @@ function generateHtml(word, data) {
if('form_of' in sense) {
let word = sense.form_of[0].word;
html += sense.glosses[0].replace(new RegExp(`of ${word}$`), '');
html += ` of <a href="#" class="link-primary" onclick="getWord('${word}')">${word}</a>`;
html += ` of <a href="#${word}" class="link-primary">${word}</a>`;
} else {
html += sense.glosses[0];
}
@ -181,7 +192,4 @@ function generateHtml(word, data) {
return html;
}
$(document).ready(function() {
$('#search-bar').select();
});