/**
* Sets up category toast functionality for mobile
*/
function setupCategoryToast() {
const toastButton = document.getElementById('category-toast-button');
const toastContainer = document.getElementById('category-toast-container');
const toastClose = document.getElementById('category-toast-close');
if (toastButton && toastContainer && toastClose) {
// Toggle toast on button click
toastButton.addEventListener('click', () => {
toastContainer.classList.toggle('active');
});
// Close toast on close button click
toastClose.addEventListener('click', () => {
toastContainer.classList.remove('active');
});
// Close toast when clicking outside
document.addEventListener('click', (e) => {
if (!toastContainer.contains(e.target) && e.target !== toastButton) {
toastContainer.classList.remove('active');
}
});
}
}/**
* Sets up theme selector functionality
*/
function setupThemeSelector() {
const themeSelect = document.getElementById('theme-select');
// Load saved theme if exists
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
document.body.dataset.theme = savedTheme;
themeSelect.value = savedTheme;
}
// Handle theme changes
themeSelect.addEventListener('change', (e) => {
const selectedTheme = e.target.value;
document.body.dataset.theme = selectedTheme;
localStorage.setItem('theme', selectedTheme);
});
}/**
* Sets up mobile menu toggle functionality
*/
function setupMobileMenu() {
const mobileMenuToggle = document.getElementById('mobile-menu-toggle');
const mainNav = document.getElementById('mainnav');
if (mobileMenuToggle && mainNav) {
mobileMenuToggle.addEventListener('click', () => {
mainNav.classList.toggle('mobile-active');
// Change icon based on menu state
const icon = mobileMenuToggle.querySelector('i');
if (mainNav.classList.contains('mobile-active')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-times');
} else {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
// Close mobile menu when a link is clicked
mainNav.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
if (window.innerWidth <= 768) { // Only on mobile screens
mainNav.classList.remove('mobile-active');
const icon = mobileMenuToggle.querySelector('i');
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
});
}
}
document.addEventListener('DOMContentLoaded', () => {
// Setup mobile menu
setupMobileMenu();
// Setup theme switching
setupThemeSelector();
// Navigation handling
setupNavigation();
// Check if marked is loaded
if (typeof marked === 'undefined') {
console.error('marked.js is not loaded!');
document.getElementById('resources-container').innerHTML = `
Error: marked.js library is not loaded properly.
`;
return;
}
// Parse and display content from README.md
parseAndDisplayContent()
.then(() => {
console.log("Content successfully parsed and displayed");
// Show section if page fragment exists
if (location.hash) {
const hashPart = location.hash.substring(1);
document.querySelector(`a[data-category='${hashPart}']`)?.click();
}
})
.catch(error => {
console.error('Error in main content processing:', error);
document.getElementById('resources-container').innerHTML = `
Error loading content: ${error.message}
`;
});
});
/**
* Sets up navigation between views
*/
function setupNavigation() {
const navHome = document.getElementById('navhome');
const navProfile = document.getElementById('nav-profile');
const navServices = document.getElementById('nav-services');
const navApps = document.getElementById('nav-apps');
navHome.addEventListener('click', (e) => {
e.preventDefault();
switchView('home-view');
});
navProfile.addEventListener('click', (e) => {
e.preventDefault();
switchView('profile-view');
loadProfileManager();
});
navServices.addEventListener('click', (e) => {
e.preventDefault();
switchView('services-view');
loadServices();
});
navApps.addEventListener('click', (e) => {
e.preventDefault();
switchView('apps-view');
loadApps();
});
}
/**
* Switches to the specified view
* @param {string} viewId - ID of the view to show
*/
function switchView(viewId) {
// Hide all views
document.querySelectorAll('.view').forEach(view => {
view.classList.remove('active');
});
// Show the selected view
document.getElementById(viewId).classList.add('active');
}
/**
* Sets up navigation between views
*/
function setupNavigation() {
const navHome = document.getElementById('navhome');
const navProfile = document.getElementById('nav-profile');
const navServices = document.getElementById('nav-services');
const navApps = document.getElementById('nav-apps');
navHome.addEventListener('click', (e) => {
e.preventDefault();
switchView('home-view');
});
navProfile.addEventListener('click', (e) => {
e.preventDefault();
switchView('profile-view');
loadProfileManager();
});
navServices.addEventListener('click', (e) => {
e.preventDefault();
switchView('services-view');
loadServices();
});
navApps.addEventListener('click', (e) => {
e.preventDefault();
switchView('apps-view');
loadApps();
});
}
/**
* Switches to the specified view
* @param {string} viewId - ID of the view to show
*/
function switchView(viewId) {
// Hide all views
document.querySelectorAll('.view').forEach(view => {
view.classList.remove('active');
});
// Show the selected view
document.getElementById(viewId).classList.add('active');
}
/**
* Loads the profile manager functionality
*/
function loadProfileManager() {
const pmContainer = document.getElementById('PM-container');
// This would normally load the profile manager from external scripts
// For now, displaying a placeholder message
pmContainer.innerHTML = `
Profile Manager_
Profile manager functionality will be loaded here.
This will integrate with the nostr-profile-manager module.
`;
}
/**
* Loads the services view
*/
function loadServices() {
const servicesContainer = document.getElementById('services-container');
// This would normally fetch services from parsed markdown or API
// For now, displaying placeholder services
servicesContainer.innerHTML = `
NIP-05 Identity Services
Providers that offer NIP-05 identity verification services for Nostr users.
`;
}
/**
* Loads the apps view
*/
function loadApps() {
const appsContainer = document.getElementById('apps-container');
// This would normally fetch apps from parsed markdown or API
// For now, displaying placeholder apps
appsContainer.innerHTML = `