// Rasd - script.js let currentLanguage = localStorage.getItem('rasdLanguage') || 'ar'; document.addEventListener('DOMContentLoaded', () => { initializeLanguage(); setupEventListeners(); if (window.location.pathname.includes('dashboard.html')) { initializeDashboard(); } else if (window.location.pathname.includes('certification.html')) { initializeCertificationPage(); } else { initializeHomePage(); } }); function setupEventListeners() { document.querySelectorAll('#lang-toggle-btn').forEach(btn => { btn.addEventListener('click', toggleLanguage); }); } function initializeLanguage() { const htmlEl = document.getElementById('html'); if (currentLanguage === 'ar') { htmlEl.lang = 'ar'; htmlEl.dir = 'rtl'; htmlEl.classList.add('rtl'); htmlEl.classList.remove('ltr'); } else { htmlEl.lang = 'en'; htmlEl.dir = 'ltr'; htmlEl.classList.add('ltr'); htmlEl.classList.remove('rtl'); } updateLanguageUI(); updateTextContent(); } function toggleLanguage() { currentLanguage = currentLanguage === 'en' ? 'ar' : 'en'; localStorage.setItem('rasdLanguage', currentLanguage); initializeLanguage(); } function updateLanguageUI() { document.querySelectorAll('#lang-toggle-btn').forEach(btn => { btn.textContent = currentLanguage === 'en' ? 'ع' : 'En'; }); } function updateTextContent() { if (!translations) return; document.querySelectorAll('[data-en]').forEach(el => { const key = currentLanguage === 'en' ? el.dataset.en : el.dataset.ar; if (key) el.textContent = key; }); } // Home Page Logic function initializeHomePage() { document.querySelectorAll('.counter').forEach(counter => { const target = +counter.dataset.target; counter.textContent = '0'; const updateCount = () => { const current = +counter.textContent; const increment = target / 200; if (current < target) { counter.textContent = `${Math.ceil(current + increment)}`; setTimeout(updateCount, 10); } else { counter.textContent = target.toLocaleString(); } }; updateCount(); }); if (document.getElementById('footer-year')) { document.getElementById('footer-year').textContent = new Date().getFullYear(); } } // Dashboard Logic function initializeDashboard() { const sidebarLinks = document.querySelectorAll('.sidebar-link'); sidebarLinks.forEach(link => { link.addEventListener('click', e => { e.preventDefault(); sidebarLinks.forEach(l => l.classList.remove('active')); link.classList.add('active'); const dashboardId = link.dataset.dashboard; document.querySelectorAll('.dashboard-panel').forEach(p => p.classList.add('hidden')); document.getElementById(`dashboard-${dashboardId}`).classList.remove('hidden'); const titleEl = document.getElementById('dashboard-title'); titleEl.dataset.en = link.querySelector('[data-en]').dataset.en; titleEl.dataset.ar = link.querySelector('[data-ar]').dataset.ar; updateTextContent(); // Re-run to update the title }); }); // Initial content load const initialDashboard = document.querySelector('.sidebar-link.active'); const titleEl = document.getElementById('dashboard-title'); titleEl.dataset.en = initialDashboard.querySelector('[data-en]').dataset.en; titleEl.dataset.ar = initialDashboard.querySelector('[data-ar]').dataset.ar; updateTextContent(); } // Certification Page Logic function initializeCertificationPage() { const verifyBtn = document.getElementById('verify-btn'); const resultDiv = document.getElementById('verify-result'); const inputField = document.getElementById('verify-input'); verifyBtn.addEventListener('click', () => { resultDiv.classList.remove('hidden'); resultDiv.innerHTML = ``; setTimeout(() => { if (inputField.value.trim() !== "") { resultDiv.innerHTML = `

${currentLanguage === 'ar' ? 'أصلي وموثق' : 'Authentic & Verified'}

${currentLanguage === 'ar' ? 'تم التحقق من هذه الصورة وهي تابعة لوكالة الأنباء السعودية.' : 'This image has been verified as authentic SPA property.'}

`; } else { resultDiv.innerHTML = `

${currentLanguage === 'ar' ? 'الرجاء إدخال معرف صالح.' : 'Please enter a valid ID.'}

`; } }, 1500); }); if (document.getElementById('footer-year-cert')) { document.getElementById('footer-year-cert').textContent = new Date().getFullYear(); } }