Atom feed for our EEG site

more

Changed files
+15 -214
+15 -214
index.html
···
if (monthEl) {
monthEl.classList.add('active');
-
monthEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
// Store the last active month globally
lastActiveMonth = month;
···
timeline.style.display = 'flex';
document.querySelector('.content').style.paddingRight = 'var(--sidebar-width)';
-
// Reset timeline highlighting when switching between posts/links
+
// Reset timeline highlighting
document.querySelectorAll('.timeline-year.active, .timeline-month.active').forEach(el => {
el.classList.remove('active');
});
-
// Check if we have stored the active year/month
-
// If we don't have stored dates yet, try to find them from the active timeline elements
-
if (!lastActiveYear || !lastActiveMonth) {
-
const activeYearEl = document.querySelector('.timeline-year.active');
-
const activeMonthEl = document.querySelector('.timeline-month.active');
-
-
if (activeYearEl) {
-
lastActiveYear = activeYearEl.getAttribute('data-year');
-
}
-
-
if (activeMonthEl) {
-
lastActiveMonth = activeMonthEl.getAttribute('data-month');
-
} else {
-
// If still no active month, try to find the first visible item in current view
-
const previousTabName = document.querySelector('.tab-button.active').getAttribute('data-tab');
-
const selector = previousTabName === 'posts' ? '.feed-item' : '.link-item';
-
const visibleItems = Array.from(document.querySelectorAll(selector))
-
.filter(item => {
-
const rect = item.getBoundingClientRect();
-
return rect.top >= 0 && rect.bottom <= window.innerHeight;
-
});
-
-
if (visibleItems.length > 0) {
-
lastActiveYear = visibleItems[0].getAttribute('data-year');
-
lastActiveMonth = visibleItems[0].getAttribute('data-month');
-
-
}
-
}
+
// Disconnect and recreate the observer to ensure proper tracking
+
if (globalFeedObserver) {
+
globalFeedObserver.disconnect();
+
// Setup a new observer
+
globalFeedObserver = setupObserver({
+
root: null,
+
rootMargin: '0px',
+
threshold: 0.3
+
});
-
// If switching to links view, ensure link items are properly observed
-
if (tabName === 'links') {
-
// Disconnect and recreate the observer to ensure proper tracking
-
if (globalFeedObserver) {
-
globalFeedObserver.disconnect();
-
}
-
-
// Setup a new observer
-
globalFeedObserver = setupObserver({
-
root: null,
-
rootMargin: '0px',
-
threshold: 0.3
-
});
-
-
// Observe all items in the active tab
-
observeAllDateItems();
-
-
// If we have active year/month from previous tab, find closest match
-
if (lastActiveYear && lastActiveMonth) {
-
// Find link items from this time period
-
let selector = `.link-item[data-year="${lastActiveYear}"][data-month="${lastActiveMonth}"]`;
-
let matchingItems = document.querySelectorAll(selector);
-
-
-
// If no exact match, try just matching the year
-
if (matchingItems.length === 0) {
-
selector = `.link-item[data-year="${lastActiveYear}"]`;
-
matchingItems = document.querySelectorAll(selector);
-
}
-
-
// If still no match, find the closest date
-
if (matchingItems.length === 0) {
-
const targetDate = new Date(lastActiveYear, lastActiveMonth);
-
const allLinkItems = Array.from(document.querySelectorAll('.link-item'));
-
-
// Sort by closest date
-
if (allLinkItems.length > 0) {
-
allLinkItems.sort((a, b) => {
-
const dateA = new Date(a.getAttribute('data-year'), a.getAttribute('data-month'));
-
const dateB = new Date(b.getAttribute('data-year'), b.getAttribute('data-month'));
-
-
return Math.abs(dateA - targetDate) - Math.abs(dateB - targetDate);
-
});
-
-
// Use closest match
-
if (allLinkItems.length > 0) {
-
matchingItems = [allLinkItems[0]];
-
}
-
}
-
}
-
-
// Scroll to the matching item
-
if (matchingItems.length > 0) {
-
matchingItems[0].scrollIntoView({ behavior: 'smooth', block: 'start' });
-
-
// Update timeline
-
const year = matchingItems[0].getAttribute('data-year');
-
const month = matchingItems[0].getAttribute('data-month');
-
-
const yearEl = document.querySelector(`.timeline-year[data-year="${year}"]`);
-
const monthEl = document.querySelector(`.timeline-month[data-year="${year}"][data-month="${month}"]`);
-
-
if (yearEl) yearEl.classList.add('active');
-
if (monthEl) {
-
monthEl.classList.add('active');
-
monthEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
-
}
-
}
-
} else {
-
// If no active period, default to highlighting first visible
-
const visibleLinks = Array.from(document.querySelectorAll('.link-item'))
-
.filter(item => {
-
const rect = item.getBoundingClientRect();
-
return rect.top >= 0 && rect.bottom <= window.innerHeight;
-
});
-
-
if (visibleLinks.length > 0) {
-
const firstVisible = visibleLinks[0];
-
const year = firstVisible.getAttribute('data-year');
-
const month = firstVisible.getAttribute('data-month');
-
-
if (year && month) {
-
const yearEl = document.querySelector(`.timeline-year[data-year="${year}"]`);
-
const monthEl = document.querySelector(`.timeline-month[data-year="${year}"][data-month="${month}"]`);
-
-
if (yearEl) yearEl.classList.add('active');
-
if (monthEl) {
-
monthEl.classList.add('active');
-
monthEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
-
}
-
}
-
}
-
}
-
} else if (tabName === 'posts') {
-
// Same for posts view
-
if (globalFeedObserver) {
-
globalFeedObserver.disconnect();
-
}
-
-
globalFeedObserver = setupObserver({
-
root: null,
-
rootMargin: '0px',
-
threshold: 0.3
-
});
-
-
observeAllDateItems();
-
-
// If we have active year/month from previous tab, find closest match
-
if (lastActiveYear && lastActiveMonth) {
-
// Find feed items from this time period
-
let selector = `.feed-item[data-year="${lastActiveYear}"][data-month="${lastActiveMonth}"]`;
-
let matchingItems = document.querySelectorAll(selector);
-
-
-
// If no exact match, try just matching the year
-
if (matchingItems.length === 0) {
-
selector = `.feed-item[data-year="${lastActiveYear}"]`;
-
matchingItems = document.querySelectorAll(selector);
-
}
-
-
// If still no match, find the closest date
-
if (matchingItems.length === 0) {
-
const targetDate = new Date(lastActiveYear, lastActiveMonth);
-
const allFeedItems = Array.from(document.querySelectorAll('.feed-item'));
-
-
// Sort by closest date
-
if (allFeedItems.length > 0) {
-
allFeedItems.sort((a, b) => {
-
const dateA = new Date(a.getAttribute('data-year'), a.getAttribute('data-month'));
-
const dateB = new Date(b.getAttribute('data-year'), b.getAttribute('data-month'));
-
-
return Math.abs(dateA - targetDate) - Math.abs(dateB - targetDate);
-
});
-
-
// Use closest match
-
if (allFeedItems.length > 0) {
-
matchingItems = [allFeedItems[0]];
-
}
-
}
-
}
-
-
// Scroll to the matching item
-
if (matchingItems.length > 0) {
-
matchingItems[0].scrollIntoView({ behavior: 'smooth', block: 'start' });
-
-
// Update timeline
-
const year = matchingItems[0].getAttribute('data-year');
-
const month = matchingItems[0].getAttribute('data-month');
-
-
const yearEl = document.querySelector(`.timeline-year[data-year="${year}"]`);
-
const monthEl = document.querySelector(`.timeline-month[data-year="${year}"][data-month="${month}"]`);
-
-
if (yearEl) yearEl.classList.add('active');
-
if (monthEl) {
-
monthEl.classList.add('active');
-
monthEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
-
}
-
}
-
} else {
-
// If no active period, default to highlighting first visible
-
const visiblePosts = Array.from(document.querySelectorAll('.feed-item'))
-
.filter(item => {
-
const rect = item.getBoundingClientRect();
-
return rect.top >= 0 && rect.bottom <= window.innerHeight;
-
});
-
-
if (visiblePosts.length > 0) {
-
const firstVisible = visiblePosts[0];
-
const year = firstVisible.getAttribute('data-year');
-
const month = firstVisible.getAttribute('data-month');
-
-
if (year && month) {
-
const yearEl = document.querySelector(`.timeline-year[data-year="${year}"]`);
-
const monthEl = document.querySelector(`.timeline-month[data-year="${year}"][data-month="${month}"]`);
-
-
if (yearEl) yearEl.classList.add('active');
-
if (monthEl) {
-
monthEl.classList.add('active');
-
monthEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
-
}
-
}
-
}
-
}
-
}
+
// Observe all items in the active tab
+
observeAllDateItems();
+
+
// Always scroll to top when switching tabs
+
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});