Spaces:
Running
Running
File size: 5,571 Bytes
4c2054c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
// 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 = `<i class="fas fa-spinner fa-spin text-2xl text-spa-green"></i>`;
setTimeout(() => {
if (inputField.value.trim() !== "") {
resultDiv.innerHTML = `
<div class="p-4 bg-green-100 border-l-4 border-green-500 text-green-700">
<div class="flex items-center">
<i class="fas fa-check-circle text-2xl mr-4"></i>
<div>
<p class="font-bold">${currentLanguage === 'ar' ? 'أصلي وموثق' : 'Authentic & Verified'}</p>
<p class="text-sm">${currentLanguage === 'ar' ? 'تم التحقق من هذه الصورة وهي تابعة لوكالة الأنباء السعودية.' : 'This image has been verified as authentic SPA property.'}</p>
</div>
</div>
</div>`;
} else {
resultDiv.innerHTML = `
<div class="p-4 bg-red-100 border-l-4 border-red-500 text-red-700">
<p>${currentLanguage === 'ar' ? 'الرجاء إدخال معرف صالح.' : 'Please enter a valid ID.'}</p>
</div>`;
}
}, 1500);
});
if (document.getElementById('footer-year-cert')) {
document.getElementById('footer-year-cert').textContent = new Date().getFullYear();
}
} |