-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-projects.js
46 lines (40 loc) · 1.47 KB
/
load-projects.js
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
const projectList = [
'research/airc.html',
'research/style.html',
'research/ads.html'
// 'project2.html',
// Add more project HTML file names here
];
document.addEventListener('DOMContentLoaded', loadProjects);
function loadProjects() {
const container = document.getElementById('projects-container');
const fetchPromises = projectList.map(project => {
return fetch(project)
.then(response => response.text())
.then(content => {
const projectSection = document.createElement('div');
projectSection.className = 'project';
projectSection.innerHTML = content;
// Add event listener to toggle content visibility
const titleElement = projectSection.querySelector('.project-title');
titleElement.addEventListener('click', () => {
const detailsElement = projectSection.querySelector('.project-details');
toggleDisplay(detailsElement);
});
return projectSection;
});
});
Promise.all(fetchPromises)
.then(projectSections => {
projectSections.forEach(projectSection => {
container.appendChild(projectSection);
});
});
}
function toggleDisplay(element) {
if (element.style.display === 'none') {
element.style.display = 'block';
} else {
element.style.display = 'none';
}
}