Commit 548fd73f authored by Michał Woźniak's avatar Michał Woźniak
Browse files

hash handled properly

parent 02631d2f
Pipeline #89 passed with stage
in 0 seconds
......@@ -185,6 +185,8 @@ document.addEventListener('DOMContentLoaded', (e)=>{
// need to handle the corner cases, eh
var site = event.target.value
// using History.pushState() because we don't want the onhashchange event to fire
history.pushState({}, '', '#' + site.toLowerCase().replace(/[^a-z0-9]/g, '-'))
siteSelectTimeout = setTimeout(function(){
siteSelectTimeout = false
......@@ -236,21 +238,25 @@ document.addEventListener('DOMContentLoaded', (e)=>{
return sites
})
// at this point we have all the sites ready,
// so we can process the URL #hash to check if any matches
//
// format of our hashes is:
//
// so we can process the URL #hash
.then(()=>{
if (window.location.hash) {
console.log(`+-- got hash: ${window.location.hash}`)
var hash_sites = sites.filter(site => (site.toLowerCase().replace(/[^a-z]/g, '-') === window.location.hash.substr(1)))
if (hash_sites.length === 1) {
console.log(` +-- got site from hash: ${hash_sites[0]}`)
siteSelect.value = hash_sites[0]
siteSelect.dispatchEvent(new Event('change'));
}
}
window.dispatchEvent(new Event('hashchange'));
})
// handling manual hash change
window.addEventListener("hashchange", (e)=>{
console.log(`+-- manual hash change! '${window.location.hash}'`)
if (window.location.hash) {
console.log(` got hash: ${window.location.hash}`)
var hash_sites = sites.filter(site => (site.toLowerCase().replace(/[^a-z]/g, '-') === window.location.hash.substr(1)))
if (hash_sites.length === 1) {
console.log(` +-- got site from hash: ${hash_sites[0]}`)
siteSelect.value = hash_sites[0]
siteSelect.dispatchEvent(new Event('change'));
}
}
}, false);
});
// https://en.wikipedia.org/wiki/File:Epidemic_curve_update_18_march_20.png
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment