Spaces:
Running
Running
Download script.js from ana1992/cottonflow-master: direct link, hf CLI and curl.
- Browser
- Download file 4.15 kB
-
https://huggingface.co/spaces/ana1992/cottonflow-master/resolve/main/script.js
- Command line
-
hf download hf://spaces/ana1992/cottonflow-master/script.js
-
curl -L -o script.js https://huggingface.co/spaces/ana1992/cottonflow-master/resolve/main/script.js
4.15 kB
| // Main application script | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize tooltips | |
| const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); | |
| const tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { | |
| return new bootstrap.Tooltip(tooltipTriggerEl); | |
| }); | |
| // Handle sidebar menu active state | |
| const currentPath = window.location.pathname.split('/').pop() || 'index.html'; | |
| const menuItems = document.querySelectorAll('.sidebar-menu a'); | |
| menuItems.forEach(item => { | |
| const href = item.getAttribute('href'); | |
| if (href === currentPath || (href === 'index.html' && currentPath === '')) { | |
| item.classList.add('bg-primary-50', 'text-primary-700'); | |
| item.classList.remove('text-gray-700'); | |
| } | |
| }); | |
| // Mobile menu toggle | |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); | |
| const mobileMenu = document.getElementById('mobile-menu'); | |
| if (mobileMenuButton && mobileMenu) { | |
| mobileMenuButton.addEventListener('click', function() { | |
| mobileMenu.classList.toggle('hidden'); | |
| }); | |
| } | |
| // Dark mode toggle | |
| const darkModeToggle = document.getElementById('dark-mode-toggle'); | |
| if (darkModeToggle) { | |
| darkModeToggle.addEventListener('click', function() { | |
| document.documentElement.classList.toggle('dark'); | |
| localStorage.setItem('darkMode', document.documentElement.classList.contains('dark')); | |
| }); | |
| } | |
| // Check for saved dark mode preference | |
| if (localStorage.getItem('darkMode') === 'true') { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| // Initialize charts (placeholder - would use Chart.js in a real implementation) | |
| initializePlaceholderCharts(); | |
| }); | |
| function initializePlaceholderCharts() { | |
| // This would be replaced with actual chart initialization code | |
| console.log('Initializing charts...'); | |
| // Example of what this might look like with Chart.js: | |
| /* | |
| const gradeCtx = document.getElementById('gradeChart').getContext('2d'); | |
| const gradeChart = new Chart(gradeCtx, { | |
| type: 'doughnut', | |
| data: { | |
| labels: ['Grade 32', 'Grade 33', 'Grade 41', 'Grade 42', 'Grade 43'], | |
| datasets: [{ | |
| data: [300, 250, 180, 150, 100], | |
| backgroundColor: [ | |
| '#3B82F6', | |
| '#10B981', | |
| '#F59E0B', | |
| '#8B5CF6', | |
| '#EF4444' | |
| ], | |
| borderWidth: 1 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| position: 'right', | |
| } | |
| } | |
| } | |
| }); | |
| */ | |
| } | |
| // Utility function for API calls | |
| async function fetchData(endpoint, options = {}) { | |
| try { | |
| const response = await fetch(`/api/${endpoint}`, { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| ...options.headers | |
| }, | |
| ...options | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| return await response.json(); | |
| } catch (error) { | |
| console.error('Error fetching data:', error); | |
| showNotification('Error loading data. Please try again.', 'error'); | |
| throw error; | |
| } | |
| } | |
| function showNotification(message, type = 'info') { | |
| const notification = document.createElement('div'); | |
| notification.className = `fixed bottom-4 right-4 p-4 rounded-md shadow-lg text-white ${ | |
| type === 'error' ? 'bg-red-500' : | |
| type === 'success' ? 'bg-green-500' : 'bg-blue-500' | |
| }`; | |
| notification.textContent = message; | |
| document.body.appendChild(notification); | |
| setTimeout(() => { | |
| notification.classList.add('opacity-0', 'transition-opacity', 'duration-300'); | |
| setTimeout(() => notification.remove(), 300); | |
| }, 3000); | |
| } |