Spaces:
Sleeping
Sleeping
| // Toast Notification System | |
| function showToast(message, type = 'success', duration = 3000) { | |
| const container = document.getElementById('toast-container'); | |
| // Create toast element | |
| const toast = document.createElement('div'); | |
| toast.className = `toast ${type}`; | |
| // Icon based on type | |
| const icons = { | |
| success: '✨', | |
| error: '❌', | |
| info: 'ℹ️', | |
| warning: '⚠️' | |
| }; | |
| const icon = icons[type] || icons.success; | |
| toast.innerHTML = ` | |
| <span class="toast-icon">${icon}</span> | |
| <span class="toast-message">${message}</span> | |
| <button class="toast-close">×</button> | |
| `; | |
| // Add to container | |
| container.appendChild(toast); | |
| // Close button handler | |
| const closeBtn = toast.querySelector('.toast-close'); | |
| closeBtn.addEventListener('click', () => { | |
| removeToast(toast); | |
| }); | |
| // Auto remove after duration | |
| setTimeout(() => { | |
| removeToast(toast); | |
| }, duration); | |
| } | |
| function removeToast(toast) { | |
| toast.classList.add('hiding'); | |
| setTimeout(() => { | |
| if (toast.parentElement) { | |
| toast.parentElement.removeChild(toast); | |
| } | |
| }, 300); | |
| } | |
| // Loading overlay functions | |
| function showLoading(text = 'Loading...') { | |
| const overlay = document.getElementById('loading-overlay'); | |
| const loadingText = document.getElementById('loading-text'); | |
| loadingText.textContent = text; | |
| overlay.classList.add('show'); | |
| } | |
| function hideLoading() { | |
| const overlay = document.getElementById('loading-overlay'); | |
| overlay.classList.remove('show'); | |
| } | |
| // Device detection | |
| function isMobileDevice() { | |
| return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); | |
| } | |
| function isAndroid() { | |
| return /Android/i.test(navigator.userAgent); | |
| } | |
| // Detect touch device | |
| function isTouchDevice() { | |
| return (('ontouchstart' in window) || | |
| (navigator.maxTouchPoints > 0) || | |
| (navigator.msMaxTouchPoints > 0)); | |
| } | |