From ea389f4b1c28df071fb04ea10abc2f29fd2e1192 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Wed, 12 Jan 2022 08:04:19 -0300 Subject: [PATCH] Improve state management --- static/index.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/static/index.js b/static/index.js index ed326b4..29d9249 100644 --- a/static/index.js +++ b/static/index.js @@ -43,22 +43,28 @@ $(document).ready(() => { function getWord() { let word = window.location.hash.replace('#', ''); - $.ajax({ - url: '/langs/pl/words/' + word, + if (word) { + document.title = `Inflective - ${decodeURIComponent(word)}`; - success: (data) => { - $('#ajax-content').html(generateHtml(word, data)) - }, + $.ajax({ + url: '/langs/pl/words/' + word, - error: err => console.error(err) - }) + success: (data) => { + $('#ajax-content').html(generateHtml(word, data)); + }, - window.scrollTo(0, 0); - searchBar.select(); - searchBar.autocomplete('close'); - // Sometimes autocomplete opens after close was called - // A better fix should be made - setTimeout(() => searchBar.autocomplete('close'), 1000); + error: err => console.error(err) + }) + + window.scrollTo(0, 0); + searchBar.select(); + searchBar.autocomplete('close'); + // Sometimes autocomplete opens after close was called + // A better fix should be made + setTimeout(() => searchBar.autocomplete('close'), 1000); + } else { + $('#ajax-content').html(''); + } } function getCells(forms, tags) {