document.addEventListener('DOMContentLoaded', function() { // Initialize Feather Icons feather.replace(); // Magazine page interaction const pages = document.querySelectorAll('.a4-page'); let currentPage = 0; // Show all pages by default for full magazine view function showAllPages() { pages.forEach(page => { page.style.display = 'block'; page.style.margin = '20px auto'; }); } // Show single page (for paginated view) function showSinglePage(index) { pages.forEach((page, i) => { page.style.display = i === index ? 'block' : 'none'; page.style.margin = '10mm auto'; }); } // Toggle between full view and paginated view function toggleView() { const toggleBtn = document.getElementById('view-toggle'); if (toggleBtn.textContent.includes('Single')) { showAllPages(); toggleBtn.innerHTML = ' Single Page View'; } else { showSinglePage(currentPage); toggleBtn.innerHTML = ' Full Magazine View'; } feather.replace(); } // Add view toggle button to navbar const navbar = document.querySelector('custom-navbar').shadowRoot.querySelector('.navbar-container'); const toggleBtn = document.createElement('button'); toggleBtn.id = 'view-toggle'; toggleBtn.className = 'view-toggle no-print'; toggleBtn.innerHTML = ' Full Magazine View'; toggleBtn.addEventListener('click', toggleView); navbar.insertBefore(toggleBtn, navbar.querySelector('.print-button')); // Paginated view controls document.addEventListener('keydown', function(e) { if (e.key === 'ArrowRight' && currentPage < pages.length - 1) { currentPage++; showSinglePage(currentPage); } else if (e.key === 'ArrowLeft' && currentPage > 0) { currentPage--; showSinglePage(currentPage); } }); // Initial view - show all pages showAllPages(); // Handle print functionality const printButton = document.getElementById('print-button'); if (printButton) { printButton.addEventListener('click', function() { showAllPages(); // Ensure all pages are visible for printing setTimeout(() => { window.print(); showSinglePage(currentPage); // Return to single page view after printing }, 500); }); } });