AhmedMostafaAttia commited on
Commit
4c2054c
·
verified ·
1 Parent(s): d8bd1e5

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +142 -0
script.js ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Rasd - script.js
2
+ let currentLanguage = localStorage.getItem('rasdLanguage') || 'ar';
3
+
4
+ document.addEventListener('DOMContentLoaded', () => {
5
+ initializeLanguage();
6
+ setupEventListeners();
7
+
8
+ if (window.location.pathname.includes('dashboard.html')) {
9
+ initializeDashboard();
10
+ } else if (window.location.pathname.includes('certification.html')) {
11
+ initializeCertificationPage();
12
+ } else {
13
+ initializeHomePage();
14
+ }
15
+ });
16
+
17
+ function setupEventListeners() {
18
+ document.querySelectorAll('#lang-toggle-btn').forEach(btn => {
19
+ btn.addEventListener('click', toggleLanguage);
20
+ });
21
+ }
22
+
23
+ function initializeLanguage() {
24
+ const htmlEl = document.getElementById('html');
25
+ if (currentLanguage === 'ar') {
26
+ htmlEl.lang = 'ar';
27
+ htmlEl.dir = 'rtl';
28
+ htmlEl.classList.add('rtl');
29
+ htmlEl.classList.remove('ltr');
30
+ } else {
31
+ htmlEl.lang = 'en';
32
+ htmlEl.dir = 'ltr';
33
+ htmlEl.classList.add('ltr');
34
+ htmlEl.classList.remove('rtl');
35
+ }
36
+ updateLanguageUI();
37
+ updateTextContent();
38
+ }
39
+
40
+ function toggleLanguage() {
41
+ currentLanguage = currentLanguage === 'en' ? 'ar' : 'en';
42
+ localStorage.setItem('rasdLanguage', currentLanguage);
43
+ initializeLanguage();
44
+ }
45
+
46
+ function updateLanguageUI() {
47
+ document.querySelectorAll('#lang-toggle-btn').forEach(btn => {
48
+ btn.textContent = currentLanguage === 'en' ? 'ع' : 'En';
49
+ });
50
+ }
51
+
52
+ function updateTextContent() {
53
+ if (!translations) return;
54
+ document.querySelectorAll('[data-en]').forEach(el => {
55
+ const key = currentLanguage === 'en' ? el.dataset.en : el.dataset.ar;
56
+ if (key) el.textContent = key;
57
+ });
58
+ }
59
+
60
+ // Home Page Logic
61
+ function initializeHomePage() {
62
+ document.querySelectorAll('.counter').forEach(counter => {
63
+ const target = +counter.dataset.target;
64
+ counter.textContent = '0';
65
+ const updateCount = () => {
66
+ const current = +counter.textContent;
67
+ const increment = target / 200;
68
+ if (current < target) {
69
+ counter.textContent = `${Math.ceil(current + increment)}`;
70
+ setTimeout(updateCount, 10);
71
+ } else {
72
+ counter.textContent = target.toLocaleString();
73
+ }
74
+ };
75
+ updateCount();
76
+ });
77
+ if (document.getElementById('footer-year')) {
78
+ document.getElementById('footer-year').textContent = new Date().getFullYear();
79
+ }
80
+ }
81
+
82
+ // Dashboard Logic
83
+ function initializeDashboard() {
84
+ const sidebarLinks = document.querySelectorAll('.sidebar-link');
85
+ sidebarLinks.forEach(link => {
86
+ link.addEventListener('click', e => {
87
+ e.preventDefault();
88
+ sidebarLinks.forEach(l => l.classList.remove('active'));
89
+ link.classList.add('active');
90
+
91
+ const dashboardId = link.dataset.dashboard;
92
+ document.querySelectorAll('.dashboard-panel').forEach(p => p.classList.add('hidden'));
93
+ document.getElementById(`dashboard-${dashboardId}`).classList.remove('hidden');
94
+
95
+ const titleEl = document.getElementById('dashboard-title');
96
+ titleEl.dataset.en = link.querySelector('[data-en]').dataset.en;
97
+ titleEl.dataset.ar = link.querySelector('[data-ar]').dataset.ar;
98
+ updateTextContent(); // Re-run to update the title
99
+ });
100
+ });
101
+ // Initial content load
102
+ const initialDashboard = document.querySelector('.sidebar-link.active');
103
+ const titleEl = document.getElementById('dashboard-title');
104
+ titleEl.dataset.en = initialDashboard.querySelector('[data-en]').dataset.en;
105
+ titleEl.dataset.ar = initialDashboard.querySelector('[data-ar]').dataset.ar;
106
+ updateTextContent();
107
+ }
108
+
109
+ // Certification Page Logic
110
+ function initializeCertificationPage() {
111
+ const verifyBtn = document.getElementById('verify-btn');
112
+ const resultDiv = document.getElementById('verify-result');
113
+ const inputField = document.getElementById('verify-input');
114
+
115
+ verifyBtn.addEventListener('click', () => {
116
+ resultDiv.classList.remove('hidden');
117
+ resultDiv.innerHTML = `<i class="fas fa-spinner fa-spin text-2xl text-spa-green"></i>`;
118
+
119
+ setTimeout(() => {
120
+ if (inputField.value.trim() !== "") {
121
+ resultDiv.innerHTML = `
122
+ <div class="p-4 bg-green-100 border-l-4 border-green-500 text-green-700">
123
+ <div class="flex items-center">
124
+ <i class="fas fa-check-circle text-2xl mr-4"></i>
125
+ <div>
126
+ <p class="font-bold">${currentLanguage === 'ar' ? 'أصلي وموثق' : 'Authentic & Verified'}</p>
127
+ <p class="text-sm">${currentLanguage === 'ar' ? 'تم التحقق من هذه الصورة وهي تابعة لوكالة الأنباء السعودية.' : 'This image has been verified as authentic SPA property.'}</p>
128
+ </div>
129
+ </div>
130
+ </div>`;
131
+ } else {
132
+ resultDiv.innerHTML = `
133
+ <div class="p-4 bg-red-100 border-l-4 border-red-500 text-red-700">
134
+ <p>${currentLanguage === 'ar' ? 'الرجاء إدخال معرف صالح.' : 'Please enter a valid ID.'}</p>
135
+ </div>`;
136
+ }
137
+ }, 1500);
138
+ });
139
+ if (document.getElementById('footer-year-cert')) {
140
+ document.getElementById('footer-year-cert').textContent = new Date().getFullYear();
141
+ }
142
+ }