Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michał Woźniak
covid
Commits
5fcb6d96
Commit
5fcb6d96
authored
Apr 19, 2020
by
Michał Woźniak
Browse files
starting to clean up url hash handling code
parent
8b4c86cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
covid.js
View file @
5fcb6d96
...
@@ -995,6 +995,22 @@ let calculateAverageRate = (data) => {
...
@@ -995,6 +995,22 @@ let calculateAverageRate = (data) => {
return
a
/
(
data
.
length
-
1
)
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
* handling a .sites-select change
*/
*/
...
@@ -1015,12 +1031,8 @@ let selectSite = (e) => {
...
@@ -1015,12 +1031,8 @@ let selectSite = (e) => {
// need to handle the corner cases, eh
// need to handle the corner cases, eh
var
site
=
theSelect
.
value
var
site
=
theSelect
.
value
var
selected_sites
=
[]
// set the URL hash without firing the hashchange event
for
(
let
sselect
of
sitesSelects
)
{
setUrlHash
()
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
(
'
,
'
))
// using a timeout to give the user a chance to change their mind
// using a timeout to give the user a chance to change their mind
theSelect
.
selectTimeout
=
setTimeout
(
function
(){
theSelect
.
selectTimeout
=
setTimeout
(
function
(){
...
@@ -2006,7 +2018,9 @@ document.addEventListener('DOMContentLoaded', (e)=>{
...
@@ -2006,7 +2018,9 @@ document.addEventListener('DOMContentLoaded', (e)=>{
sitesSelects
[
0
].
value
=
"
select one
"
sitesSelects
[
0
].
value
=
"
select one
"
}
}
// using History.pushState() because we don't want the onhashchange event to fire
// using History.pushState() because we don't want the onhashchange event to fire
history
.
pushState
({},
''
,
window
.
location
.
hash
.
replace
(
/,
[^
,
]
+$/
,
''
))
setUrlHash
()
// update the chart
updateChartSettings
()
updateChartSettings
()
})
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment