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
6431fb7d
Commit
6431fb7d
authored
Apr 22, 2020
by
Michał Woźniak
Browse files
first, naïve implementation of setting the settings based on URL hash
parent
374fd0cd
Changes
1
Show whitespace changes
Inline
Side-by-side
covid.js
View file @
6431fb7d
...
...
@@ -1016,9 +1016,6 @@ let selectSite = (e) => {
// need to handle the corner cases, eh
var
site
=
theSelect
.
value
// set the URL hash without firing the hashchange event
updateUrlHash
()
// using a timeout to give the user a chance to change their mind
theSelect
.
selectTimeout
=
setTimeout
(
function
(){
theSelect
.
selectTimeout
=
false
...
...
@@ -1605,6 +1602,10 @@ let updateChartSettings = () => {
theChart
.
options
.
title
.
text
[
0
]
=
theChart
.
options
.
title
.
text
[
0
][
0
].
toUpperCase
()
+
theChart
.
options
.
title
.
text
[
0
].
slice
(
1
)
theChart
.
options
.
title
.
text
.
push
(
`(as of
${
siteData
[
'
Global
'
].
data
.
slice
(
-
1
)[
0
].
date
.
replace
(
/-
([
0-9
](?![
0-9
]))
/g
,
'
-0$1
'
)}
)`
)
// set the URL hash without firing the hashchange event
// this handles both the sites and the settings in the URL
updateUrlHash
()
// ignoring the potential error
// because we might have filled out data for an nth site
// while data for (n-1)th is still undefined
...
...
@@ -1673,7 +1674,7 @@ let setChartSettings = (settingsObj) => {
/*
* get an array of sites from a string
* used mainly in context of the URL hash
* used mainly in
the
context of the URL hash
*
* takes a comma-separated string of URL-normalized country names
* and returns the country names as used in siteData
...
...
@@ -1716,7 +1717,8 @@ let processUrlHash = (hash) => {
// ";" is used as a separator of options and sites
// with sites coming last and settings being optional
hash
=
hash
.
split
(
'
;
'
)
sites_hash
=
hash
[
sites_hash
.
length
-
1
]
var
sites_hash
=
hash
[
hash
.
length
-
1
]
var
settings_hash
=
''
if
(
hash
.
length
>
1
)
{
settings_hash
=
hash
[
0
]
}
...
...
@@ -2102,6 +2104,25 @@ document.addEventListener('DOMContentLoaded', (e)=>{
// get the actual site names from the URL hash (sans '#')
var
hash
=
processUrlHash
(
window
.
location
.
hash
)
// handle settings
hash
.
settings
.
forEach
((
setting
)
=>
{
// do we have anything to work with?
if
(
setting
===
''
)
{
return
false
;
}
// perhaps it' a "valued" setting?
setting
=
setting
.
split
(
'
:
'
)
// get the node
node
=
document
.
querySelector
(
`.chart-config-container input[id$=
${
setting
[
0
]}
]`
)
// if so, use .value
if
(
setting
.
length
>
1
)
{
node
.
value
=
setting
[
1
]
// otherwise, use .checked
}
else
{
node
.
checked
=
true
}
})
// any site data containers to be removed?
if
(
sitesSelects
.
length
-
hash
.
sites
.
length
>
0
)
{
console
.
log
(
` +-- removing
${
sitesSelects
.
length
-
hash
.
sites
.
length
}
sites...`
)
...
...
Write
Preview
Markdown
is supported
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