Dashboard Temp Share Shortlinks Frames API

HTMLify

script.js
Views: 39 | Author: karbonsites
  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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
document.addEventListener('DOMContentLoaded', () => {
    // --- THEME TOGGLE LOGIC (Applies to all pages) ---
    const getTheme = () => localStorage.getItem('theme') || 'light';
    const setTheme = (theme) => {
        document.documentElement.setAttribute('data-theme', theme);
        localStorage.setItem('theme', theme);
    };

    const applyThemeToAllToggles = (theme) => {
        const toggles = document.querySelectorAll('[id^="theme-toggle-"], .theme-toggle-btn');
        toggles.forEach(toggle => {
            const iconSpan = toggle.querySelector('.material-icons');
            if (iconSpan) {
                if (theme === 'dark') {
                    iconSpan.textContent = 'brightness_5'; // Sun icon for dark mode
                } else {
                    iconSpan.textContent = 'brightness_4'; // Moon icon for light mode
                }
            }
        });
    };

    const initializeTheme = () => {
        const initialTheme = getTheme();
        setTheme(initialTheme);
        applyThemeToAllToggles(initialTheme);
    };

    const handleThemeToggle = (e) => {
        const currentTheme = getTheme();
        const newTheme = currentTheme === 'light' ? 'dark' : 'light';
        setTheme(newTheme);
        applyThemeToAllToggles(newTheme);
    };

    initializeTheme();

    document.querySelectorAll('.theme-toggle-btn, #theme-toggle-landing, #theme-toggle-login, #theme-toggle-signup, #theme-toggle-feed, #theme-toggle-profile, #theme-toggle-events, #theme-toggle-search').forEach(toggle => {
        toggle.addEventListener('click', handleThemeToggle);
    });


    // --- Page Specific Logic (Placeholder for actual interaction) ---

    // 1. Landing Page Interactions (index.html)
    if (document.getElementById('theme-toggle-landing')) {
        // Already handled by universal listener above
    }

    // 2. Auth Page Interactions (login.html, signup.html)
    if (document.getElementById('login-form') || document.getElementById('signup-form')) {
        // Placeholder for form submission logic (authentication/redirection)
        // Since we cannot implement backend logic, these will just prevent default and log.
        const forms = [document.getElementById('login-form'), document.getElementById('signup-form')];
        forms.forEach(form => {
            if (form) {
                form.addEventListener('submit', (e) => {
                    e.preventDefault();
                    console.log(`${form.id} submitted. In a real app, this would authenticate.`);
                    if (form.id === 'login-form') {
                        window.location.href = 'feed.html'; // Simulate successful login
                    } else {
                        window.location.href = 'login.html'; // Simulate successful signup
                    }
                });
            }
        });
    }

    // 3. Feed Page Interactions (feed.html)
    if (document.querySelector('.post-feed')) {
        console.log('Feed page loaded.');
        
        // Simple function to trigger fade-ins on load
        document.querySelectorAll('.post-card').forEach((card, index) => {
            card.style.transitionDelay = `${index * 0.1}s`;
            card.classList.add('fade-in-up');
        });
        
        // Apply delay to the new Create Post section
        const createArea = document.getElementById('create-post-area');
        if (createArea) {
            createArea.style.transitionDelay = '0s';
            createArea.classList.add('fade-in-up');
        }
    }

    // 4. Profile Page Interactions (profile.html)
    if (document.querySelector('.profile-main')) {
        const tabLinks = document.querySelectorAll('.tab-link');
        const tabContents = document.querySelectorAll('.tab-content');

        tabLinks.forEach(link => {
            link.addEventListener('click', function() {
                // Deactivate all links/contents
                tabLinks.forEach(l => l.classList.remove('active'));
                tabContents.forEach(c => c.classList.remove('active'));

                // Activate clicked link and corresponding content
                this.classList.add('active');
                document.getElementById(this.dataset.tab).classList.add('active');
            });
        });

        // Trigger initial fade-ins for profile section
        document.querySelector('.profile-header').classList.add('fade-in-up');
        document.querySelector('.profile-tabs').classList.add('fade-in-up', 'delay-1');
    }

    // 5. Events Page Interactions (events.html)
    if (document.querySelector('.event-list')) {
         document.querySelectorAll('.event-card').forEach((card, index) => {
            card.style.transitionDelay = `${index * 0.1}s`;
            card.classList.add('fade-in-up');
        });
    }
    
    // 6. Create Post button placeholder (functional across navigation pages)
    document.querySelectorAll('.create-btn').forEach(btn => {
        btn.addEventListener('click', (e) => {
            e.preventDefault();
            alert('Feature: Create Post Modal/Page. (Currently placeholder)');
        });
    });

    // 7. Search Page Placeholder (search.html)
    if (document.getElementById('search-input-main')) {
        const searchInput = document.getElementById('search-input-main');
        searchInput.addEventListener('input', () => {
            console.log('Searching for:', searchInput.value);
            // In a real scenario, this would trigger API calls and update the search-results-section
        });
    }

});