Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
224 lines (194 loc) · 7.84 KB
/
Copy pathscript.js
File metadata and controls
224 lines (194 loc) · 7.84 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// =========================================================
// disz2 swipe slider
// =========================================================
const DISZ2_SLIDES = 60; // dt1.jpg .. dt60.jpg
function buildSlider(sliderEl) {
const track = sliderEl.querySelector('.slider-track');
const counter = sliderEl.querySelector('.slider-counter');
for (let i = 1; i <= DISZ2_SLIDES; i++) {
const img = document.createElement('img');
img.src = `assets/images/disz2/dt${i}.jpg`;
img.alt = `Kolbásztöltő verseny ${i}`;
img.loading = 'lazy';
img.className = 'slider-img';
// Lazy loading means src isn't fetched until visible; don't open modal
// before the load, and only open when the click was a genuine tap
// (not part of a swipe gesture).
img.addEventListener('click', function (e) {
if (sliderEl.dataset.hadSwipe === '1') return;
openModal(this.src);
});
track.appendChild(img);
}
let index = 0;
function goTo(i) {
index = Math.max(0, Math.min(DISZ2_SLIDES - 1, i));
track.style.transform = `translateX(-${index * 100}%)`;
counter.textContent = `${index + 1} / ${DISZ2_SLIDES}`;
}
sliderEl.querySelector('.slider-prev').addEventListener('click', () => {
sliderEl.dataset.hadSwipe = '1';
goTo(index - 1);
clearTimeoutSwipe(sliderEl);
});
sliderEl.querySelector('.slider-next').addEventListener('click', () => {
sliderEl.dataset.hadSwipe = '1';
goTo(index + 1);
clearTimeoutSwipe(sliderEl);
});
// Touch / swipe support
let startX = null;
let moved = false;
const viewport = sliderEl.querySelector('.slider-viewport');
viewport.addEventListener('touchstart', (e) => {
startX = e.touches[0].clientX;
moved = false;
}, { passive: true });
viewport.addEventListener('touchmove', (e) => {
if (startX !== null && Math.abs(e.touches[0].clientX - startX) > 30) {
moved = true;
}
}, { passive: true });
viewport.addEventListener('touchend', (e) => {
if (startX === null) return;
const dx = e.changedTouches[0].clientX - startX;
startX = null;
if (Math.abs(dx) > 40) {
moved = true;
sliderEl.dataset.hadSwipe = '1';
if (dx < 0) goTo(index + 1);
else goTo(index - 1);
clearTimeoutSwipe(sliderEl);
return;
}
// A tap (no drag) opens the modal
if (!moved) {
const img = e.target.closest('.slider-img');
if (img) openModal(img.src);
}
});
goTo(0);
}
function clearTimeoutSwipe(sliderEl) {
// Re-enable direct image clicks shortly after an arrow button press
setTimeout(() => { sliderEl.dataset.hadSwipe = '0'; }, 100);
}
document.querySelectorAll('.disz2-slider').forEach(buildSlider);
// =========================================================
// Poster back side toggle (di-po1 front / di-po2 back)
// =========================================================
function initPosterBack(langPrefix, hideText, showText) {
const link = document.getElementById(`${langPrefix}-poster-back-link`);
const back = document.getElementById(`${langPrefix}-poster-back`);
if (!link || !back) return;
// The back side is visible by default; the link lets people hide it.
link.addEventListener('click', function (e) {
e.preventDefault();
const visible = back.style.display !== 'none';
back.style.display = visible ? 'none' : 'block';
link.textContent = visible ? showText : hideText;
});
}
initPosterBack('hu', 'A hátoldal elrejtése', 'A plakát hátoldalának megtekintése');
initPosterBack('de', 'Rückseite ausblenden', 'Rückseite des Plakats anzeigen');
// =========================================================
// Image modal
// =========================================================
let modal = document.createElement('div');
modal.id = 'image-modal';
modal.innerHTML = `
<span id="modal-close">×</span>
<img id="modal-image" src="" alt="">
`;
modal.style.display = 'none';
modal.style.position = 'fixed';
modal.style.zIndex = '10000';
modal.style.left = '0';
modal.style.top = '0';
modal.style.width = '100%';
modal.style.height = '100%';
modal.style.overflow = 'auto';
modal.style.backgroundColor = 'rgba(0,0,0,0.9)';
document.body.appendChild(modal);
let modalImg = document.getElementById('modal-image');
let modalClose = document.getElementById('modal-close');
function openModal(imgSrc) {
modal.style.display = 'block';
modalImg.src = imgSrc;
document.body.style.overflow = 'hidden';
}
function closeModal() {
modal.style.display = 'none';
modalImg.src = '';
document.body.style.overflow = 'auto';
}
modalClose.onclick = closeModal;
modal.onclick = function (event) {
if (event.target === modal) {
closeModal();
}
};
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape' && modal.style.display === 'block') {
closeModal();
}
});
// =========================================================
// Posters open full-screen when clicked
// =========================================================
document.querySelectorAll('.event-poster').forEach(function (img) {
img.addEventListener('click', function () {
openModal(this.src);
});
});
// =========================================================
// Language switcher
// =========================================================
document.getElementById('hu-btn').addEventListener('click', function () {
document.getElementById('hu-content').style.display = 'block';
document.getElementById('de-content').style.display = 'none';
this.classList.add('active');
document.getElementById('de-btn').classList.remove('active');
});
document.getElementById('de-btn').addEventListener('click', function () {
document.getElementById('hu-content').style.display = 'none';
document.getElementById('de-content').style.display = 'block';
this.classList.add('active');
document.getElementById('hu-btn').classList.remove('active');
});
// =========================================================
// Navigation highlight + smooth scroll
// =========================================================
const navLinks = document.querySelectorAll('nav ul li a');
navLinks.forEach(link => {
link.addEventListener('click', function (e) {
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
e.preventDefault();
let scrollToSection = targetSection;
const deContent = document.getElementById('de-content');
if (deContent && deContent.style.display !== 'none') {
const deTargetSection = document.getElementById(targetId + '-de');
if (deTargetSection) scrollToSection = deTargetSection;
}
navLinks.forEach(l => l.classList.remove('active'));
this.classList.add('active');
scrollToSection.scrollIntoView({ behavior: 'smooth' });
}
});
});
window.addEventListener('scroll', function () {
const sections = document.querySelectorAll('.content-section');
const scrollPos = window.pageYOffset + 200;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) {
navLinks.forEach(link => link.classList.remove('active'));
const correspondingLink = document.querySelector(`nav a[href="#${sectionId.replace('-de', '')}"]`);
if (correspondingLink) correspondingLink.classList.add('active');
}
});
});