|
1 | | -const animated = document.querySelectorAll( |
2 | | - '[data-animate], [data-pop], .card, .feature__media video, .card video' |
3 | | -); |
4 | | - |
5 | | -const observer = new IntersectionObserver( |
6 | | - entries => { |
7 | | - entries.forEach(entry => { |
8 | | - if (entry.isIntersecting) { |
9 | | - entry.target.classList.add('is-visible'); |
10 | | - if (entry.target.tagName === 'VIDEO') { |
11 | | - entry.target.play().catch(() => {}); |
12 | | - } |
13 | | - } |
14 | | - }); |
15 | | - }, |
16 | | - { threshold: 0.35 } |
17 | | -); |
18 | | - |
19 | | -animated.forEach(el => observer.observe(el)); |
20 | | - |
21 | | -const toggleButtons = document.querySelectorAll('.play-toggle'); |
22 | | - |
23 | | -toggleButtons.forEach(button => { |
24 | | - const video = button.previousElementSibling; |
25 | | - button.addEventListener('click', () => { |
26 | | - if (video.paused) { |
27 | | - video.play(); |
28 | | - button.querySelector('span').textContent = 'pause'; |
29 | | - } else { |
30 | | - video.pause(); |
31 | | - button.querySelector('span').textContent = 'play'; |
32 | | - } |
33 | | - }); |
| 1 | +const animated = document.querySelectorAll(␊ |
| 2 | + '[data-animate], [data-pop], .card, .feature__media video, .card video'␊ |
| 3 | +);␊ |
| 4 | +␊ |
| 5 | +const observer = new IntersectionObserver(␊ |
| 6 | + entries => {␊ |
| 7 | + entries.forEach(entry => {␊ |
| 8 | + if (entry.isIntersecting) {␊ |
| 9 | + entry.target.classList.add('is-visible');␊ |
| 10 | + if (entry.target.tagName === 'VIDEO') {␊ |
| 11 | + entry.target.play().catch(() => {});␊ |
| 12 | + }␊ |
| 13 | + }␊ |
| 14 | + });␊ |
| 15 | + },␊ |
| 16 | + { threshold: 0.35 }␊ |
| 17 | +);␊ |
| 18 | +␊ |
| 19 | +animated.forEach(el => observer.observe(el));␊ |
| 20 | +␊ |
| 21 | +const toggleButtons = document.querySelectorAll('.play-toggle');␊ |
| 22 | +␊ |
| 23 | +toggleButtons.forEach(button => {␊ |
| 24 | + const video = button.previousElementSibling;␊ |
| 25 | + button.addEventListener('click', () => {␊ |
| 26 | + if (video.paused) {␊ |
| 27 | + video.play();␊ |
| 28 | + button.querySelector('span').textContent = 'pause';␊ |
| 29 | + } else {␊ |
| 30 | + video.pause();␊ |
| 31 | + button.querySelector('span').textContent = 'play';␊ |
| 32 | + }␊ |
| 33 | + });␊ |
| 34 | +});␊ |
| 35 | +␊ |
| 36 | +const cards = document.querySelectorAll('.card video');␊ |
| 37 | +cards.forEach(video => {␊ |
| 38 | + video.addEventListener('mouseenter', () => video.play());␊ |
| 39 | + video.addEventListener('mouseleave', () => video.pause());␊ |
34 | 40 | }); |
35 | | - |
36 | | -const cards = document.querySelectorAll('.card video'); |
37 | | -cards.forEach(video => { |
38 | | - video.addEventListener('mouseenter', () => video.play()); |
39 | | - video.addEventListener('mouseleave', () => video.pause()); |
40 | | -}); |
41 | | - |
42 | | -const langToggleButtons = document.querySelectorAll('.lang-toggle button'); |
43 | | -const langViews = document.querySelectorAll('.lang-view'); |
44 | | -const navLinks = document.querySelectorAll('.nav-links a[data-href-en]'); |
45 | | - |
46 | | -const setLanguage = lang => { |
47 | | - document.documentElement.setAttribute('lang', lang); |
48 | | - |
49 | | - langToggleButtons.forEach(btn => { |
50 | | - btn.classList.toggle('is-active', btn.dataset.lang === lang); |
51 | | - }); |
52 | | - |
53 | | - langViews.forEach(view => { |
54 | | - view.classList.toggle('is-active', view.dataset.lang === lang); |
55 | | - }); |
56 | | - |
57 | | - navLinks.forEach(link => { |
58 | | - const href = link.dataset[`href${lang.toUpperCase()}`]; |
59 | | - const label = link.dataset[`label${lang.toUpperCase()}`]; |
60 | | - if (href) link.setAttribute('href', href); |
61 | | - if (label) link.textContent = label; |
62 | | - }); |
63 | | -}; |
64 | | - |
65 | | -if (langToggleButtons.length) { |
66 | | - langToggleButtons.forEach(button => { |
67 | | - button.addEventListener('click', () => { |
68 | | - setLanguage(button.dataset.lang); |
69 | | - }); |
70 | | - }); |
71 | | - |
72 | | - setLanguage('en'); |
73 | | -} |
0 commit comments