|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('alpine:init', () => { |
|
|
|
|
|
const navigationAreas = window.navigationAreas || []; |
|
|
|
|
|
|
|
|
const areaTopicsMap = {}; |
|
|
navigationAreas.forEach(area => { |
|
|
areaTopicsMap[area.id] = { |
|
|
title: area.navTitle, |
|
|
topics: area.topics.map(topic => ({ |
|
|
id: topic.id, |
|
|
name: topic.navName |
|
|
})) |
|
|
}; |
|
|
}); |
|
|
|
|
|
|
|
|
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() { |
|
|
|
|
|
if (window.Alpine) { |
|
|
const event = new CustomEvent('navigation-updated', { |
|
|
detail: { |
|
|
area: this.currentArea, |
|
|
topic: this.currentTopic, |
|
|
page: this.currentPage |
|
|
} |
|
|
}); |
|
|
window.dispatchEvent(event); |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Alpine.data('mobileTopicNav', () => ({ |
|
|
areas: navigationAreas.map(area => ({ |
|
|
id: area.id, |
|
|
title: area.navTitle, |
|
|
topics: area.topics.map(topic => ({ |
|
|
id: topic.id, |
|
|
name: topic.navName |
|
|
})) |
|
|
})) |
|
|
})); |
|
|
|
|
|
|
|
|
Alpine.data('homeHover', () => ({ |
|
|
homeHovered: false, |
|
|
|
|
|
setHomeHover(state) { |
|
|
this.homeHovered = state; |
|
|
window.dispatchEvent(new CustomEvent('home-hovered', { detail: { hovered: state } })); |
|
|
} |
|
|
})); |
|
|
|
|
|
|
|
|
Alpine.data('areaHover', () => ({ |
|
|
hoveredArea: null, |
|
|
|
|
|
areas: navigationAreas, |
|
|
|
|
|
setHover(area) { |
|
|
this.hoveredArea = area; |
|
|
this.homeHovered = false; |
|
|
|
|
|
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; |
|
|
} |
|
|
})); |
|
|
|
|
|
|
|
|
Alpine.data('subNavigation', () => ({ |
|
|
|
|
|
areaId: null, |
|
|
areaTitle: '', |
|
|
topics: [], |
|
|
currentTopic: null, |
|
|
hoveredArea: null, |
|
|
|
|
|
|
|
|
homeHovered: false, |
|
|
isHomePage: false, |
|
|
|
|
|
|
|
|
get showHomeMenu() { |
|
|
|
|
|
return this.homeHovered || this.isHomePage; |
|
|
}, |
|
|
|
|
|
get showAreaMenu() { |
|
|
|
|
|
|
|
|
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() { |
|
|
|
|
|
window.addEventListener('navigation-updated', (e) => { |
|
|
this.updateFromRouter(e.detail.area, e.detail.topic, e.detail.page); |
|
|
}); |
|
|
|
|
|
|
|
|
window.addEventListener('area-hovered', (e) => { |
|
|
this.hoveredArea = e.detail.area; |
|
|
}); |
|
|
|
|
|
|
|
|
window.addEventListener('home-hovered', (e) => { |
|
|
this.homeHovered = e.detail.hovered; |
|
|
}); |
|
|
|
|
|
|
|
|
if (window.router) { |
|
|
this.updateFromRouter( |
|
|
window.router.currentArea, |
|
|
window.router.currentTopic, |
|
|
window.router.currentPage |
|
|
); |
|
|
} |
|
|
}, |
|
|
|
|
|
updateFromRouter(area, topic, page) { |
|
|
|
|
|
this.isHomePage = page === 'home' && !area; |
|
|
|
|
|
|
|
|
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; |
|
|
} |
|
|
} |
|
|
})); |
|
|
}); |
|
|
|
|
|
|