summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/404.js54
-rw-r--r--assets/js/filters.js45
-rw-r--r--assets/js/glitch.js30
-rw-r--r--assets/js/hamburger.js83
-rw-r--r--assets/js/lightbox.js31
-rw-r--r--assets/js/main.js13
-rw-r--r--assets/js/matrix-rain.js12
-rw-r--r--assets/js/photo-utils.js476
-rw-r--r--assets/js/progress-bar.js44
-rw-r--r--assets/js/scroll-reveal.js26
-rw-r--r--assets/js/share-sidebar.js51
-rw-r--r--assets/js/theme-toggle.js18
-rw-r--r--assets/js/typing.js69
13 files changed, 894 insertions, 58 deletions
diff --git a/assets/js/404.js b/assets/js/404.js
new file mode 100644
index 0000000..c26c218
--- /dev/null
+++ b/assets/js/404.js
@@ -0,0 +1,54 @@
+/**
+ * 404.js
+ * Quote randomization and terminal animation for 404 page
+ */
+
+(function() {
+ 'use strict';
+
+ const quotes = [
+ 'The page you are looking for doesn\'t exist. But that\'s okay, nothing exists until you find it.',
+ 'A 404 is just a redirect to a new beginning.',
+ 'You found a secret path. Sadly, it leads nowhere.',
+ 'This page chose to remain unknown.',
+ 'In the quantum realm, this page exists and doesn\'t exist simultaneously.',
+ 'Sometimes the best discoveries are the ones we never intended to find.',
+ ];
+
+ const quoteText = document.getElementById('quote-text');
+ const quoteAuthor = document.getElementById('quote-author');
+ const terminalFiles = document.getElementById('terminal-files');
+
+ if (quoteText && quoteAuthor) {
+ const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
+ quoteText.textContent = randomQuote;
+ quoteAuthor.textContent = '— 404 Philosopher';
+ }
+
+ if (terminalFiles) {
+ const files = [
+ 'post-01-security.md',
+ 'post-02-web-dev.md',
+ 'post-03-bash-tips.md',
+ 'about.md',
+ 'contact.md',
+ ];
+
+ files.forEach((file) => {
+ const line = document.createElement('div');
+ line.textContent = file;
+ terminalFiles.appendChild(line);
+ });
+ }
+
+ // Listen for search (if implemented)
+ const searchBtn = document.querySelector('.search-box button');
+ if (searchBtn) {
+ searchBtn.addEventListener('click', () => {
+ const input = document.querySelector('.search-box input');
+ if (input && input.value) {
+ window.location.href = `/articles/?search=${encodeURIComponent(input.value)}`;
+ }
+ });
+ }
+})();
diff --git a/assets/js/filters.js b/assets/js/filters.js
index 64d9c57..f7fa6a6 100644
--- a/assets/js/filters.js
+++ b/assets/js/filters.js
@@ -1,28 +1,37 @@
-// filters.js
+/**
+ * filters.js
+ * Article filtering by type on the articles page
+ */
+
(function() {
- const filterBtns = document.querySelectorAll('.filter-btn');
- const feedList = document.getElementById('articles-feed');
- const cards = feedList ? feedList.querySelectorAll('.post-card') : [];
+ 'use strict';
- if (!filterBtns.length || !cards.length) return;
+ const filterBtns = document.querySelectorAll('.filter-btn');
+ const timelineItems = document.querySelectorAll('.timeline-item');
- filterBtns.forEach(btn => {
- btn.addEventListener('click', function() {
- const filter = this.dataset.filter;
+ filterBtns.forEach((btn) => {
+ btn.addEventListener('click', () => {
+ const filter = btn.getAttribute('data-filter');
// Update active button
- filterBtns.forEach(b => b.classList.remove('active'));
- this.classList.add('active');
+ filterBtns.forEach((b) => b.classList.remove('active'));
+ btn.classList.add('active');
- // Filter cards
- cards.forEach(card => {
- const cardType = card.querySelector('.post-type-badge')?.classList[1];
- const matches = filter === 'all' || cardType === filter;
- card.style.display = matches ? '' : 'none';
- });
+ // Filter articles
+ timelineItems.forEach((item) => {
+ const type = item.getAttribute('data-type');
- // Scroll to top
- window.scrollTo({ top: 0, behavior: 'smooth' });
+ if (filter === 'all' || type === filter) {
+ item.classList.add('visible');
+ } else {
+ item.classList.remove('visible');
+ }
+ });
});
});
+
+ // Show all on load
+ timelineItems.forEach((item) => {
+ item.classList.add('visible');
+ });
})();
diff --git a/assets/js/glitch.js b/assets/js/glitch.js
new file mode 100644
index 0000000..85f8a00
--- /dev/null
+++ b/assets/js/glitch.js
@@ -0,0 +1,30 @@
+/**
+ * glitch.js
+ * Random glitch effect on .hero-name every 4-11 seconds
+ */
+
+export function initGlitch() {
+ 'use strict';
+
+ const heroName = document.querySelector('.hero-name');
+ if (!heroName) return;
+
+ if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
+
+ function triggerGlitch() {
+ heroName.classList.add('is-glitching');
+ setTimeout(() => {
+ heroName.classList.remove('is-glitching');
+ }, 450);
+ }
+
+ function scheduleNextGlitch() {
+ const delay = Math.random() * 7000 + 4000; // 4-11 seconds
+ setTimeout(() => {
+ triggerGlitch();
+ scheduleNextGlitch();
+ }, delay);
+ }
+
+ scheduleNextGlitch();
+}
diff --git a/assets/js/hamburger.js b/assets/js/hamburger.js
new file mode 100644
index 0000000..1d27633
--- /dev/null
+++ b/assets/js/hamburger.js
@@ -0,0 +1,83 @@
+/**
+ * hamburger.js
+ * Hamburger menu toggle with focus trap and keyboard navigation
+ */
+
+export function initHamburger() {
+ 'use strict';
+
+ const hamburgerBtn = document.getElementById('hamburger-btn');
+ const menuOverlay = document.getElementById('menu-overlay');
+ const menuLinks = document.querySelectorAll('.menu-links a');
+ const themeSwitch = document.getElementById('theme-switch');
+
+ if (!hamburgerBtn || !menuOverlay) return;
+
+ // Toggle menu on hamburger click
+ hamburgerBtn.addEventListener('click', () => {
+ const isOpen = hamburgerBtn.getAttribute('aria-expanded') === 'true';
+ setMenuOpen(!isOpen);
+ });
+
+ // Close menu on overlay click
+ menuOverlay.addEventListener('click', (e) => {
+ if (e.target === menuOverlay) {
+ setMenuOpen(false);
+ }
+ });
+
+ // Close menu on menu link click
+ menuLinks.forEach((link) => {
+ link.addEventListener('click', () => {
+ setMenuOpen(false);
+ });
+ });
+
+ // Close menu on Escape key
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Escape') {
+ setMenuOpen(false);
+ }
+ });
+
+ // Focus trap: Tab through menu items and theme switch
+ menuOverlay.addEventListener('keydown', (e) => {
+ if (e.key !== 'Tab') return;
+
+ const focusableElements = Array.from(
+ menuOverlay.querySelectorAll('a, button')
+ );
+ const firstElement = focusableElements[0];
+ const lastElement = focusableElements[focusableElements.length - 1];
+
+ if (e.shiftKey) {
+ if (document.activeElement === firstElement) {
+ lastElement.focus();
+ e.preventDefault();
+ }
+ } else {
+ if (document.activeElement === lastElement) {
+ firstElement.focus();
+ e.preventDefault();
+ }
+ }
+ });
+
+ function setMenuOpen(isOpen) {
+ hamburgerBtn.setAttribute('aria-expanded', isOpen);
+ hamburgerBtn.classList.toggle('active', isOpen);
+ menuOverlay.classList.toggle('active', isOpen);
+
+ if (isOpen) {
+ document.body.style.overflow = 'hidden';
+ // Focus the first menu link
+ const firstLink = menuLinks[0];
+ if (firstLink) {
+ setTimeout(() => firstLink.focus(), 100);
+ }
+ } else {
+ document.body.style.overflow = '';
+ hamburgerBtn.focus();
+ }
+ }
+}
diff --git a/assets/js/lightbox.js b/assets/js/lightbox.js
new file mode 100644
index 0000000..81c3613
--- /dev/null
+++ b/assets/js/lightbox.js
@@ -0,0 +1,31 @@
+/**
+ * lightbox.js
+ * Photo lightbox initialization
+ */
+
+(function() {
+ 'use strict';
+
+ if (typeof PhotoUtils === 'undefined') return;
+
+ const photoGrid = document.querySelector('.photo-grid[data-lightbox="true"]');
+ if (!photoGrid) return;
+
+ const photoCards = photoGrid.querySelectorAll('.photo-card');
+ const photosData = [];
+
+ photoCards.forEach((card, index) => {
+ const figure = card.querySelector('figure');
+ const img = card.querySelector('img');
+ photosData.push({
+ index,
+ src: figure.getAttribute('data-src') || img.src,
+ alt: figure.getAttribute('data-alt') || img.alt,
+ caption: figure.getAttribute('data-caption'),
+ location: figure.getAttribute('data-location'),
+ });
+ });
+
+ // Initialize lightbox with PhotoUtils
+ PhotoUtils.initLightbox('.photo-grid', photosData);
+})();
diff --git a/assets/js/main.js b/assets/js/main.js
index 5b5848c..ee6b24f 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -3,3 +3,16 @@ import './theme-toggle.js';
import './matrix-rain.js';
import './progress-bar.js';
import './copy-code.js';
+import { initHamburger } from './hamburger.js';
+import { initGlitch } from './glitch.js';
+import { initTyping } from './typing.js';
+import { initScrollReveal } from './scroll-reveal.js';
+import { initShareSidebar } from './share-sidebar.js';
+
+document.addEventListener('DOMContentLoaded', () => {
+ initHamburger();
+ initGlitch();
+ initTyping();
+ initScrollReveal();
+ initShareSidebar();
+});
diff --git a/assets/js/matrix-rain.js b/assets/js/matrix-rain.js
index 479231f..742b0bd 100644
--- a/assets/js/matrix-rain.js
+++ b/assets/js/matrix-rain.js
@@ -7,11 +7,19 @@
const ctx = canvas.getContext('2d');
const CHARS = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン0123456789ABCDEF<>/\\|{}[]$#@!';
const FS = 14; // font size / column width in px
+ const mode = canvas.getAttribute('data-mode') || 'background'; // 'hero' or 'background'
let cols, drops, raf;
function init() {
- canvas.width = canvas.offsetWidth;
- canvas.height = canvas.offsetHeight;
+ if (mode === 'hero') {
+ // Hero mode: size relative to canvas element's offsetWidth
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ } else {
+ // Background mode: size to full viewport
+ canvas.width = window.innerWidth;
+ canvas.height = window.innerHeight;
+ }
cols = Math.floor(canvas.width / FS) + 1;
drops = Array.from({ length: cols }, () => Math.random() * -(canvas.height / FS));
}
diff --git a/assets/js/photo-utils.js b/assets/js/photo-utils.js
new file mode 100644
index 0000000..32ede76
--- /dev/null
+++ b/assets/js/photo-utils.js
@@ -0,0 +1,476 @@
+(function() {
+ 'use strict';
+
+ // Internal state
+ let currentPhotoIndex = 0;
+ let photosData = [];
+ let isOpen = false;
+ let exifData = {};
+ let options = {
+ swipeEnabled: true,
+ keyboardEnabled: true,
+ extractEXIF: true,
+ onOpen: null,
+ onClose: null,
+ };
+
+ // Lightbox DOM elements (created on first init)
+ let lightboxModal = null;
+ let lightboxImage = null;
+ let lightboxCaption = null;
+ let lightboxSidebar = null;
+
+ /**
+ * Initialize lightbox for a photo collection
+ * @param {string} containerSelector - CSS selector for photo container
+ * @param {Array} photos - Array of photo objects: {src, alt, caption, location}
+ * @param {Object} opts - Options: {swipeEnabled, keyboardEnabled, extractEXIF, onOpen, onClose}
+ * @returns {Object} - {openLightbox, closeLightbox}
+ */
+ function initLightbox(containerSelector, photos, opts = {}) {
+ photosData = photos;
+ options = { ...options, ...opts };
+
+ // Merge options with defaults
+ const container = document.querySelector(containerSelector);
+ if (!container) {
+ console.error('Photo container not found:', containerSelector);
+ return { openLightbox: () => {}, closeLightbox: () => {} };
+ }
+
+ // Attach click listeners to all figures in the container
+ const figures = container.querySelectorAll('figure[data-photo-index]');
+ figures.forEach((figure) => {
+ figure.addEventListener('click', () => {
+ const index = parseInt(figure.dataset.photoIndex, 10);
+ openLightbox(index);
+ });
+ });
+
+ // Return public API
+ return {
+ openLightbox,
+ closeLightbox,
+ };
+ }
+
+ /**
+ * Open lightbox to a specific photo
+ * @param {number} photoIndex - 0-based index into photosData array
+ */
+ function openLightbox(photoIndex) {
+ if (photoIndex < 0 || photoIndex >= photosData.length) {
+ console.warn('Invalid photo index:', photoIndex);
+ return;
+ }
+
+ currentPhotoIndex = photoIndex;
+ isOpen = true;
+
+ // Create lightbox DOM if it doesn't exist
+ if (!lightboxModal) {
+ createLightboxDOM();
+ }
+
+ // Populate lightbox with current photo
+ updateLightboxContent();
+
+ // Show modal
+ lightboxModal.classList.add('visible');
+ document.body.style.overflow = 'hidden';
+
+ // Extract EXIF if enabled
+ if (options.extractEXIF) {
+ extractEXIFForCurrentPhoto();
+ }
+
+ // Attach event listeners
+ attachEventListeners();
+
+ // Callback
+ if (options.onOpen) {
+ options.onOpen(photoIndex);
+ }
+ }
+
+ /**
+ * Close lightbox
+ */
+ function closeLightbox() {
+ if (!isOpen || !lightboxModal) return;
+
+ isOpen = false;
+ lightboxModal.classList.remove('visible');
+ document.body.style.overflow = '';
+
+ // Detach event listeners
+ detachEventListeners();
+
+ // Callback
+ if (options.onClose) {
+ options.onClose();
+ }
+ }
+
+ /**
+ * Create lightbox HTML structure and inject into DOM
+ */
+ function createLightboxDOM() {
+ lightboxModal = document.createElement('div');
+ lightboxModal.className = 'photo-lightbox';
+
+ lightboxModal.innerHTML = `
+ <div class="photo-lightbox-backdrop"></div>
+ <div class="photo-lightbox-container">
+ <button class="photo-lightbox-close" aria-label="Close lightbox">×</button>
+
+ <button class="photo-lightbox-prev" aria-label="Previous photo">←</button>
+
+ <div class="photo-lightbox-content">
+ <img class="photo-lightbox-image" src="" alt="">
+ <div class="photo-lightbox-caption"></div>
+ </div>
+
+ <button class="photo-lightbox-next" aria-label="Next photo">→</button>
+
+ <div class="photo-lightbox-sidebar">
+ <div class="photo-lightbox-sidebar-content"></div>
+ </div>
+ </div>
+ `;
+
+ document.body.appendChild(lightboxModal);
+
+ // Cache element references
+ lightboxImage = lightboxModal.querySelector('.photo-lightbox-image');
+ lightboxCaption = lightboxModal.querySelector('.photo-lightbox-caption');
+ lightboxSidebar = lightboxModal.querySelector('.photo-lightbox-sidebar-content');
+
+ // Attach close button and backdrop click
+ lightboxModal.querySelector('.photo-lightbox-close').addEventListener('click', closeLightbox);
+ lightboxModal.querySelector('.photo-lightbox-backdrop').addEventListener('click', closeLightbox);
+
+ // Attach navigation buttons
+ lightboxModal.querySelector('.photo-lightbox-prev').addEventListener('click', () => navigate(-1));
+ lightboxModal.querySelector('.photo-lightbox-next').addEventListener('click', () => navigate(1));
+ }
+
+ /**
+ * Update lightbox content with current photo
+ */
+ function updateLightboxContent() {
+ const photo = photosData[currentPhotoIndex];
+ if (!photo) return;
+
+ lightboxImage.src = photo.src;
+ lightboxImage.alt = photo.alt || '';
+
+ // Caption
+ if (photo.caption) {
+ lightboxCaption.textContent = photo.caption;
+ lightboxCaption.style.display = 'block';
+ } else {
+ lightboxCaption.style.display = 'none';
+ }
+
+ // Update prev/next button states
+ const prevBtn = lightboxModal.querySelector('.photo-lightbox-prev');
+ const nextBtn = lightboxModal.querySelector('.photo-lightbox-next');
+ prevBtn.disabled = currentPhotoIndex === 0;
+ nextBtn.disabled = currentPhotoIndex === photosData.length - 1;
+ }
+
+ /**
+ * Navigate to previous or next photo
+ * @param {number} direction - -1 for prev, 1 for next
+ */
+ function navigate(direction) {
+ const newIndex = currentPhotoIndex + direction;
+ if (newIndex >= 0 && newIndex < photosData.length) {
+ currentPhotoIndex = newIndex;
+ updateLightboxContent();
+
+ // Reset EXIF data and re-extract if enabled
+ exifData = {};
+ if (options.extractEXIF) {
+ extractEXIFForCurrentPhoto();
+ }
+ }
+ }
+
+ /**
+ * Extract EXIF data from current photo image element
+ */
+ function extractEXIFForCurrentPhoto() {
+ extractEXIF(lightboxImage).then((data) => {
+ exifData = data;
+ updateSidebarContent();
+ });
+ }
+
+ /**
+ * Update sidebar with EXIF and location data
+ */
+ function updateSidebarContent() {
+ const photo = photosData[currentPhotoIndex];
+ let sidebarHTML = '';
+
+ // Always show location if provided
+ if (photo.location) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">Location</div>
+ <div class="photo-metadata-value">${photo.location}</div>
+ </div>
+ `;
+ }
+
+ // Show EXIF fields if available
+ if (Object.keys(exifData).length > 0) {
+ sidebarHTML += `
+ <div class="photo-metadata-divider"></div>
+ <div class="photo-metadata-label">Camera</div>
+ `;
+
+ if (exifData.camera) {
+ sidebarHTML += `
+ <div class="photo-metadata-value">${exifData.camera}</div>
+ `;
+ }
+ if (exifData.lens) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">Lens</div>
+ <div class="photo-metadata-value">${exifData.lens}</div>
+ </div>
+ `;
+ }
+ if (exifData.focalLength) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">Focal Length</div>
+ <div class="photo-metadata-value">${exifData.focalLength}</div>
+ </div>
+ `;
+ }
+ if (exifData.aperture) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">Aperture</div>
+ <div class="photo-metadata-value">${exifData.aperture}</div>
+ </div>
+ `;
+ }
+ if (exifData.shutterSpeed) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">Shutter Speed</div>
+ <div class="photo-metadata-value">${exifData.shutterSpeed}</div>
+ </div>
+ `;
+ }
+ if (exifData.iso) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">ISO</div>
+ <div class="photo-metadata-value">${exifData.iso}</div>
+ </div>
+ `;
+ }
+ if (exifData.dateTaken) {
+ sidebarHTML += `
+ <div class="photo-metadata-field">
+ <div class="photo-metadata-label">Date Taken</div>
+ <div class="photo-metadata-value">${exifData.dateTaken}</div>
+ </div>
+ `;
+ }
+ }
+
+ // Show or hide sidebar based on whether there's content
+ const sidebarContainer = lightboxModal.querySelector('.photo-lightbox-sidebar');
+ if (sidebarHTML) {
+ lightboxSidebar.innerHTML = sidebarHTML;
+ sidebarContainer.classList.add('visible');
+ } else {
+ sidebarContainer.classList.remove('visible');
+ }
+ }
+
+ /**
+ * Extract EXIF data from an image element using exif-js library
+ * @param {HTMLImageElement} imageElement - Image to read EXIF from
+ * @returns {Promise} - Resolves to {camera, lens, iso, aperture, shutterSpeed, focalLength, dateTaken}
+ */
+ function extractEXIF(imageElement) {
+ return new Promise((resolve) => {
+ // If exif-js is not loaded, return empty object
+ if (typeof EXIF === 'undefined') {
+ console.warn('exif-js library not loaded');
+ resolve({});
+ return;
+ }
+
+ EXIF.getData(imageElement, function() {
+ const data = {
+ camera: EXIF.getTag(this, 'Model'),
+ lens: EXIF.getTag(this, 'LensModel'),
+ iso: EXIF.getTag(this, 'ISOSpeedRatings'),
+ aperture: formatAperture(EXIF.getTag(this, 'FNumber')),
+ shutterSpeed: formatShutterSpeed(EXIF.getTag(this, 'ExposureTime')),
+ focalLength: formatFocalLength(EXIF.getTag(this, 'FocalLength')),
+ dateTaken: EXIF.getTag(this, 'DateTime'),
+ };
+
+ // Filter out undefined values
+ Object.keys(data).forEach(key => {
+ if (data[key] === undefined) {
+ delete data[key];
+ }
+ });
+
+ resolve(data);
+ });
+ });
+ }
+
+ /**
+ * Format aperture value (f-number)
+ */
+ function formatAperture(value) {
+ if (!value) return null;
+ if (typeof value === 'object' && value.numerator !== undefined) {
+ return `f/${(value.numerator / value.denominator).toFixed(1)}`;
+ }
+ return `f/${value}`;
+ }
+
+ /**
+ * Format shutter speed (exposure time)
+ */
+ function formatShutterSpeed(value) {
+ if (!value) return null;
+ if (typeof value === 'object' && value.numerator !== undefined) {
+ const speed = value.numerator / value.denominator;
+ if (speed >= 1) {
+ return `${speed.toFixed(1)}s`;
+ }
+ return `1/${Math.round(1 / speed)}`;
+ }
+ return value;
+ }
+
+ /**
+ * Format focal length
+ */
+ function formatFocalLength(value) {
+ if (!value) return null;
+ if (typeof value === 'object' && value.numerator !== undefined) {
+ return `${(value.numerator / value.denominator).toFixed(0)}mm`;
+ }
+ return `${value}mm`;
+ }
+
+ /**
+ * Attach event listeners (swipe, keyboard, etc.)
+ */
+ function attachEventListeners() {
+ if (options.swipeEnabled) {
+ attachSwipeListeners();
+ }
+ if (options.keyboardEnabled) {
+ attachKeyboardListeners();
+ }
+ }
+
+ /**
+ * Detach event listeners to prevent memory leaks
+ */
+ function detachEventListeners() {
+ if (options.swipeEnabled) {
+ detachSwipeListeners();
+ }
+ if (options.keyboardEnabled) {
+ detachKeyboardListeners();
+ }
+ }
+
+ /**
+ * Touch swipe event listeners
+ */
+ let swipeStartX = 0;
+ let swipeStartY = 0;
+
+ function onTouchStart(e) {
+ swipeStartX = e.touches[0].clientX;
+ swipeStartY = e.touches[0].clientY;
+ }
+
+ function onTouchEnd(e) {
+ const swipeEndX = e.changedTouches[0].clientX;
+ const swipeEndY = e.changedTouches[0].clientY;
+ const diffX = swipeEndX - swipeStartX;
+ const diffY = swipeEndY - swipeStartY;
+
+ // Only consider horizontal swipe if delta-x > delta-y
+ if (Math.abs(diffX) > Math.abs(diffY) && Math.abs(diffX) > 50) {
+ if (diffX > 0) {
+ // Swiped right: go to previous
+ navigate(-1);
+ } else {
+ // Swiped left: go to next
+ navigate(1);
+ }
+ }
+ }
+
+ function attachSwipeListeners() {
+ lightboxModal.addEventListener('touchstart', onTouchStart, false);
+ lightboxModal.addEventListener('touchend', onTouchEnd, false);
+ }
+
+ function detachSwipeListeners() {
+ lightboxModal.removeEventListener('touchstart', onTouchStart, false);
+ lightboxModal.removeEventListener('touchend', onTouchEnd, false);
+ }
+
+ /**
+ * Keyboard event listeners
+ */
+ function onKeyDown(e) {
+ if (!isOpen) return;
+
+ switch (e.key) {
+ case 'ArrowLeft':
+ navigate(-1);
+ e.preventDefault();
+ break;
+ case 'ArrowRight':
+ navigate(1);
+ e.preventDefault();
+ break;
+ case 'Escape':
+ closeLightbox();
+ e.preventDefault();
+ break;
+ default:
+ break;
+ }
+ }
+
+ function attachKeyboardListeners() {
+ document.addEventListener('keydown', onKeyDown);
+ }
+
+ function detachKeyboardListeners() {
+ document.removeEventListener('keydown', onKeyDown);
+ }
+
+ // Expose public API
+ window.PhotoUtils = {
+ initLightbox,
+ extractEXIF,
+ openLightbox,
+ closeLightbox,
+ };
+})();
diff --git a/assets/js/progress-bar.js b/assets/js/progress-bar.js
index bc8b70a..e171f4f 100644
--- a/assets/js/progress-bar.js
+++ b/assets/js/progress-bar.js
@@ -1,38 +1,20 @@
-// progress-bar.js
+/**
+ * progress-bar.js
+ * Reading progress indicator for articles
+ */
+
(function() {
- const progressBar = document.querySelector('.reading-progress');
- if (!progressBar) return;
+ 'use strict';
- // Only enable on pages with substantial content
- const mainContent = document.querySelector('main');
- if (!mainContent) return;
+ const progressBar = document.getElementById('progress-bar');
+ if (!progressBar) return;
- function updateProgress() {
- // Calculate scroll percentage
- const windowHeight = window.innerHeight;
- const docHeight = document.documentElement.scrollHeight - windowHeight;
+ window.addEventListener('scroll', () => {
+ const windowHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrolled = window.scrollY;
- const percent = docHeight > 0 ? (scrolled / docHeight) * 100 : 0;
+ const progress = windowHeight > 0 ? (scrolled / windowHeight) * 100 : 0;
- progressBar.style.width = percent + '%';
- }
-
- // Mark body as scrollable if there's significant content
- const contentHeight = mainContent.offsetHeight;
- if (contentHeight > window.innerHeight * 1.5) {
- document.body.classList.add('scrollable');
- }
-
- // Use requestAnimationFrame for smooth updates
- let ticking = false;
- window.addEventListener('scroll', function() {
- if (!ticking) {
- requestAnimationFrame(updateProgress);
- ticking = true;
- setTimeout(() => { ticking = false; }, 100);
- }
+ progressBar.style.width = progress + '%';
+ progressBar.setAttribute('aria-valuenow', Math.round(progress));
}, { passive: true });
-
- // Initial update
- updateProgress();
})();
diff --git a/assets/js/scroll-reveal.js b/assets/js/scroll-reveal.js
new file mode 100644
index 0000000..ab099c0
--- /dev/null
+++ b/assets/js/scroll-reveal.js
@@ -0,0 +1,26 @@
+/**
+ * scroll-reveal.js
+ * IntersectionObserver for revealing elements on scroll
+ */
+
+export function initScrollReveal() {
+ 'use strict';
+
+ const revealElements = document.querySelectorAll('.reveal');
+ if (!revealElements.length) return;
+
+ const observer = new IntersectionObserver((entries) => {
+ entries.forEach((entry) => {
+ if (entry.isIntersecting) {
+ entry.target.classList.add('revealed');
+ observer.unobserve(entry.target);
+ }
+ });
+ }, {
+ threshold: 0.1,
+ });
+
+ revealElements.forEach((el) => {
+ observer.observe(el);
+ });
+}
diff --git a/assets/js/share-sidebar.js b/assets/js/share-sidebar.js
new file mode 100644
index 0000000..81e5f6c
--- /dev/null
+++ b/assets/js/share-sidebar.js
@@ -0,0 +1,51 @@
+/**
+ * share-sidebar.js
+ * Social sharing sidebar with copy-to-clipboard
+ */
+
+export function initShareSidebar() {
+ 'use strict';
+
+ const sidebar = document.getElementById('share-sidebar');
+ const copyBtn = document.getElementById('share-copy');
+
+ if (!sidebar) return;
+
+ // Share button handlers
+ const shareBtns = sidebar.querySelectorAll('.share-btn[data-platform]');
+ shareBtns.forEach((btn) => {
+ btn.addEventListener('click', () => {
+ const platform = btn.getAttribute('data-platform');
+ const url = sidebar.getAttribute('data-url');
+ const title = sidebar.getAttribute('data-title');
+
+ const shareUrls = {
+ whatsapp: `https://wa.me/?text=${encodeURIComponent(title + ' ' + url)}`,
+ telegram: `https://t.me/share/url?url=${encodeURIComponent(url)}&text=${encodeURIComponent(title)}`,
+ linkedin: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`,
+ twitter: `https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(title)}`,
+ facebook: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`,
+ reddit: `https://reddit.com/submit?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`,
+ email: `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(url)}`,
+ };
+
+ if (shareUrls[platform]) {
+ window.open(shareUrls[platform], '_blank');
+ }
+ });
+ });
+
+ // Copy to clipboard
+ if (copyBtn) {
+ copyBtn.addEventListener('click', () => {
+ const url = sidebar.getAttribute('data-url');
+ navigator.clipboard.writeText(url).then(() => {
+ const originalText = copyBtn.innerHTML;
+ copyBtn.innerHTML = '✓';
+ setTimeout(() => {
+ copyBtn.innerHTML = originalText;
+ }, 2000);
+ });
+ });
+ }
+}
diff --git a/assets/js/theme-toggle.js b/assets/js/theme-toggle.js
index 9f0fd5a..e03fce7 100644
--- a/assets/js/theme-toggle.js
+++ b/assets/js/theme-toggle.js
@@ -45,21 +45,25 @@
// Setup toggle button
function setupToggleButton() {
- const btn = document.getElementById('theme-toggle-btn');
+ const btn = document.getElementById('theme-switch');
if (btn) {
btn.addEventListener('click', toggleTheme);
- updateToggleButtonLabel();
+ updateToggleButtonUI();
- // Listen for theme changes to update button label
- window.addEventListener('theme-changed', updateToggleButtonLabel);
+ // Listen for theme changes to update button UI
+ window.addEventListener('theme-changed', updateToggleButtonUI);
}
}
- function updateToggleButtonLabel() {
- const btn = document.getElementById('theme-toggle-btn');
+ function updateToggleButtonUI() {
+ const btn = document.getElementById('theme-switch');
if (btn) {
const current = getCurrentTheme();
- btn.textContent = current === 'dark' ? '☀️ light' : '🌙 dark';
+ if (current === 'light') {
+ btn.classList.add('light');
+ } else {
+ btn.classList.remove('light');
+ }
}
}
diff --git a/assets/js/typing.js b/assets/js/typing.js
new file mode 100644
index 0000000..369fed7
--- /dev/null
+++ b/assets/js/typing.js
@@ -0,0 +1,69 @@
+/**
+ * typing.js
+ * Typing animation for .hero-role / #typed element
+ */
+
+export function initTyping() {
+ 'use strict';
+
+ const typedElement = document.getElementById('typed');
+ if (!typedElement) return;
+
+ const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
+ const phrasesJson = typedElement.getAttribute('data-phrases');
+ let phrases = [];
+
+ if (phrasesJson) {
+ try {
+ phrases = JSON.parse(phrasesJson);
+ } catch (e) {
+ console.warn('Failed to parse typing phrases:', e);
+ phrases = ['Security & Web Dev', 'WordPress Developer'];
+ }
+ }
+
+ if (!phrases.length) return;
+
+ let currentPhraseIndex = 0;
+ let currentCharIndex = 0;
+ let isDeleting = false;
+
+ function type() {
+ const phrase = phrases[currentPhraseIndex];
+ const speed = isDeleting ? 50 : 100;
+
+ if (isDeleting) {
+ currentCharIndex--;
+ } else {
+ currentCharIndex++;
+ }
+
+ typedElement.textContent = phrase.substring(0, currentCharIndex);
+
+ // Add cursor
+ if (!isDeleting && currentCharIndex === phrase.length) {
+ typedElement.innerHTML += '<span class="cursor"></span>';
+ } else if (isDeleting && currentCharIndex === 0) {
+ currentPhraseIndex = (currentPhraseIndex + 1) % phrases.length;
+ isDeleting = false;
+ setTimeout(type, 500);
+ return;
+ } else {
+ typedElement.innerHTML = phrase.substring(0, currentCharIndex) + '<span class="cursor"></span>';
+ }
+
+ if (!isDeleting && currentCharIndex === phrase.length) {
+ isDeleting = true;
+ setTimeout(type, 2000);
+ } else {
+ setTimeout(type, prefersReducedMotion ? 0 : speed);
+ }
+ }
+
+ if (prefersReducedMotion) {
+ // Just show the first phrase without animation
+ typedElement.textContent = phrases[0];
+ } else {
+ type();
+ }
+}