-
Notifications
You must be signed in to change notification settings - Fork 0
/
epitracker.js
119 lines (109 loc) · 4.12 KB
/
epitracker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { infoDeck } from "./src/pages/homePage.js";
import {
hideAnimation,
assignNavbarActive
} from "./src/shared.js";
import { aboutepitracker, renderOverView } from "./src/pages/about.js";
import { footerTemplate } from "./src/components/footer.js";
import { dictionaryPage } from "./src/pages/dictionarypage.js"
import {init as startQuantilePage} from "./src/utils/quantilePage.js"
//import {start as startMapPage} from "./src/utils/map.js"
import {init as startMapPage} from "./src/utils/mapPage.js"
export const epitracker = async () => {
if(window.navigator && navigator.serviceWorker) {
navigator.serviceWorker.getRegistrations()
.then(function(registrations) {
for(let registration of registrations) {
registration.unregister();
console.log("Service worker removed.")
}
});
}
manageRouter();
};
const manageRouter = async () => {
const epitrackerDiv = document.getElementById("epitrackerDiv");
const navBarOptions = document.getElementById("navBarOptions");
document.querySelector("[role='contentinfo']").innerHTML = footerTemplate();
const hash = decodeURIComponent(window.location.hash);
if (
!document.getElementById("navBarBtn").classList.contains("collapsed") &&
document.getElementById("navbarToggler").classList.contains("show")
)
document.getElementById("navBarBtn").click();
if (hash === "#home") {
const element = document.getElementById("homePage");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "Epitracker";
assignNavbarActive(element);
infoDeck();
hideAnimation();
} else if (hash === "#about/overview") {
const element = document.getElementById("aboutDCEG");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "Epitracker - Overview";
assignNavbarActive(element);
aboutepitracker("overview");
renderOverView();
} else if (hash === "#visualization/quantile") {
const element = document.getElementById("quantile-visualization");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "quantile-visualization";
assignNavbarActive(element);
epitrackerDiv.innerHTML = renderQuantileVisualizationPage()
//loadQuantileData().then((data => quantileDataLoaded(...data)))
startQuantilePage()
}
else if (hash === "#visualization/map") {
const element = document.getElementById("map-visualization");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "map-visualization";
assignNavbarActive(element);
epitrackerDiv.innerHTML = renderMapVisualizationPage()
startMapPage()
//loadMapData().then(mapDataLoaded)
}
else if (hash === "#instruction") {
const element = document.getElementById("instructionPage");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "instruction-visualization";
assignNavbarActive(element);
epitrackerDiv.innerHTML = InstructionPage ();
}
else if (hash === "#dictionarypage") {
const element = document.getElementById("dictionaryPage");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "dictionary-visualization";
assignNavbarActive(element);
epitrackerDiv.innerHTML = dictionaryPage();
}
else if (hash === "#visualization/demographic") {
const element = document.getElementById("demographic-visualization");
if (!element) return;
if (element.classList.contains("navbar-active")) return;
document.title = "demographic-visualization";
assignNavbarActive(element);
epitrackerDiv.innerHTML = renderQuantileVisualizationPage()
startQuantilePage()
}
else window.location.hash = "#home";
};
window.onload = async () => {
const epitrackerDiv = document.getElementById("epitrackerDiv");
epitrackerDiv.innerHTML = "";
await epitracker();
};
window.onhashchange = () => {
manageRouter();
};
window.addEventListener("beforeinstallprompt", (e) => {
e.userChoice.then((choiceResult) => {
gtag("send", "event", "A2H", choiceResult.outcome);
});
});