Spaces:
Running
Running
Download script.js from RodzDXebec/condocomm-manager: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/spaces/RodzDXebec/condocomm-manager/resolve/main/script.js
- Command line
-
hf download hf://spaces/RodzDXebec/condocomm-manager/script.js
-
curl -L -o script.js https://huggingface.co/spaces/RodzDXebec/condocomm-manager/resolve/main/script.js
2.79 kB
| // Global functions and event listeners | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize tooltips | |
| const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); | |
| tooltipTriggerList.map(function (tooltipTriggerEl) { | |
| return new bootstrap.Tooltip(tooltipTriggerEl); | |
| }); | |
| // Handle 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'); | |
| }); | |
| } | |
| // Handle 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 user preference | |
| if (localStorage.getItem('darkMode') === 'true') { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| } | |
| }); | |
| // API functions | |
| async function fetchRecentPackages() { | |
| try { | |
| const response = await fetch('/api/packages/recent'); | |
| if (!response.ok) throw new Error('Network response was not ok'); | |
| return await response.json(); | |
| } catch (error) { | |
| console.error('Error fetching packages:', error); | |
| return []; | |
| } | |
| } | |
| async function registerNewPackage(packageData) { | |
| try { | |
| const response = await fetch('/api/packages', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(packageData), | |
| }); | |
| return await response.json(); | |
| } catch (error) { | |
| console.error('Error registering package:', error); | |
| return { success: false, error: error.message }; | |
| } | |
| } | |
| // Notification functions | |
| function showNotification(message, type = 'info') { | |
| const notification = document.createElement('div'); | |
| notification.className = `fixed bottom-4 right-4 px-4 py-2 rounded-md shadow-lg text-white bg-${type}-500 z-50`; | |
| notification.textContent = message; | |
| document.body.appendChild(notification); | |
| setTimeout(() => { | |
| notification.classList.add('opacity-0', 'transition-opacity', 'duration-300'); | |
| setTimeout(() => notification.remove(), 300); | |
| }, 3000); | |
| } | |
| // Utility functions | |
| function formatDate(dateString) { | |
| const options = { year: 'numeric', month: 'short', day: 'numeric' }; | |
| return new Date(dateString).toLocaleDateString('pt-BR', options); | |
| } |