-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
130 lines (112 loc) · 5.17 KB
/
script.js
File metadata and controls
130 lines (112 loc) · 5.17 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
document.addEventListener('DOMContentLoaded', () => {
// Smooth scroll for navigation links
document.querySelectorAll('nav a').forEach(anchor => {
if (anchor.getAttribute('href').startsWith('#')) {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
document.getElementById(targetId).scrollIntoView({ behavior: 'smooth' });
});
}
});
// Fade-in animation on scroll for sections
const fadeInSections = document.querySelectorAll('.fade-in-section');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
}
});
}, { threshold: 0.1 });
fadeInSections.forEach(section => {
observer.observe(section);
});
// Toggle show more/less for publication authors
document.querySelectorAll('.show-more').forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const publication = this.closest('p');
publication.querySelector('.et-al').style.display = 'none';
publication.querySelector('.all-authors').style.display = 'inline';
});
});
document.querySelectorAll('.show-less').forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const publication = this.closest('p');
publication.querySelector('.et-al').style.display = 'inline';
publication.querySelector('.all-authors').style.display = 'none';
});
});
// Handle video playback on hover
const videoContainers = document.querySelectorAll('.publication[data-has-video="true"]');
videoContainers.forEach(container => {
const video = container.querySelector('video');
container.addEventListener('mouseenter', () => {
video.play().catch(error => {
console.error('Error playing video:', error);
});
});
container.addEventListener('mouseleave', () => {
video.pause();
video.currentTime = 0; // Reset to beginning
});
});
const toggles = document.querySelectorAll(".toggle-btn");
toggles.forEach((btn) => {
btn.addEventListener("click", function () {
const content = this.nextElementSibling;
content.style.display = content.style.display === "block" ? "none" : "block";
});
});
// Publications: show selected vs show all
const publicationsToggle = document.getElementById('publicationsToggle');
const publicationCards = document.querySelectorAll('#publications .publication');
const applyPublicationsFilter = (showAll) => {
publicationCards.forEach((card) => {
const isSelected = card.dataset.selected === 'true';
const shouldShow = showAll || isSelected;
card.style.display = shouldShow ? '' : 'none';
});
};
if (publicationsToggle && publicationCards.length > 0) {
let showAll = false;
applyPublicationsFilter(showAll);
publicationsToggle.addEventListener('click', () => {
showAll = !showAll;
applyPublicationsFilter(showAll);
publicationsToggle.setAttribute('aria-pressed', showAll ? 'true' : 'false');
publicationsToggle.textContent = showAll ? 'Show selected' : 'Show all';
});
}
// Projects carousel arrows (desktop/tablet)
const projectsCarousel = document.querySelector('#projects .projects-carousel');
if (projectsCarousel) {
const track = projectsCarousel.querySelector('.projects-list');
const leftBtn = projectsCarousel.querySelector('.carousel-arrow-left');
const rightBtn = projectsCarousel.querySelector('.carousel-arrow-right');
const getPageScroll = () => {
if (!track) return 0;
const styles = window.getComputedStyle(track);
const gap = Number.parseFloat(styles.columnGap || styles.gap || '16') || 16;
// Scroll by one "page" (4 cards on desktop, 2 on tablet)
return Math.max(1, track.clientWidth - gap);
};
const updateArrows = () => {
if (!track || !leftBtn || !rightBtn) return;
const maxScrollLeft = track.scrollWidth - track.clientWidth;
leftBtn.disabled = track.scrollLeft <= 1;
rightBtn.disabled = track.scrollLeft >= maxScrollLeft - 1;
};
const scrollByPage = (direction) => {
if (!track) return;
const amount = getPageScroll() * direction;
track.scrollBy({ left: amount, behavior: 'smooth' });
};
if (leftBtn) leftBtn.addEventListener('click', () => scrollByPage(-1));
if (rightBtn) rightBtn.addEventListener('click', () => scrollByPage(1));
if (track) track.addEventListener('scroll', () => window.requestAnimationFrame(updateArrows), { passive: true });
window.addEventListener('resize', updateArrows);
updateArrows();
}
});