Files
Bookshelf/mockups/app.js
2026-10-18 19:01:01 -07:00

73 lines
2.1 KiB
JavaScript
Executable File

// Copyright 2026 Umbra Tools (umbratools.com)
// SPDX-License-Identifier: Apache-2.0
document.addEventListener('DOMContentLoaded', () => {
// Mobile navigation toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('open');
});
}
// Sticky header scroll effect
const siteNav = document.querySelector('.site-nav');
if (siteNav) {
window.addEventListener('scroll', () => {
if (window.scrollY > 250) {
siteNav.classList.add('scrolled');
} else {
siteNav.classList.remove('scrolled');
}
});
}
// Format toggles
const formatBtns = document.querySelectorAll('.format-btn');
formatBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
// Find parent container
const container = e.target.closest('.book-details') || document.body;
const btnsInContainer = container.querySelectorAll('.format-btn');
// Remove active from all in this container
btnsInContainer.forEach(b => b.classList.remove('active'));
// Add active to clicked
e.target.classList.add('active');
// Logic to filter retailers could go here based on data attributes
console.log('Format selected:', e.target.dataset.format);
});
});
// Share button
const shareBtn = document.querySelector('.share-btn');
if (shareBtn) {
shareBtn.addEventListener('click', async () => {
const url = shareBtn.dataset.url || window.location.href;
if (navigator.share) {
try {
await navigator.share({
title: document.title,
url: url
});
} catch (err) {
console.error('Error sharing:', err);
}
} else {
// Fallback to clipboard
try {
await navigator.clipboard.writeText(url);
alert('Link copied to clipboard!');
} catch (err) {
console.error('Failed to copy!', err);
}
}
});
}
});