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 @@