tune urls

This commit is contained in:
j 2022-01-28 16:03:23 +00:00
parent 097d64a2ce
commit f9578af0e4
2 changed files with 13 additions and 4 deletions

View file

@ -1,5 +1,6 @@
// FIXME: move to utils // FIXME: move to utils
// From: https://stackoverflow.com/a/175787 // 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)... 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 !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
@ -46,13 +47,21 @@ function parseHash() {
var options = {} var options = {}
location.hash.slice(1).split('&').forEach(kv => { location.hash.slice(1).split('&').forEach(kv => {
kv = kv.split('=') kv = kv.split('=')
options[kv.shift()] = kv.join('=') const k = kv.shift()
if (k.length) {
options[k] = kv.join('=')
}
}) })
return options; return options;
} }
function updateHash() { 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) document.getElementById('sort-select').addEventListener('change', sortChanged)

View file

@ -6,7 +6,7 @@
<div class="actions"> <div class="actions">
<strong>Filter:</strong> <strong>Filter:</strong>
<select id="filter-select"> <select id="filter-select">
<option value="">All Types</option> <option value="" selected>All Types</option>
{% for type in types %} {% for type in types %}
<option value="{{ type.value }}">{{ type.title }}</option> <option value="{{ type.value }}">{{ type.title }}</option>
{% endfor %} {% endfor %}