-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 1.33 KB
/
index.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
document.addEventListener("DOMContentLoaded", (event) => {
// setup href click events
Array.from(document.querySelectorAll('a')).filter(isContentLink).forEach(addContentStorageCapability);
// set correct content on refresh
if (
(window.performance.navigation && window.performance.navigation.type === 1)
||
window.performance
.getEntriesByType('navigation')
.map((nav) => nav.type)
.includes('reload')
)
{
const sites = new Map([
['about', 'pages/about/about.html'],
['blog-overview', 'pages/blog/overview/blog-overview.html']
]);
const initialState = localStorage.getItem('iframeContent');
let site = sites.get(initialState);
if (site !== undefined) {
document.getElementById('content-frame').src = site;
} else {
document.getElementById('content-frame').src = 'pages/invalid-content/invalid-content.html'
}
} else {
document.getElementById('content-frame').src = 'pages/blog/overview/blog-overview.html';
}
});
function isContentLink(a) {
return a.target === "content-frame";
}
function addContentStorageCapability(a) {
a.addEventListener('click', (event) => {
localStorage.setItem('iframeContent', a.dataset.linksTo);
});
}