/** * UX Features Implementation * 10 تحسينات لتجربة المستخدم */ (function() { 'use strict'; // =================================== // 1. SIDEBAR SEARCH // =================================== const sidebarSearch = { input: null, results: null, clearBtn: null, allLinks: [], init() { this.input = document.getElementById('sidebarSearchInput'); this.results = document.getElementById('searchResults'); this.clearBtn = document.getElementById('searchClear'); if (!this.input) return; // جمع كل الروابط this.collectLinks(); // Event listeners this.input.addEventListener('input', (e) => this.handleSearch(e.target.value)); this.input.addEventListener('focus', () => { if (this.input.value) this.results.style.display = 'block'; }); this.clearBtn?.addEventListener('click', () => this.clearSearch()); // إغلاق النتائج عند الضغط خارجها document.addEventListener('click', (e) => { if (!e.target.closest('.sidebar-search')) { this.results.style.display = 'none'; } }); }, collectLinks() { const items = document.querySelectorAll('.sidebar-item, .sidebar-subitem'); items.forEach(item => { const text = item.querySelector('span')?.textContent.trim(); const href = item.getAttribute('href'); const icon = item.querySelector('i')?.className || ''; if (text && href) { this.allLinks.push({ text, href, icon, element: item }); } }); }, handleSearch(query) { query = query.trim().toLowerCase(); if (!query) { this.results.style.display = 'none'; this.clearBtn.style.display = 'none'; return; } this.clearBtn.style.display = 'block'; const filtered = this.allLinks.filter(link => link.text.toLowerCase().includes(query) ); this.displayResults(filtered, query); }, displayResults(results, query) { if (results.length === 0) { this.results.innerHTML = `
لا توجد نتائج لـ "${query}"
لا توجد إشعارات