|
|
| |
| document.addEventListener('DOMContentLoaded', function() { |
| |
| if (typeof feather !== 'undefined') { |
| feather.replace(); |
| } |
| |
| |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
| anchor.addEventListener('click', function (e) { |
| e.preventDefault(); |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ |
| behavior: 'smooth' |
| }); |
| }); |
| }); |
| |
| document.addEventListener('click', function(e) { |
| |
| if (e.target && e.target.closest) { |
| const mobileButton = e.target.closest('#mobile-menu-button'); |
| if (mobileButton) { |
| const header = mobileButton.closest('custom-header'); |
| if (header) { |
| |
| return; |
| } |
| } |
| } |
| }); |
|
|
| |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); |
| const mobileMenu = document.getElementById('mobile-menu'); |
|
|
| if (mobileMenuButton && mobileMenu) { |
| mobileMenuButton.addEventListener('click', () => { |
| mobileMenu.classList.toggle('hidden'); |
| }); |
| } |
| |
| const forms = document.querySelectorAll('form'); |
| forms.forEach(form => { |
| form.addEventListener('submit', function(e) { |
| e.preventDefault(); |
| |
| console.log('Form submitted'); |
| }); |
| }); |
| |
| |
| const themeToggle = document.getElementById('theme-toggle'); |
| if (themeToggle) { |
| themeToggle.addEventListener('click', function() { |
| document.documentElement.classList.toggle('dark'); |
| |
| const isDark = document.documentElement.classList.contains('dark'); |
| localStorage.setItem('theme', isDark ? 'dark' : 'light'); |
| }); |
| } |
| |
| |
| initializeCharts(); |
| |
| |
| setupEventListeners(); |
| }); |
|
|
| |
| function initializeCharts() { |
| |
| |
| console.log('Initializing charts...'); |
| } |
|
|
| |
| function setupEventListeners() { |
| |
| console.log('Setting up event listeners...'); |
| } |
|
|
| |
| function showNotification(message, type = 'info') { |
| const notification = document.createElement('div'); |
| notification.className = `notification bg-${type === 'error' ? 'red' : type === 'success' ? 'green' : 'blue'}-500 text-white`; |
| notification.textContent = message; |
| |
| document.body.appendChild(notification); |
| |
| |
| setTimeout(() => { |
| notification.remove(); |
| }, 3000); |
| } |
|
|
| |
| function formatCurrency(amount) { |
| return new Intl.NumberFormat('ar-YE', { |
| style: 'currency', |
| currency: 'YER' |
| }).format(amount); |
| } |
|
|
| |
| function formatDate(dateString) { |
| const options = { year: 'numeric', month: 'long', day: 'numeric' }; |
| return new Date(dateString).toLocaleDateString('ar-YE', options); |
| } |
|
|
| |
| async function fetchData(endpoint) { |
| try { |
| const response = await fetch(`/api/${endpoint}`); |
| 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'); |
| } |
| } |
|
|
| |
| function debounce(func, wait) { |
| let timeout; |
| return function executedFunction(...args) { |
| const later = () => { |
| clearTimeout(timeout); |
| func(...args); |
| }; |
| clearTimeout(timeout); |
| timeout = setTimeout(later, wait); |
| }; |
| } |
|
|
| |
| function exportToExcel(data, filename) { |
| |
| console.log('Exporting to Excel:', filename); |
| showNotification('تم تصدير البيانات إلى Excel', 'success'); |
| } |
|
|
| |
| function printPage() { |
| window.print(); |
| } |