Upload main.js
Browse files- js/main.js +50 -19
js/main.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
// main.js
|
| 2 |
-
import { createHomeAreaCard } from './cards/HomeAreaCard.js';
|
| 3 |
-
import { createArtifactSummaryCard, createArtifactCarousel } from './cards/ArtifactSummaryCard.js';
|
| 4 |
import { teamMembers, teamTagData } from './data/team.js';
|
| 5 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
// Team member component
|
| 8 |
export function createTeamMember(name, role, hfUsername, tags) {
|
|
@@ -47,19 +50,7 @@ export function createTeamMember(name, role, hfUsername, tags) {
|
|
| 47 |
}
|
| 48 |
|
| 49 |
// Make router's scrollToSection globally available for onclick handlers
|
| 50 |
-
window.scrollToSection =
|
| 51 |
-
const element = document.getElementById(sectionId);
|
| 52 |
-
if (element) {
|
| 53 |
-
const elementRect = element.getBoundingClientRect();
|
| 54 |
-
const absoluteElementTop = elementRect.top + window.pageYOffset;
|
| 55 |
-
const offset = 120; // Account for fixed header + some padding
|
| 56 |
-
|
| 57 |
-
window.scrollTo({
|
| 58 |
-
top: absoluteElementTop - offset,
|
| 59 |
-
behavior: 'smooth'
|
| 60 |
-
});
|
| 61 |
-
}
|
| 62 |
-
};
|
| 63 |
|
| 64 |
// Scroll to top functionality
|
| 65 |
function scrollToTop() {
|
|
@@ -113,12 +104,36 @@ function initializeScrollToTop() {
|
|
| 113 |
toggleScrollToTopButton();
|
| 114 |
}
|
| 115 |
|
|
|
|
| 116 |
// Main initialization
|
| 117 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
// Initialize scroll to top functionality
|
| 121 |
initializeScrollToTop();
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
// The router will handle page-specific component initialization
|
| 124 |
// No need to call initializeTeamMembers, initializeHomeAreaCards, etc. here
|
|
@@ -134,6 +149,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 134 |
const sidebarToggle = document.getElementById('sidebar-toggle');
|
| 135 |
const leftSidebar = document.getElementById('left-sidebar');
|
| 136 |
const mainContentEl = document.getElementById('main-content');
|
|
|
|
| 137 |
|
| 138 |
function toggleLeftSidebar() {
|
| 139 |
const isOpen = !leftSidebar.classList.contains('-translate-x-full');
|
|
@@ -142,10 +158,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 142 |
// Close sidebar
|
| 143 |
leftSidebar.classList.add('-translate-x-full');
|
| 144 |
mainContentEl.style.marginLeft = '0';
|
|
|
|
|
|
|
| 145 |
} else {
|
| 146 |
-
// Open sidebar
|
|
|
|
|
|
|
| 147 |
leftSidebar.classList.remove('-translate-x-full');
|
| 148 |
mainContentEl.style.marginLeft = '256px';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
}
|
| 151 |
|
|
@@ -154,9 +182,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 154 |
function toggleSearch() {
|
| 155 |
const isOpen = !searchSidebar.classList.contains('translate-x-full');
|
| 156 |
const leftSidebarOpen = !leftSidebar.classList.contains('-translate-x-full');
|
|
|
|
| 157 |
|
| 158 |
if (isOpen) {
|
| 159 |
searchSidebar.classList.add('translate-x-full');
|
|
|
|
| 160 |
if (leftSidebarOpen) {
|
| 161 |
mainContent.style.marginLeft = '256px';
|
| 162 |
mainContent.classList.remove('mr-80');
|
|
@@ -167,6 +197,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 167 |
overlay.classList.add('hidden');
|
| 168 |
} else {
|
| 169 |
searchSidebar.classList.remove('translate-x-full');
|
|
|
|
| 170 |
if (leftSidebarOpen) {
|
| 171 |
mainContent.style.marginLeft = '256px';
|
| 172 |
mainContent.classList.add('mr-80');
|
|
|
|
| 1 |
// main.js
|
|
|
|
|
|
|
| 2 |
import { teamMembers, teamTagData } from './data/team.js';
|
| 3 |
+
import { initializeSearchUI } from './utils/search.js';
|
| 4 |
+
import { overallBackgroundImage } from './data/areas.js';
|
| 5 |
+
import { scrollToSection } from './utils/dom.js';
|
| 6 |
+
import { updatePageBackgroundPosition } from './utils/router.js'; // Import the new function
|
| 7 |
+
|
| 8 |
+
let allArtifactsData; // Declare a variable to hold the fetched artifacts
|
| 9 |
|
| 10 |
// Team member component
|
| 11 |
export function createTeamMember(name, role, hfUsername, tags) {
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
// Make router's scrollToSection globally available for onclick handlers
|
| 53 |
+
window.scrollToSection = scrollToSection;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
// Scroll to top functionality
|
| 56 |
function scrollToTop() {
|
|
|
|
| 104 |
toggleScrollToTopButton();
|
| 105 |
}
|
| 106 |
|
| 107 |
+
|
| 108 |
// Main initialization
|
| 109 |
+
document.addEventListener('DOMContentLoaded', async function() { // Mark as async
|
| 110 |
+
const backgroundImg = document.querySelector('#overall-background img');
|
| 111 |
+
if (backgroundImg) {
|
| 112 |
+
backgroundImg.src = `images/${overallBackgroundImage.image}`;
|
| 113 |
+
backgroundImg.alt = overallBackgroundImage.altText;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Fetch artifacts once
|
| 117 |
+
try {
|
| 118 |
+
const response = await fetch('/data/artifacts.json');
|
| 119 |
+
if (!response.ok) {
|
| 120 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 121 |
+
}
|
| 122 |
+
allArtifactsData = await response.json();
|
| 123 |
+
console.log('Artifacts loaded once in main.js:', allArtifactsData.length, 'items');
|
| 124 |
+
} catch (error) {
|
| 125 |
+
console.error('Failed to load artifacts in main.js:', error);
|
| 126 |
+
allArtifactsData = [];
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Make allArtifactsData globally available for other modules
|
| 130 |
+
window.allArtifacts = allArtifactsData;
|
| 131 |
|
| 132 |
// Initialize scroll to top functionality
|
| 133 |
initializeScrollToTop();
|
| 134 |
+
|
| 135 |
+
// Initialize search UI, passing the loaded artifacts
|
| 136 |
+
initializeSearchUI(allArtifactsData);
|
| 137 |
|
| 138 |
// The router will handle page-specific component initialization
|
| 139 |
// No need to call initializeTeamMembers, initializeHomeAreaCards, etc. here
|
|
|
|
| 149 |
const sidebarToggle = document.getElementById('sidebar-toggle');
|
| 150 |
const leftSidebar = document.getElementById('left-sidebar');
|
| 151 |
const mainContentEl = document.getElementById('main-content');
|
| 152 |
+
const leftSidebarBg = document.getElementById('left-sidebar-background'); // Get the background element
|
| 153 |
|
| 154 |
function toggleLeftSidebar() {
|
| 155 |
const isOpen = !leftSidebar.classList.contains('-translate-x-full');
|
|
|
|
| 158 |
// Close sidebar
|
| 159 |
leftSidebar.classList.add('-translate-x-full');
|
| 160 |
mainContentEl.style.marginLeft = '0';
|
| 161 |
+
leftSidebarBg.classList.add('hidden'); // Hide the left sidebar background
|
| 162 |
+
updatePageBackgroundPosition(); // Update page background position immediately on close
|
| 163 |
} else {
|
| 164 |
+
// Open sidebar - initially hide its background
|
| 165 |
+
leftSidebarBg.classList.add('hidden'); // Ensure it's hidden before animation starts
|
| 166 |
+
|
| 167 |
leftSidebar.classList.remove('-translate-x-full');
|
| 168 |
mainContentEl.style.marginLeft = '256px';
|
| 169 |
+
|
| 170 |
+
// Wait for transition to end before updating background position AND showing sidebar background
|
| 171 |
+
const handleTransitionEnd = () => {
|
| 172 |
+
leftSidebarBg.classList.remove('hidden'); // Now show the left sidebar background
|
| 173 |
+
updatePageBackgroundPosition();
|
| 174 |
+
leftSidebar.removeEventListener('transitionend', handleTransitionEnd);
|
| 175 |
+
};
|
| 176 |
+
leftSidebar.addEventListener('transitionend', handleTransitionEnd);
|
| 177 |
}
|
| 178 |
}
|
| 179 |
|
|
|
|
| 182 |
function toggleSearch() {
|
| 183 |
const isOpen = !searchSidebar.classList.contains('translate-x-full');
|
| 184 |
const leftSidebarOpen = !leftSidebar.classList.contains('-translate-x-full');
|
| 185 |
+
const rightSidebarBg = document.getElementById('right-sidebar-background');
|
| 186 |
|
| 187 |
if (isOpen) {
|
| 188 |
searchSidebar.classList.add('translate-x-full');
|
| 189 |
+
rightSidebarBg.classList.add('hidden');
|
| 190 |
if (leftSidebarOpen) {
|
| 191 |
mainContent.style.marginLeft = '256px';
|
| 192 |
mainContent.classList.remove('mr-80');
|
|
|
|
| 197 |
overlay.classList.add('hidden');
|
| 198 |
} else {
|
| 199 |
searchSidebar.classList.remove('translate-x-full');
|
| 200 |
+
rightSidebarBg.classList.remove('hidden');
|
| 201 |
if (leftSidebarOpen) {
|
| 202 |
mainContent.style.marginLeft = '256px';
|
| 203 |
mainContent.classList.add('mr-80');
|