-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
152 lines (125 loc) · 5.72 KB
/
Copy pathscript.js
File metadata and controls
152 lines (125 loc) · 5.72 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
document.addEventListener('DOMContentLoaded', () => {
/* --- NAVBAR SCROLL EFFECT --- */
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
/* --- INTERSECTION OBSERVER FOR FADE-IN ANIMATIONS --- */
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.15 // Trigger when 15% of the element is visible
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('appear');
// Optional: stop observing once it has appeared
// observer.unobserve(entry.target);
}
});
}, observerOptions);
// Select all elements with the .fade-in class
const fadeElements = document.querySelectorAll('.fade-in');
fadeElements.forEach(el => observer.observe(el));
/* --- SMOOTH SCROLLING FOR NAV LINKS --- */
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if(targetId === '#') return;
const targetElement = document.querySelector(targetId);
if(targetElement) {
const navHeight = navbar.offsetHeight;
const targetPosition = targetElement.getBoundingClientRect().top + window.scrollY - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
/* --- PARALLAX EFFECT FOR BACKGROUND BLOBS --- */
const blobs = document.querySelectorAll('.blob-bg');
window.addEventListener('scroll', () => {
const scrolled = window.scrollY;
blobs.forEach((blob, index) => {
// Different speed for different blobs
const speed = (index + 1) * 0.1;
blob.style.transform = `translateY(${scrolled * speed}px)`;
});
});
/* --- DYNAMIC ORCID PUBLICATIONS --- */
const ORCID_ID = '0000-0002-4690-5783';
const pubGrid = document.getElementById('publications-grid');
const skeleton = document.getElementById('pub-skeleton');
async function initPublications() {
if (!pubGrid) return;
try {
const response = await fetch(`https://pub.orcid.org/v3.0/${ORCID_ID}/works`, {
headers: { 'Accept': 'application/json' }
});
const data = await response.json();
// Extract works and sort by year (newest first)
const works = data.group.map(g => g['work-summary'][0])
.sort((a, b) => {
const yearA = a['publication-date']?.year?.value || 0;
const yearB = b['publication-date']?.year?.value || 0;
return yearB - yearA;
})
.slice(0, 6); // Top 6 recent
// Fetch details for authors/DOI if needed, or just render summaries
renderPublications(works);
} catch (error) {
console.error('Error fetching ORCID works:', error);
if (skeleton) skeleton.innerHTML = '<p class="text-dim">Unable to load live publications. Please view the full profile below.</p>';
}
}
function renderPublications(works) {
if (skeleton) skeleton.remove();
works.forEach((work, index) => {
const title = work.title?.title?.value || 'Untitled Work';
const year = work['publication-date']?.year?.value || 'N/A';
const journal = work['journal-title']?.value || 'Journal/Venue Not Listed';
const type = work.type.replace(/_/g, ' ');
// Try to find DOI
let doiUrl = '#';
const doi = work['external-ids']?.['external-id']?.find(id => id['external-id-type'] === 'doi');
if (doi) {
doiUrl = doi['external-id-url']?.value || `https://doi.org/${doi['external-id-value']}`;
}
// Create container card
const card = document.createElement('div');
card.className = `pub-card fade-in`;
card.style.animationDelay = `${index * 0.1}s`;
// Create title link
const titleLink = document.createElement('a');
titleLink.href = doiUrl;
titleLink.target = '_blank';
titleLink.rel = 'noopener noreferrer';
titleLink.className = 'pub-title';
titleLink.textContent = title;
// Create venue/year text
const venueDiv = document.createElement('div');
venueDiv.className = 'pub-venue';
venueDiv.textContent = journal !== 'Journal/Venue Not Listed' ? `${journal} • ${year}` : `${year}`;
// Create type badge
const badge = document.createElement('div');
badge.className = 'badge glass';
badge.style.cssText = 'align-self: flex-start; margin-top: 0.5rem; font-size: 0.7rem; padding: 0.2rem 0.6rem; text-transform: capitalize;';
badge.textContent = type;
// Assemble the card
card.appendChild(titleLink);
card.appendChild(venueDiv);
card.appendChild(badge);
pubGrid.appendChild(card);
// Trigger animation
setTimeout(() => card.classList.add('appear'), 50);
});
}
initPublications();
});