File size: 13,313 Bytes
68bab6a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
// Main application script for Cooperative Constellation Network
// DOM Ready
document.addEventListener('DOMContentLoaded', function() {
// Initialize all components and functionality
initCooperatives();
initAnimations();
initEventListeners();
});
// Initialize cooperatives from API
async function initCooperatives() {
const container = document.getElementById('cooperatives-container');
if (!container) return;
try {
// Using a mock API endpoint - in production, replace with real API
const cooperatives = await fetchCooperatives();
displayCooperatives(container, cooperatives.slice(0, 6)); // Show first 6
} catch (error) {
console.error('Error loading cooperatives:', error);
displayFallbackCooperatives(container);
}
}
// Fetch cooperatives from API (mock version)
async function fetchCooperatives() {
// Mock data - in production, replace with real API call
return new Promise((resolve) => {
setTimeout(() => {
resolve([
{
id: 1,
name: "EduCollective North",
location: "Toronto, Canada",
focus: "Digital Literacy Education",
members: 45,
established: 2018,
description: "Promoting digital inclusion through community-based tech education programs.",
image: "http://static.photos/technology/640x360/101"
},
{
id: 2,
name: "Social Impact Educators Co-op",
location: "Berlin, Germany",
focus: "Sustainable Development",
members: 32,
established: 2015,
description: "Training educators in sustainable development practices for schools and communities.",
image: "http://static.photos/nature/640x360/102"
},
{
id: 3,
name: "Community Learning Hub",
location: "Nairobi, Kenya",
focus: "Early Childhood Education",
members: 28,
established: 2020,
description: "Providing early childhood education resources and teacher training in underserved communities.",
image: "http://static.photos/education/640x360/103"
},
{
id: 4,
name: "Indigenous Knowledge Cooperative",
location: "Auckland, New Zealand",
focus: "Cultural Preservation",
members: 36,
established: 2016,
description: "Integrating indigenous knowledge systems with modern educational frameworks.",
image: "http://static.photos/travel/640x360/104"
},
{
id: 5,
name: "Urban Youth Empowerment Co-op",
location: "São Paulo, Brazil",
focus: "Youth Development",
members: 52,
established: 2019,
description: "Empowering urban youth through vocational training and mentorship programs.",
image: "http://static.photos/cityscape/640x360/105"
},
{
id: 6,
name: "Environmental Education Network",
location: "Melbourne, Australia",
focus: "Environmental Education",
members: 41,
established: 2017,
description: "Connecting environmental educators and developing climate literacy curricula.",
image: "http://static.photos/green/640x360/106"
}
]);
}, 300);
});
}
// Display cooperatives in container
function displayCooperatives(container, cooperatives) {
container.innerHTML = '';
cooperatives.forEach((coop, index) => {
const card = document.createElement('div');
card.className = 'cooperative-card bg-white rounded-2xl overflow-hidden shadow-lg animate-slide-up';
card.style.animationDelay = `${index * 0.1}s`;
card.innerHTML = `
<div class="h-48 overflow-hidden">
<img src="${coop.image}" alt="${coop.name}" class="w-full h-full object-cover transform hover:scale-110 transition-transform duration-500">
</div>
<div class="p-6">
<div class="flex justify-between items-start mb-4">
<h3 class="text-xl font-bold text-gray-800">${coop.name}</h3>
<span class="bg-primary-100 text-primary-800 text-xs font-semibold px-3 py-1 rounded-full">
${coop.established}
</span>
</div>
<div class="flex items-center text-gray-600 mb-3">
<i data-feather="map-pin" class="w-4 h-4 mr-2"></i>
<span>${coop.location}</span>
</div>
<div class="mb-4">
<span class="inline-block bg-secondary-100 text-secondary-800 text-sm font-medium px-3 py-1 rounded-full mb-2">
${coop.focus}
</span>
</div>
<p class="text-gray-600 mb-4">${coop.description}</p>
<div class="flex items-center justify-between">
<div class="flex items-center">
<i data-feather="users" class="w-4 h-4 mr-2 text-primary-600"></i>
<span class="text-sm font-medium">${coop.members} Members</span>
</div>
<a href="cooperative.html?id=${coop.id}" class="text-primary-600 hover:text-primary-700 font-medium text-sm inline-flex items-center">
Learn More
<i data-feather="arrow-right" class="ml-1 w-4 h-4"></i>
</a>
</div>
</div>
`;
container.appendChild(card);
});
feather.replace();
}
// Display fallback cooperatives if API fails
function displayFallbackCooperatives(container) {
container.innerHTML = `
<div class="col-span-full text-center py-12">
<div class="bg-gray-100 rounded-full w-20 h-20 flex items-center justify-center mx-auto mb-6">
<i data-feather="users" class="w-10 h-10 text-gray-400"></i>
</div>
<h3 class="text-xl font-semibold text-gray-700 mb-2">Network Loading</h3>
<p class="text-gray-600 mb-4">Our cooperative network is currently connecting...</p>
<button onclick="initCooperatives()" class="bg-primary-500 hover:bg-primary-600 text-white font-medium py-2 px-6 rounded-lg transition-colors duration-300">
Retry Connection
</button>
</div>
`;
feather.replace();
}
// Create network visualization
function createNetworkVisualization() {
const container = document.querySelector('.network-visualization');
if (!container) return;
// Clear container
container.innerHTML = '';
// Create nodes
const nodeCount = 15;
const nodes = [];
for (let i = 0; i < nodeCount; i++) {
const angle = (i / nodeCount) * Math.PI * 2;
const radius = Math.random() * 0.7 + 0.1;
const x = 50 + Math.cos(angle) * radius * 50;
const y = 50 + Math.sin(angle) * radius * 50;
const node = document.createElement('div');
node.className = 'network-node';
node.style.left = `${x}%`;
node.style.top = `${y}%`;
node.style.animationDelay = `${i * 0.2}s`;
node.style.width = `${Math.random() * 8 + 8}px`;
node.style.height = node.style.width;
node.addEventListener('click', () => {
showNodeInfo(i);
});
container.appendChild(node);
nodes.push({ x, y, element: node });
}
// Create connections between nodes
for (let i = 0; i < nodes.length; i++) {
for (let j = i + 1; j < nodes.length; j++) {
// Only connect some nodes
if (Math.random() > 0.7) {
const node1 = nodes[i];
const node2 = nodes[j];
const dx = node2.x - node1.x;
const dy = node2.y - node1.y;
const distance = Math.sqrt(dx * dx + dy * dy);
// Only connect if not too far apart
if (distance < 40) {
const connection = document.createElement('div');
connection.className = 'network-connection';
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
connection.style.width = `${distance}%`;
connection.style.left = `${node1.x}%`;
connection.style.top = `${node1.y}%`;
connection.style.transform = `rotate(${angle}deg)`;
connection.style.opacity = 0.3 - (distance / 100);
container.insertBefore(connection, node1.element);
}
}
}
}
// Add central hub
const hub = document.createElement('div');
hub.className = 'network-node animate-pulse-glow';
hub.style.left = '50%';
hub.style.top = '50%';
hub.style.width = '24px';
hub.style.height = '24px';
hub.style.background = 'linear-gradient(135deg, #3B82F6, #10B981)';
hub.style.zIndex = '10';
hub.addEventListener('click', () => {
showNodeInfo('hub');
});
container.appendChild(hub);
}
// Show information for a network node
function showNodeInfo(nodeId) {
const info = [
"Community Learning Initiative",
"Educational Resource Hub",
"Social Impact Project",
"Teacher Training Center",
"Youth Mentorship Program",
"Digital Education Platform",
"Sustainability Project",
"Cultural Exchange Network",
"Vocational Training Cooperative",
"Early Childhood Program",
"Environmental Education Center",
"Technology Access Initiative",
"Rural Education Network",
"Urban Development Program",
"Health Education Cooperative",
"Network Central Hub"
];
const nodeName = info[nodeId] || "Cooperative Node";
alert(`🌐 ${nodeName}\n\nThis node represents one of the many interconnected cooperatives in our network, each contributing unique expertise and resources to our collective mission.`);
}
// Initialize animations
function initAnimations() {
// Add scroll reveal animations
const revealElements = document.querySelectorAll('.reveal-on-scroll');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
revealElements.forEach(element => {
observer.observe(element);
});
// Add hover animation to cards
const cards = document.querySelectorAll('.cooperative-card, .bg-white.shadow-lg');
cards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-8px)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0)';
});
});
}
// Initialize event listeners
function initEventListeners() {
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
// Network visualization refresh
const refreshBtn = document.getElementById('refresh-network');
if (refreshBtn) {
refreshBtn.addEventListener('click', createNetworkVisualization);
}
}
// Utility function to format numbers
function formatNumber(num) {
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
} else if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num.toString();
}
// Global function to load cooperatives (for retry button)
window.loadCooperatives = initCooperatives;
// Export for module usage if needed
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
initCooperatives,
createNetworkVisualization,
initAnimations
};
} |