From b0c30d5b3cc05c27270c9c6fdfb7576397bfccb0 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 4 Mar 2021 07:17:43 +0100 Subject: only attempt to load /laws.json if it exists --- assets/script.js | 7 +++++-- lexsurf.go | 5 +++++ views/search.html | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/assets/script.js b/assets/script.js index 34c386e..6d9e476 100644 --- a/assets/script.js +++ b/assets/script.js @@ -1,7 +1,7 @@ const searchInput = document.getElementById('search'); const suggestionsDiv = document.getElementById('suggestions'); -(async function(){ +async function enableAutocomplete() { const res = await fetch('/laws.json'); const laws = await res.json(); searchInput.addEventListener('input', (e) => { @@ -48,4 +48,7 @@ const suggestionsDiv = document.getElementById('suggestions'); suggestionsDiv.replaceChildren(...suggestions); }); -})(); +} + +if ('json' in searchInput.dataset) + enableAutocomplete(); \ No newline at end of file diff --git a/lexsurf.go b/lexsurf.go index 9c88052..6fa4394 100644 --- a/lexsurf.go +++ b/lexsurf.go @@ -26,6 +26,11 @@ func (c country) HasPlaceholder() bool { return strings.Contains(c.SearchURL, "%s") } +func (c SearchContext) HasJSONLaws() bool { + _, ok := lawsByCC[c.TLD] + return ok +} + var countries = map[string]country{} var lawsByCC = map[string]map[string]law{} diff --git a/views/search.html b/views/search.html index 44d496c..5cf0483 100644 --- a/views/search.html +++ b/views/search.html @@ -10,7 +10,7 @@

National Law of {{.Country.Name}}

{{if .Country.HasPlaceholder}}
- +
{{else}} -- cgit v1.2.3