From f9578af0e4065f5fc83ac8a2d3c9d685ede1de13 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 28 Jan 2022 16:03:23 +0000 Subject: [PATCH] tune urls --- app/static/js/films.js | 15 ++++++++++++--- app/templates/films.html | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/static/js/films.js b/app/static/js/films.js index 727298f..6f0d2cb 100644 --- a/app/static/js/films.js +++ b/app/static/js/films.js @@ -1,6 +1,7 @@ // FIXME: move to utils // From: https://stackoverflow.com/a/175787 -function isNumeric (str) { + +function isNumeric (str) { return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)... !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail } @@ -46,13 +47,21 @@ function parseHash() { var options = {} location.hash.slice(1).split('&').forEach(kv => { kv = kv.split('=') - options[kv.shift()] = kv.join('=') + const k = kv.shift() + if (k.length) { + options[k] = kv.join('=') + } }) return options; } function updateHash() { - location.hash = '#' + Object.keys(options).map(key => { return key + '=' + options[key]; }).join('&') + const value = Object.keys(options).filter(key => { + return key && options[key]; + }).map(key => { + return key + '=' + options[key]; + }).join('&') + location.hash = value ? '#' + value : '' } document.getElementById('sort-select').addEventListener('change', sortChanged) diff --git a/app/templates/films.html b/app/templates/films.html index 299ede7..dad69d7 100644 --- a/app/templates/films.html +++ b/app/templates/films.html @@ -6,7 +6,7 @@
Filter: