Spaces:
Running
Running
File size: 8,982 Bytes
6500e56 |
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 |
// Main JavaScript for NatureVerse Explorer
// Initialize all tabs functionality
function initializeTabs() {
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
tabButtons.forEach(button => {
button.addEventListener('click', () => {
const tabId = button.getAttribute('data-tab');
// Remove active class from all buttons and contents
tabButtons.forEach(btn => btn.classList.remove('active'));
tabContents.forEach(content => content.classList.add('hidden'));
// Add active class to clicked button and corresponding content
button.classList.add('active');
document.getElementById(`${tabId}-tab`).classList.remove('hidden');
});
});
}
// Initialize all interactive features
function initializeInteractiveFeatures() {
initializeImageGalleries();
initializeWeatherWidget();
initializeMapInteractions();
initializeVirtualTour();
initializeNewsFeed();
initializeEcoTips();
}
// Image Gallery functionality
function initializeImageGalleries() {
const galleries = document.querySelectorAll('.image-gallery');
galleries.forEach(gallery => {
const mainImage = gallery.querySelector('.main-image');
const thumbnails = gallery.querySelectorAll('.thumbnail');
thumbnails.forEach(thumbnail => {
thumbnail.addEventListener('click', () => {
const newSrc = thumbnail.getAttribute('data-full');
mainImage.src = newSrc;
// Update active thumbnail
thumbnails.forEach(thumb => thumb.classList.remove('active'));
thumbnail.classList.add('active');
});
});
});
}
// Weather Widget functionality
function initializeWeatherWidget() {
const weatherWidget = document.querySelector('.weather-widget');
if (!weatherWidget) return;
// Simulate weather data fetching
setTimeout(() => {
const weatherData = {
temperature: Math.floor(Math.random() * 30) + 10,
condition: ['Sunny', 'Cloudy', 'Rainy', 'Stormy'][Math.floor(Math.random() * 4)],
humidity: Math.floor(Math.random() * 40) + 50,
windSpeed: Math.floor(Math.random() * 20) + 5
};
updateWeatherDisplay(weatherData);
}, 1000);
}
function updateWeatherDisplay(data) {
const tempElement = document.querySelector('.weather-temp');
const conditionElement = document.querySelector('.weather-condition');
const humidityElement = document.querySelector('.weather-humidity');
const windElement = document.querySelector('.weather-wind');
if (tempElement) tempElement.textContent = `${data.temperature}°C`;
if (conditionElement) conditionElement.textContent = data.condition;
if (humidityElement) humidityElement.textContent = `${data.humidity}%`;
if (windElement) windElement.textContent = `${data.windSpeed} km/h`;
}
// Map Interactions
function initializeMapInteractions() {
const mapPoints = document.querySelectorAll('.map-point');
mapPoints.forEach(point => {
point.addEventListener('mouseenter', () => {
const tooltip = point.querySelector('.map-tooltip');
if (tooltip) {
tooltip.classList.remove('hidden');
tooltip.classList.add('block');
}
});
point.addEventListener('mouseleave', () => {
const tooltip = point.querySelector('.map-tooltip');
if (tooltip) {
tooltip.classList.remove('block');
tooltip.classList.add('hidden');
}
});
});
}
// Virtual Tour functionality
function initializeVirtualTour() {
const tourScenes = document.querySelectorAll('.tour-scene');
const sceneButtons = document.querySelectorAll('.scene-button');
sceneButtons.forEach((button, index) => {
button.addEventListener('click', () => {
tourScenes.forEach(scene => scene.classList.add('hidden'));
tourScenes[index].classList.remove('hidden');
});
});
}
// News Feed functionality
function initializeNewsFeed() {
const newsItems = document.querySelectorAll('.news-item');
const loadMoreBtn = document.querySelector('.load-more-news');
if (loadMoreBtn) {
loadMoreBtn.addEventListener('click', () => {
// Simulate loading more news
const loadingIndicator = document.createElement('div');
loadingIndicator.className = 'text-center py-4 pulse-animation';
loadingIndicator.textContent = 'Loading more nature news...';
loadMoreBtn.parentNode.replaceChild(loadingIndicator, loadMoreBtn);
setTimeout(() => {
// In a real app, this would fetch actual data
loadingIndicator.remove();
// Add more news items here
}, 2000);
});
}
}
// Eco Tips functionality
function initializeEcoTips() {
const tipCards = document.querySelectorAll('.eco-tip-card');
const randomTipBtn = document.querySelector('.random-tip-btn');
if (randomTipBtn) {
randomTipBtn.addEventListener('click', () => {
const randomIndex = Math.floor(Math.random() * tipCards.length);
tipCards.forEach((card, index) => {
card.classList.add('hidden');
if (index === randomIndex) {
card.classList.remove('hidden');
}
});
});
}
}
// Search functionality
function initializeSearch() {
const searchInput = document.querySelector('.search-input');
const searchResults = document.querySelector('.search-results');
if (searchInput && searchResults) {
searchInput.addEventListener('input', (e) => {
const query = e.target.value.toLowerCase();
if (query.length > 2) {
// Simulate search results
const results = [
'Amazon Rainforest Conservation',
'Great Barrier Reef Protection',
'African Wildlife Safaris',
'Arctic Circle Expeditions',
'Himalayan Mountain Treks'
].filter(item => item.toLowerCase().includes(query));
displaySearchResults(results);
} else {
searchResults.classList.add('hidden');
}
});
}
}
function displaySearchResults(results) {
const searchResults = document.querySelector('.search-results');
if (!searchResults) return;
searchResults.innerHTML = '';
if (results.length === 0) {
searchResults.innerHTML = '<div class="p-4 text-gray-500">No results found</div>';
} else {
results.forEach(result => {
const resultElement = document.createElement('div');
resultElement.className = 'p-3 hover:bg-emerald-50 cursor-pointer border-b border-gray-100';
resultElement.textContent = result;
searchResults.appendChild(resultElement);
});
}
searchResults.classList.remove('hidden');
}
// Dark mode toggle (if needed)
function toggleDarkMode() {
document.documentElement.classList.toggle('dark');
}
// Initialize everything when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
initializeTabs();
initializeInteractiveFeatures();
initializeSearch();
// Add smooth scrolling to all links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
});
// API integration for real data (placeholder functions)
async function fetchNatureData(endpoint) {
try {
const response = await fetch(`https://api.example.com/nature/${endpoint}`);
return await response.json();
} catch (error) {
console.error('Error fetching nature data:', error);
return null;
}
}
// Utility functions
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Export functions for use in components if needed
window.NatureVerse = {
initializeTabs,
initializeInteractiveFeatures,
fetchNatureData,
debounce
}; |