From ad19cff23e4b21ab47d4c4206def91faa1066ec3 Mon Sep 17 00:00:00 2001 From: sakrecoer Date: Mon, 3 Aug 2026 09:53:25 +0200 Subject: [PATCH] add navigation back --- themes/one-pager/assets/js/scripts.js | 70 ++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/themes/one-pager/assets/js/scripts.js b/themes/one-pager/assets/js/scripts.js index d05983d..1209bcb 100644 --- a/themes/one-pager/assets/js/scripts.js +++ b/themes/one-pager/assets/js/scripts.js @@ -43,7 +43,6 @@ function buildPhotoArray() { currentPhotos = []; photoItems.forEach(item => { const image = item.querySelector('img'); - // FIX: Use dataset values directly const date = item.dataset.date || ''; const pubkey = item.dataset.pubkey || ''; const alt = item.dataset.alt || ''; @@ -77,7 +76,6 @@ function openLightbox(index) { lightboxImage.alt = photo.alt; lightboxCaption.textContent = photo.alt; - // FIX: Show date and pubkey in the meta let metaText = ''; if (photo.date) metaText += `📅 ${photo.date}`; @@ -162,7 +160,6 @@ function renderMusicTracks(tracks, containerId, randomize = false) { const container = document.getElementById(containerId); if (!container) return; - // Filter tracks by artist const filteredTracks = tracks.filter(track => { let artist = ''; if (track.tags) { @@ -180,11 +177,9 @@ function renderMusicTracks(tracks, containerId, randomize = false) { let selected; if (randomize) { - // Randomize: shuffle and get first 6 const shuffled = shuffleArray(filteredTracks); selected = shuffled.slice(0, 6); } else { - // Chronological: sort by created_at (newest first) and get first 6 const sorted = [...filteredTracks].sort((a, b) => b.created_at - a.created_at); selected = sorted.slice(0, 6); } @@ -270,18 +265,15 @@ function handleLyricsToggle() { // 4. PICTURES RENDERER // ============================================ -// Render random pictures (6 max) function renderRandomPictures(picturesData, containerId, randomize = false) { const container = document.getElementById(containerId); if (!container) return; let selected; if (randomize) { - // Randomize: shuffle and get first 6 const shuffled = shuffleArray(picturesData); selected = shuffled.slice(0, 6); } else { - // Chronological: sort by created_at (newest first) and get first 6 const sorted = [...picturesData].sort((a, b) => b.created_at - a.created_at); selected = sorted.slice(0, 6); } @@ -337,11 +329,9 @@ function renderRandomVideos(videosData, containerId, randomize = false) { let selected; if (randomize) { - // Randomize: shuffle and get first 2 const shuffled = shuffleArray(videosData); selected = shuffled.slice(0, 2); } else { - // Chronological: sort by created_at (newest first) and get first 2 const sorted = [...videosData].sort((a, b) => b.created_at - a.created_at); selected = sorted.slice(0, 2); } @@ -429,7 +419,65 @@ function refreshVideos() { // ============================================ document.addEventListener('DOMContentLoaded', function() { - // ... sticky nav, read more, smooth scrolling code ... + // Sticky Navigation + const stickyNav = document.getElementById('stickyNav'); + const mainHeader = document.querySelector('.main-header'); + let lastScrollY = window.scrollY; + let ticking = false; + + function updateStickyNav() { + const scrollY = window.scrollY; + const headerHeight = mainHeader ? mainHeader.offsetHeight : 400; + if (scrollY > headerHeight - 100) { + stickyNav.classList.add('visible'); + } else { + stickyNav.classList.remove('visible'); + } + lastScrollY = scrollY; + } + + window.addEventListener('scroll', function() { + if (!ticking) { + window.requestAnimationFrame(function() { + updateStickyNav(); + ticking = false; + }); + ticking = true; + } + }); + + setTimeout(updateStickyNav, 100); + + // Read More toggle for blog posts + document.querySelectorAll('.read-more-toggle').forEach(button => { + button.addEventListener('click', function() { + const content = this.nextElementSibling; + if (content.style.display === 'none') { + content.style.display = 'block'; + this.innerHTML = 'Read Less'; + } else { + content.style.display = 'none'; + this.innerHTML = 'Read More'; + } + }); + }); + + // Smooth scrolling for navigation links (both main nav and sticky nav) + document.querySelectorAll('nav a').forEach(link => { + link.addEventListener('click', function(e) { + e.preventDefault(); + const targetId = this.getAttribute('href'); + const targetElement = document.querySelector(targetId); + if (targetElement) { + const navHeight = stickyNav.offsetHeight; + const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - navHeight - 20; + window.scrollTo({ + top: targetPosition, + behavior: 'smooth' + }); + } + }); + }); // Initialize Music (chronological, not randomized) if (window.allMusicData && window.allMusicData.length > 0) {