File size: 6,342 Bytes
8ed13f7
 
f00a7bc
 
 
8ed13f7
f00a7bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// alpine-init.js - Alpine.js component definitions
// Navigation data is already available (loaded in <head> before Alpine.js)

// Alpine.js data stores and components
document.addEventListener('alpine:init', () => {
    // Use navigation data from global scope (loaded in index.html <head>)
    const navigationAreas = window.navigationAreas || [];

    // Create a lookup map for easy access by area ID
    const areaTopicsMap = {};
    navigationAreas.forEach(area => {
        areaTopicsMap[area.id] = {
            title: area.navTitle,
            topics: area.topics.map(topic => ({
                id: topic.id,
                name: topic.navName
            }))
        };
    });
    
    // Global navigation state
    Alpine.store('navigation', {
        currentArea: null,
        currentTopic: null,
        currentPage: null,
        
        setArea(area) {
            this.currentArea = area;
            this.updateTopicNav();
        },
        
        setTopic(topic) {
            this.currentTopic = topic;
            this.updateTopicNav();
        },
        
        setPage(page) {
            this.currentPage = page;
            this.updateTopicNav();
        },
        
        updateTopicNav() {
            // Trigger update in topic navigation component
            if (window.Alpine) {
                const event = new CustomEvent('navigation-updated', {
                    detail: { 
                        area: this.currentArea, 
                        topic: this.currentTopic,
                        page: this.currentPage
                    }
                });
                window.dispatchEvent(event);
            }
        }
    });
    
    // Mobile Topic Navigation Component
    // Uses navigation data generated from areas.js
    Alpine.data('mobileTopicNav', () => ({
        areas: navigationAreas.map(area => ({
            id: area.id,
            title: area.navTitle,
            topics: area.topics.map(topic => ({
                id: topic.id,
                name: topic.navName
            }))
        }))
    }));
    
    // Home Hover Component
    Alpine.data('homeHover', () => ({
        homeHovered: false,
        
        setHomeHover(state) {
            this.homeHovered = state;
            window.dispatchEvent(new CustomEvent('home-hovered', { detail: { hovered: state } }));
        }
    }));
    
    // Area Hover Component (for showing topics on hover)
    Alpine.data('areaHover', () => ({
        hoveredArea: null,
        // Make navigation areas available to the template
        areas: navigationAreas,
        
        setHover(area) {
            this.hoveredArea = area;
            this.homeHovered = false; // Clear home hover when hovering area
            // Trigger update in topic navigation
            window.dispatchEvent(new CustomEvent('area-hovered', { detail: { area } }));
            window.dispatchEvent(new CustomEvent('home-hovered', { detail: { hovered: false } }));
        },
        
        clearAllHover() {
            this.hoveredArea = null;
            this.homeHovered = false;
            window.dispatchEvent(new CustomEvent('area-hovered', { detail: { area: null } }));
            window.dispatchEvent(new CustomEvent('home-hovered', { detail: { hovered: false } }));
        },
        
        isActiveArea(area) {
            return window.router && window.router.currentArea === area;
        }
    }));
    
    // Sub-Navigation Component (combines Home and Area menus)
    Alpine.data('subNavigation', () => ({
        // Area state
        areaId: null,
        areaTitle: '',
        topics: [],
        currentTopic: null,
        hoveredArea: null,
        
        // Home state
        homeHovered: false,
        isHomePage: false,
        
        // Computed properties
        get showHomeMenu() {
            // Show home menu if we're hovering over Home OR if we're on the home page
            return this.homeHovered || this.isHomePage;
        },
        
        get showAreaMenu() {
            // Show area menu if we're hovering over an area OR if we're on an area page
            // BUT hide if we're showing the home menu
            return (this.areaId !== null || this.hoveredArea !== null) && !this.showHomeMenu;
        },
        
        get displayAreaId() {
            return this.hoveredArea || this.areaId;
        },
        
        get displayAreaTitle() {
            const area = this.hoveredArea || this.areaId;
            return area && areaTopicsMap[area] ? areaTopicsMap[area].title : '';
        },
        
        get displayTopics() {
            const area = this.hoveredArea || this.areaId;
            return area && areaTopicsMap[area] ? areaTopicsMap[area].topics : [];
        },
        
        init() {
            // Listen for navigation updates
            window.addEventListener('navigation-updated', (e) => {
                this.updateFromRouter(e.detail.area, e.detail.topic, e.detail.page);
            });
            
            // Listen for area hover
            window.addEventListener('area-hovered', (e) => {
                this.hoveredArea = e.detail.area;
            });
            
            // Listen for home hover
            window.addEventListener('home-hovered', (e) => {
                this.homeHovered = e.detail.hovered;
            });
            
            // Initial update from router
            if (window.router) {
                this.updateFromRouter(
                    window.router.currentArea, 
                    window.router.currentTopic,
                    window.router.currentPage
                );
            }
        },
        
        updateFromRouter(area, topic, page) {
            // Update home page status
            this.isHomePage = page === 'home' && !area;
            
            // Update area and topic
            if (area && areaTopicsMap[area]) {
                this.areaId = area;
                this.areaTitle = areaTopicsMap[area].title;
                this.topics = areaTopicsMap[area].topics;
                this.currentTopic = topic || null;
            } else {
                this.areaId = null;
                this.areaTitle = '';
                this.topics = [];
                this.currentTopic = null;
            }
        }
    }));
});