Commit 5fcb6d96 authored by Michał Woźniak's avatar Michał Woźniak
Browse files

starting to clean up url hash handling code

parent 8b4c86cc
......@@ -995,6 +995,22 @@ let calculateAverageRate = (data) => {
return a / (data.length - 1)
}
/*
* assemble and set the url hash
* without firing a hashchange event
*/
let setUrlHash = () => {
var selected_sites = []
for (let sselect of sitesSelects) {
selected_sites.push(sselect.value.toLowerCase().replace(/[^a-z0-9]/g, '-'))
}
// using History.pushState() because we don't want the onhashchange event to fire
history.pushState({}, '', '#' + selected_sites.join(','))
}
/*
* handling a .sites-select change
*/
......@@ -1015,12 +1031,8 @@ let selectSite = (e) => {
// need to handle the corner cases, eh
var site = theSelect.value
var selected_sites = []
for (let sselect of sitesSelects) {
selected_sites.push(sselect.value.toLowerCase().replace(/[^a-z0-9]/g, '-'))
}
// using History.pushState() because we don't want the onhashchange event to fire
history.pushState({}, '', '#' + selected_sites.join(','))
// set the URL hash without firing the hashchange event
setUrlHash()
// using a timeout to give the user a chance to change their mind
theSelect.selectTimeout = setTimeout(function(){
......@@ -2006,7 +2018,9 @@ document.addEventListener('DOMContentLoaded', (e)=>{
sitesSelects[0].value = "select one"
}
// using History.pushState() because we don't want the onhashchange event to fire
history.pushState({}, '', window.location.hash.replace(/,[^,]+$/, ''))
setUrlHash()
// update the chart
updateChartSettings()
})
......
Markdown is supported
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