-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
179 lines (151 loc) · 5.4 KB
/
Copy pathscript.js
File metadata and controls
179 lines (151 loc) · 5.4 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
const menuBtn = document.querySelector('.menu-btn');
const nav = document.querySelector('.site-nav');
const panelTriggers = document.querySelectorAll('a[data-panel], button[data-panel]');
const navLinks = document.querySelectorAll('.site-nav a[data-panel]');
const panels = document.querySelectorAll('.panel');
const defaultTitle = document.title;
const panelTitles = {
home: defaultTitle,
about: `About | ${defaultTitle}`,
research: `Research & Development | ${defaultTitle}`,
teaching: `Teaching & Supervision | ${defaultTitle}`,
media: `Media & Outreach | ${defaultTitle}`,
resources: `Resources | ${defaultTitle}`,
contact: `Contact | ${defaultTitle}`,
};
const setPanel = (panelName, updateHash = true) => {
const targetPanel = document.querySelector(`.panel[data-panel="${panelName}"]`);
if (!targetPanel) {
panelName = 'home';
}
panels.forEach((panel) => {
panel.classList.toggle('active', panel.dataset.panel === panelName);
});
navLinks.forEach((link) => {
link.classList.toggle('active', link.dataset.panel === panelName);
});
const activePanel = document.querySelector(`.panel[data-panel="${panelName}"]`);
if (activePanel) {
activePanel.querySelectorAll('.reveal').forEach((el) => {
el.classList.remove('in-view');
});
requestAnimationFrame(() => {
activePanel.querySelectorAll('.reveal').forEach((el) => {
el.classList.add('in-view');
});
});
}
if (nav) {
nav.classList.remove('open');
}
document.title = panelTitles[panelName] || defaultTitle;
if (updateHash && window.location.hash !== `#${panelName}`) {
window.history.pushState(null, '', `#${panelName}`);
}
window.scrollTo({ top: 0, behavior: 'smooth' });
};
if (menuBtn && nav) {
menuBtn.addEventListener('click', () => {
nav.classList.toggle('open');
});
}
panelTriggers.forEach((link) => {
link.addEventListener('click', (event) => {
event.preventDefault();
const panelName = link.dataset.panel;
if (panelName) {
setPanel(panelName);
}
});
});
const initialPanelName = window.location.hash.replace('#', '') || 'home';
setPanel(initialPanelName, false);
window.addEventListener('popstate', () => {
setPanel(window.location.hash.replace('#', '') || 'home', false);
});
const initialPanel = document.querySelector('.panel.active');
if (initialPanel) {
initialPanel.querySelectorAll('.reveal').forEach((el) => {
el.classList.add('in-view');
});
}
const yearEl = document.getElementById('year');
if (yearEl) {
yearEl.textContent = new Date().getFullYear();
}
const heroSlider = document.querySelector('[data-slider]');
if (heroSlider) {
const slides = Array.from(heroSlider.querySelectorAll('img'));
const caption = heroSlider.querySelector('.image-caption');
const previousButton = heroSlider.querySelector('[data-slide-prev]');
const nextButton = heroSlider.querySelector('[data-slide-next]');
let activeSlide = 0;
let sliderTimer = null;
if (slides.length > 1) {
const showSlide = (nextIndex) => {
slides[activeSlide].classList.remove('active');
activeSlide = (nextIndex + slides.length) % slides.length;
slides[activeSlide].classList.add('active');
if (caption) {
caption.textContent = slides[activeSlide].dataset.caption || '';
}
};
const scheduleNextSlide = () => {
window.clearTimeout(sliderTimer);
sliderTimer = window.setTimeout(() => {
showSlide(activeSlide + 1);
scheduleNextSlide();
}, Number(slides[activeSlide].dataset.duration) || 5000);
};
previousButton?.addEventListener('click', () => {
showSlide(activeSlide - 1);
scheduleNextSlide();
});
nextButton?.addEventListener('click', () => {
showSlide(activeSlide + 1);
scheduleNextSlide();
});
scheduleNextSlide();
}
}
const pubSearch = document.getElementById('pub-search');
const pubYearFilter = document.getElementById('pub-year-filter');
const pubCount = document.getElementById('pub-count');
const pubYears = Array.from(document.querySelectorAll('.pub-year'));
if (pubSearch && pubYearFilter && pubYears.length) {
const years = pubYears
.map((yearBlock) => yearBlock.querySelector('h3')?.textContent.trim())
.filter(Boolean);
years.forEach((year) => {
const option = document.createElement('option');
option.value = year;
option.textContent = year;
pubYearFilter.appendChild(option);
});
const filterPublications = () => {
const query = pubSearch.value.trim().toLowerCase();
const selectedYear = pubYearFilter.value;
let visibleCount = 0;
pubYears.forEach((yearBlock) => {
const year = yearBlock.querySelector('h3')?.textContent.trim() || '';
const yearMatches = !selectedYear || year === selectedYear;
let visibleInYear = 0;
yearBlock.querySelectorAll('li').forEach((item) => {
const textMatches = !query || item.textContent.toLowerCase().includes(query);
const isVisible = yearMatches && textMatches;
item.hidden = !isVisible;
if (isVisible) {
visibleCount += 1;
visibleInYear += 1;
}
});
yearBlock.hidden = visibleInYear === 0;
});
if (pubCount) {
pubCount.textContent = `${visibleCount} publication${visibleCount === 1 ? '' : 's'} shown`;
}
};
pubSearch.addEventListener('input', filterPublications);
pubYearFilter.addEventListener('change', filterPublications);
filterPublications();
}