Download script.js from seniorcoder/pixelledger-pro-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 8.35 kB
-
https://huggingface.co/spaces/seniorcoder/pixelledger-pro-dashboard/resolve/main/script.js
- Command line
-
hf download hf://spaces/seniorcoder/pixelledger-pro-dashboard/script.js
-
curl -L -o script.js https://huggingface.co/spaces/seniorcoder/pixelledger-pro-dashboard/resolve/main/script.js
8.35 kB
| // Enhanced UI Interactions | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize tooltips | |
| initTooltips(); | |
| // Initialize form validations | |
| initForms(); | |
| // Initialize modals | |
| initModals(); | |
| // Initialize datepickers | |
| initDatepickers(); | |
| }); | |
| function initTooltips() { | |
| const tooltipElements = document.querySelectorAll('[data-tooltip]'); | |
| tooltipElements.forEach(el => { | |
| const tooltipText = el.getAttribute('data-tooltip'); | |
| const tooltip = document.createElement('div'); | |
| tooltip.className = 'tooltip hidden absolute z-50 px-3 py-2 text-sm text-white bg-gray-800 rounded-md shadow-lg'; | |
| tooltip.textContent = tooltipText; | |
| document.body.appendChild(tooltip); | |
| el.addEventListener('mouseenter', () => { | |
| const rect = el.getBoundingClientRect(); | |
| tooltip.style.left = `${rect.left + rect.width/2 - tooltip.offsetWidth/2}px`; | |
| tooltip.style.top = `${rect.top - tooltip.offsetHeight - 5}px`; | |
| tooltip.classList.remove('hidden'); | |
| }); | |
| el.addEventListener('mouseleave', () => { | |
| tooltip.classList.add('hidden'); | |
| }); | |
| }); | |
| } | |
| function initForms() { | |
| const forms = document.querySelectorAll('form'); | |
| forms.forEach(form => { | |
| form.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const submitBtn = form.querySelector('[type="submit"]'); | |
| submitBtn.disabled = true; | |
| submitBtn.innerHTML = 'Processing...'; | |
| try { | |
| // Simulate form submission | |
| await new Promise(resolve => setTimeout(resolve, 1500)); | |
| showAlert('Form submitted successfully!', 'success'); | |
| } catch (error) { | |
| showAlert('Error submitting form. Please try again.', 'danger'); | |
| } finally { | |
| submitBtn.disabled = false; | |
| submitBtn.innerHTML = 'Submit'; | |
| } | |
| }); | |
| }); | |
| } | |
| function initModals() { | |
| const modalTriggers = document.querySelectorAll('[data-modal]'); | |
| modalTriggers.forEach(trigger => { | |
| const modalId = trigger.getAttribute('data-modal'); | |
| const modal = document.getElementById(modalId); | |
| if (!modal) return; | |
| trigger.addEventListener('click', () => { | |
| modal.classList.remove('hidden'); | |
| }); | |
| const closeButtons = modal.querySelectorAll('[data-dismiss]'); | |
| closeButtons.forEach(btn => { | |
| btn.addEventListener('click', () => { | |
| modal.classList.add('hidden'); | |
| }); | |
| }); | |
| }); | |
| } | |
| function initDatepickers() { | |
| const dateInputs = document.querySelectorAll('[type="date"]'); | |
| dateInputs.forEach(input => { | |
| if (!input.value) { | |
| const today = new Date().toISOString().split('T')[0]; | |
| input.value = today; | |
| } | |
| }); | |
| } | |
| function showAlert(message, type = 'info') { | |
| const alert = document.createElement('div'); | |
| alert.className = `alert alert-${type} fixed top-4 right-4 max-w-md z-50`; | |
| alert.innerHTML = ` | |
| <div class="flex items-start"> | |
| <div class="flex-shrink-0"> | |
| ${type === 'success' ? '<i data-feather="check-circle"></i>' : ''} | |
| ${type === 'danger' ? '<i data-feather="alert-circle"></i>' : ''} | |
| ${type === 'warning' ? '<i data-feather="alert-triangle"></i>' : ''} | |
| </div> | |
| <div class="ml-3"> | |
| <p class="text-sm">${message}</p> | |
| </div> | |
| <button onclick="this.parentElement.remove()" class="ml-auto -mx-1.5 -my-1.5 p-1.5 rounded-md hover:bg-opacity-30 focus:outline-none"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </div> | |
| `; | |
| document.body.appendChild(alert); | |
| feather.replace(); | |
| setTimeout(() => { | |
| alert.remove(); | |
| }, 5000); | |
| } | |
| // Toast notification | |
| function showToast(message, type = 'info') { | |
| const toast = document.createElement('div'); | |
| toast.className = `toast toast-${type} fixed bottom-4 right-4 max-w-xs z-50`; | |
| toast.innerHTML = ` | |
| <div class="flex items-center p-4 rounded-md shadow-lg bg-white border-l-4 ${type === 'success' ? 'border-green-500' : type === 'danger' ? 'border-red-500' : 'border-blue-500'}"> | |
| <div class="mr-3"> | |
| ${type === 'success' ? '<i data-feather="check-circle" class="text-green-500"></i>' : ''} | |
| ${type === 'danger' ? '<i data-feather="alert-circle" class="text-red-500"></i>' : ''} | |
| ${type === 'info' ? '<i data-feather="info" class="text-blue-500"></i>' : ''} | |
| </div> | |
| <div class="text-sm">${message}</div> | |
| </div> | |
| `; | |
| document.body.appendChild(toast); | |
| feather.replace(); | |
| setTimeout(() => { | |
| toast.remove(); | |
| }, 3000); | |
| } | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize any tooltips or popovers | |
| const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); | |
| tooltipTriggerList.map(function (tooltipTriggerEl) { | |
| return new bootstrap.Tooltip(tooltipTriggerEl); | |
| }); | |
| // Sample data for charts (would be replaced with real data) | |
| const revenueData = { | |
| labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | |
| datasets: [{ | |
| label: 'Revenue', | |
| data: [6500, 5900, 8000, 8100, 5600, 5500, 4000, 6200, 7800, 8200, 9100, 9500], | |
| backgroundColor: 'rgba(79, 70, 229, 0.1)', | |
| borderColor: 'rgba(79, 70, 229, 1)', | |
| borderWidth: 2, | |
| tension: 0.3, | |
| fill: true | |
| }] | |
| }; | |
| // Chart initialization would go here | |
| // const ctx = document.getElementById('revenueChart').getContext('2d'); | |
| // new Chart(ctx, { | |
| // type: 'line', | |
| // data: revenueData, | |
| // options: { | |
| // responsive: true, | |
| // plugins: { | |
| // legend: { | |
| // display: false | |
| // } | |
| // }, | |
| // scales: { | |
| // y: { | |
| // beginAtZero: true | |
| // } | |
| // } | |
| // } | |
| // }); | |
| }); | |
| // Toggle mobile menu | |
| function toggleMobileMenu() { | |
| const mobileMenu = document.getElementById('mobile-menu'); | |
| mobileMenu.classList.toggle('hidden'); | |
| } | |
| // Search functionality | |
| function handleSearch() { | |
| const searchInput = document.getElementById('search-input'); | |
| const searchValue = searchInput.value.toLowerCase(); | |
| // Implement search logic | |
| console.log('Searching for:', searchValue); | |
| } | |
| // Dark mode toggle | |
| function toggleDarkMode() { | |
| const html = document.documentElement; | |
| html.classList.toggle('dark'); | |
| localStorage.setItem('darkMode', html.classList.contains('dark')); | |
| } | |
| // Check for saved dark mode preference | |
| if (localStorage.getItem('darkMode') === 'true') { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| // Notification dropdown toggle | |
| function toggleNotifications() { | |
| const notificationDropdown = document.getElementById('notification-dropdown'); | |
| notificationDropdown.classList.toggle('hidden'); | |
| } | |
| // User dropdown toggle | |
| function toggleUserDropdown() { | |
| const userDropdown = document.getElementById('user-dropdown'); | |
| userDropdown.classList.toggle('hidden'); | |
| } | |
| // Close dropdowns when clicking outside | |
| document.addEventListener('click', function(event) { | |
| const notificationDropdown = document.getElementById('notification-dropdown'); | |
| const notificationButton = document.getElementById('notification-button'); | |
| const userDropdown = document.getElementById('user-dropdown'); | |
| const userButton = document.getElementById('user-button'); | |
| if (!notificationButton.contains(event.target) && !notificationDropdown.contains(event.target)) { | |
| notificationDropdown.classList.add('hidden'); | |
| } | |
| if (!userButton.contains(event.target) && !userDropdown.contains(event.target)) { | |
| userDropdown.classList.add('hidden'); | |
| } | |
| }); | |
| // Initialize datepicker | |
| function initDatepicker() { | |
| // Datepicker initialization would go here | |
| console.log('Initializing datepicker'); | |
| } |