File size: 2,607 Bytes
b31807d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

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 = '<i data-feather="book-open"></i> Single Page View';
        } else {
            showSinglePage(currentPage);
            toggleBtn.innerHTML = '<i data-feather="book"></i> 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 = '<i data-feather="book"></i> 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);
        });
    }
});