-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (42 loc) · 1.43 KB
/
script.js
File metadata and controls
53 lines (42 loc) · 1.43 KB
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
const i18n = window.PortfolioI18n;
const langRadios = document.querySelectorAll('.lang-switcher input[type="radio"]');
const AboutBtn = document.getElementById('About-btn');
const closeSidebarBtn = document.getElementById('close-sidebar');
const AboutSidebar = document.getElementById('About-sidebar');
const AboutOverlay = document.getElementById('About-overlay');
function applyHomeLanguage(lang) {
const activeLang = i18n.setLang(lang);
i18n.applyDataI18n(document, activeLang);
i18n.setPageMeta(
{
titleKey: 'homeTitle',
descriptionKey: 'homeDescription'
},
activeLang
);
const activeRadio = document.querySelector(`#lang-${activeLang}`);
if (activeRadio) activeRadio.checked = true;
return activeLang;
}
function openSidebar() {
AboutSidebar.classList.add('active');
AboutOverlay.classList.add('active');
}
function closeSidebar() {
AboutSidebar.classList.remove('active');
AboutOverlay.classList.remove('active');
}
langRadios.forEach((radio) => {
radio.addEventListener('change', (event) => {
applyHomeLanguage(event.target.value);
});
});
window.addEventListener('storage', (event) => {
if (event.key === i18n.STORAGE_KEY && event.newValue) {
applyHomeLanguage(event.newValue);
}
});
AboutBtn.addEventListener('click', openSidebar);
closeSidebarBtn.addEventListener('click', closeSidebar);
AboutOverlay.addEventListener('click', closeSidebar);
applyHomeLanguage(i18n.getLang());