/******************************* navigation.js *******************************/ // Grab needed DOM elements for navigation const navHome = document.getElementById("navHome"); const navEducation = document.getElementById("navEducation"); const navPositions = document.getElementById("navPositions"); const navAccount = document.getElementById("navAccount"); const navTrade = document.getElementById("navTrade"); const navWatchlist = document.getElementById("navWatchlist"); const navLeaderboard = document.getElementById("navLeaderboard"); const navAdmin = document.getElementById("navAdmin"); const navAdminTrades = document.getElementById("navAdminTrades"); const homeSection = document.getElementById("homeSection"); const educationSection = document.getElementById("educationSection"); const positionsSection = document.getElementById("positionsSection"); const accountSection = document.getElementById("accountSection"); const profileSection = document.getElementById("profileSection"); const tradeSection = document.getElementById("tradeSection"); const watchlistSection = document.getElementById("watchlistSection"); const leaderboardSection = document.getElementById("leaderboardSection"); const adminSection = document.getElementById("adminSection"); const adminTradesSection = document.getElementById("adminTradesSection"); // Hamburger menu const hamburger = document.getElementById("hamburger"); const navLinks = document.getElementById("navLinks"); // Toggle nav menu on mobile hamburger.addEventListener("click", () => { navLinks.classList.toggle("active"); }); // Close the mobile menu when a link is clicked navLinks.addEventListener("click", (e) => { if (e.target.tagName === 'A') { navLinks.classList.remove("active"); } }); // The function that shows/hides the relevant section window.showSection = function(section) { homeSection.style.display = "none"; educationSection.style.display = "none"; positionsSection.style.display = "none"; accountSection.style.display = "none"; profileSection.style.display = "none"; tradeSection.style.display = "none"; watchlistSection.style.display = "none"; leaderboardSection.style.display = "none"; adminSection.style.display = "none"; adminTradesSection.style.display = "none"; if (section === "home") { homeSection.style.display = "flex"; if (window.toggleHomeAuthSection) { window.toggleHomeAuthSection(); } } else if (section === "education") { educationSection.style.display = "block"; } else if (section === "positions") { if (!window.isLoggedIn || !window.isLoggedIn()) { showSection("account"); return; } positionsSection.style.display = "block"; if (window.loadPositions) { window.loadPositions(); } } else if (section === "account") { if (window.isLoggedIn && window.isLoggedIn()) { profileSection.style.display = "block"; } else { accountSection.style.display = "block"; } } else if (section === "trade") { if (!window.isLoggedIn || !window.isLoggedIn()) { alert("Please log in first."); showSection("account"); return; } tradeSection.style.display = "block"; if (window.loadTradeHistory) { window.loadTradeHistory(); } } else if (section === "watchlist") { if (!window.isLoggedIn || !window.isLoggedIn()) { alert("Please log in first."); showSection("account"); return; } watchlistSection.style.display = "block"; if (window.loadWatchlist) { window.loadWatchlist(); } } else if (section === "admin") { if (window.isLoggedIn && window.isLoggedIn() && window.getCurrentUsername() === "Opulentissimus") { adminSection.style.display = "block"; if (window.loadAdminDashboard) { window.loadAdminDashboard(); } } else { alert("Access denied. Admins only."); showSection("home"); } } else if (section === "adminTrades") { if (window.isLoggedIn && window.isLoggedIn() && window.getCurrentUsername() === "Opulentissimus") { adminTradesSection.style.display = "block"; if (window.loadAdminTrades) { window.loadAdminTrades(); } } else { alert("Access denied. Admins only."); showSection("home"); } } else if (section === "leaderboard") { const leaderboardStatus = localStorage.getItem("pt_leaderboard_on") === "true"; if (leaderboardStatus) { leaderboardSection.style.display = "block"; if (window.loadLeaderboard) { window.loadLeaderboard(); } } else { alert("Leaderboard is currently disabled."); showSection("home"); } } }; // Navigation link events navHome.addEventListener("click", (e) => { e.preventDefault(); showSection("home"); }); navEducation.addEventListener("click", (e) => { e.preventDefault(); showSection("education"); }); navPositions.addEventListener("click", (e) => { e.preventDefault(); showSection("positions"); }); navAccount.addEventListener("click", (e) => { e.preventDefault(); showSection("account"); }); navTrade.addEventListener("click", (e) => { e.preventDefault(); showSection("trade"); }); navWatchlist.addEventListener("click", (e) => { e.preventDefault(); showSection("watchlist"); }); navLeaderboard.addEventListener("click", (e) => { e.preventDefault(); showSection("leaderboard"); }); navAdmin.addEventListener("click", (e) => { e.preventDefault(); showSection("admin"); }); navAdminTrades.addEventListener("click", (e) => { e.preventDefault(); showSection("adminTrades"); }); // Click on the logo to go home const logoClickArea = document.getElementById("logoClickArea"); logoClickArea.addEventListener("click", (e) => { e.preventDefault(); showSection("home"); });