|
545 | 545 |
|
546 | 546 | <!-- Navigation --> |
547 | 547 | <nav class="navbar"> |
548 | | - <a class="nav-link active" onclick="router('home')">Home</a> |
549 | | - <a class="nav-link" onclick="router('staff')">Staff</a> |
| 548 | + <a class="nav-link active" href="#home">Home</a> |
| 549 | + <a class="nav-link" href="#staff">Staff</a> |
550 | 550 | <a class="nav-link" href="https://discord.com/invite/userpfp-1129784704267210844" target="_blank">Discord</a> |
551 | 551 | </nav> |
552 | 552 |
|
@@ -596,31 +596,48 @@ <h3 id="modalTitle" style="margin-top:0; font-size: 1.5rem; margin-bottom: 0.5re |
596 | 596 | </div> |
597 | 597 |
|
598 | 598 | <script> |
599 | | - // --- Router Logic --- |
600 | | - function router(viewName) { |
| 599 | + // --- Redirection Logic --- |
| 600 | + // Instantly redirect if user is on /website/ path (legacy support) |
| 601 | + if (window.location.pathname.includes('/website')) { |
| 602 | + const newPath = window.location.pathname.replace('/website', ''); |
| 603 | + window.location.replace(newPath + window.location.hash); |
| 604 | + } |
| 605 | + |
| 606 | + // --- Routing Logic --- |
| 607 | + function handleRoute() { |
| 608 | + // Get hash or default to 'home' |
| 609 | + let viewName = window.location.hash.replace('#', '') || 'home'; |
| 610 | + |
| 611 | + // Valid routes check (optional, but good for safety) |
| 612 | + if (!['home', 'staff'].includes(viewName)) { |
| 613 | + viewName = 'home'; |
| 614 | + } |
| 615 | + |
601 | 616 | // Update Nav |
602 | 617 | document.querySelectorAll('.nav-link').forEach(link => { |
603 | 618 | link.classList.remove('active'); |
604 | | - if(link.innerText.toLowerCase() === viewName) link.classList.add('active'); |
| 619 | + if (link.getAttribute('href') === `#${viewName}`) link.classList.add('active'); |
605 | 620 | }); |
606 | 621 |
|
607 | | - // Update View |
| 622 | + // Update View visibility |
608 | 623 | document.querySelectorAll('.view-container').forEach(view => { |
609 | 624 | view.classList.remove('active'); |
610 | 625 | }); |
611 | | - document.getElementById(`${viewName}-view`).classList.add('active'); |
| 626 | + const activeView = document.getElementById(`${viewName}-view`); |
| 627 | + if (activeView) activeView.classList.add('active'); |
612 | 628 |
|
613 | | - // Handle background visibility |
| 629 | + // Handle background & Lazy Loading |
614 | 630 | const bgContainer = document.getElementById('pfp-bg-container'); |
615 | 631 | if (viewName === 'home') { |
616 | | - bgContainer.style.display = 'block'; |
617 | | - // Lazy load PFPs if not loaded yet |
| 632 | + if (bgContainer) bgContainer.style.display = 'block'; |
618 | 633 | if (!window.pfpsLoaded) loadPfps(); |
619 | 634 | } else { |
620 | | - bgContainer.style.display = 'none'; |
621 | | - // Lazy load Staff if not loaded yet |
| 635 | + if (bgContainer) bgContainer.style.display = 'none'; |
622 | 636 | if (!window.staffLoaded && viewName === 'staff') loadStaff(); |
623 | 637 | } |
| 638 | + |
| 639 | + // Scroll to top |
| 640 | + window.scrollTo(0, 0); |
624 | 641 | } |
625 | 642 |
|
626 | 643 | // --- Home Logic (PFP Columns & Mods) --- |
@@ -900,12 +917,17 @@ <h3 id="modalTitle" style="margin-top:0; font-size: 1.5rem; margin-bottom: 0.5re |
900 | 917 | // Initialize |
901 | 918 | document.addEventListener('DOMContentLoaded', () => { |
902 | 919 | initMods(); |
903 | | - router('home'); |
| 920 | + |
| 921 | + // Initial routing |
| 922 | + handleRoute(); |
904 | 923 |
|
905 | 924 | // Close modal when clicking outside |
906 | 925 | document.getElementById('infoModal').addEventListener('click', (e) => { |
907 | 926 | if(e.target === document.getElementById('infoModal')) closeModal(); |
908 | 927 | }); |
| 928 | + |
| 929 | + // Listen for hash changes |
| 930 | + window.addEventListener('hashchange', handleRoute); |
909 | 931 | }); |
910 | 932 |
|
911 | 933 | </script> |
|
0 commit comments