-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
116 lines (94 loc) · 3.77 KB
/
script.js
File metadata and controls
116 lines (94 loc) · 3.77 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
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
/*=============== SHOW/HIDE MENU ===============*/
const navToggle = document.getElementById('nav-toggle');
const navMenu = document.getElementById('nav-menu');
const navLinks = document.querySelectorAll('.nav__link');
if (navToggle && navMenu) {
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('show-menu');
});
}
navLinks.forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('show-menu');
});
});
/*=============== SCROLL SECTIONS ACTIVE LINK ===============*/
const sections = document.querySelectorAll('section[id]');
function scrollActive() {
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 50;
const sectionId = section.getAttribute('id');
const navItem = document.querySelector(`.nav__menu a[href*=${sectionId}]`);
if (navItem) {
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navItem.classList.add('active-link');
} else {
navItem.classList.remove('active-link');
}
}
});
}
window.addEventListener('scroll', scrollActive);
/*=============== CHANGE HEADER BACKGROUND ON SCROLL ===============*/
function scrollHeader() {
const header = document.getElementById('header');
if (header) {
header.classList.toggle('scroll-header', window.scrollY >= 80);
}
}
window.addEventListener('scroll', scrollHeader);
/*=============== DARK/LIGHT THEME TOGGLE ===============*/
const themeButton = document.getElementById('theme-button');
const darkTheme = 'dark-theme';
const iconTheme = 'sun-icon';
const selectedTheme = localStorage.getItem('selected-theme');
const selectedIcon = localStorage.getItem('selected-icon');
const getCurrentTheme = () =>
document.body.classList.contains(darkTheme) ? 'dark' : 'light';
const getCurrentIcon = () =>
themeButton.classList.contains(iconTheme) ? 'moon-icon' : 'sun-icon';
if (selectedTheme) {
document.body.classList.toggle(darkTheme, selectedTheme === 'dark');
themeButton.classList.toggle(iconTheme, selectedIcon === 'moon-icon');
}
if (themeButton) {
themeButton.addEventListener('click', () => {
document.body.classList.toggle(darkTheme);
themeButton.classList.toggle(iconTheme);
localStorage.setItem('selected-theme', getCurrentTheme());
localStorage.setItem('selected-icon', getCurrentIcon());
});
}
/*=============== LANGUAGE SWITCHER ===============*/
const langToggle = document.getElementById('lang-toggle');
const langDropdown = document.getElementById('lang-dropdown');
if (langToggle && langDropdown) {
langToggle.addEventListener('click', () => {
langDropdown.style.display =
langDropdown.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', (e) => {
if (!langToggle.contains(e.target) && !langDropdown.contains(e.target)) {
langDropdown.style.display = 'none';
}
});
}
async function switchLanguage(lang) {
try {
const res = await fetch('lang.json');
const data = await res.json();
const content = data[lang];
document.documentElement.lang = lang;
document.getElementById('homeTitle').textContent = content.homeTitle;
document.getElementById('homeText').textContent = content.homeText;
document.getElementById('buttonText').textContent = content.buttonText;
document.getElementById('aboutTitle').innerHTML = `<span>${content.aboutTitle}</span>`;
document.getElementById('aboutText').textContent = content.aboutText;
document.getElementById('contactTitle').innerHTML = `<span>${content.contactTitle}</span>`;
document.getElementById('contactButton').textContent = content.contactButton;
} catch (error) {
console.error('Chyba při načítání jazykového souboru:', error);
}
}