AhmedMostafaAttia commited on
Commit
9da818d
·
verified ·
1 Parent(s): 523377a

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +215 -0
script.js ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // NABAD - script.js
2
+
3
+ // --- GLOBAL STATE ---
4
+ let currentLanguage = localStorage.getItem('nabadLanguage') || 'ar';
5
+
6
+ // --- INITIALIZATION ---
7
+ document.addEventListener('DOMContentLoaded', () => {
8
+ console.log("🚀 NABAD Platform Initialized");
9
+ initializeLanguage();
10
+ setupEventListeners();
11
+
12
+ if (document.getElementById('year')) {
13
+ document.getElementById('year').textContent = new Date().getFullYear();
14
+ }
15
+
16
+ // Page specific initializations
17
+ if (window.location.pathname.includes('dashboard.html')) {
18
+ initDashboards();
19
+ } else if (window.location.pathname.includes('video.html')) {
20
+ initVideoLibrary();
21
+ } else {
22
+ initHomePage();
23
+ }
24
+ });
25
+
26
+ // --- EVENT LISTENERS SETUP ---
27
+ function setupEventListeners() {
28
+ // Language toggles
29
+ document.querySelectorAll('button[onclick="toggleLanguage()"]').forEach(btn => {
30
+ btn.addEventListener('click', toggleLanguage);
31
+ });
32
+
33
+ // Smooth scrolling for homepage links
34
+ if (!window.location.pathname.includes('dashboard.html') && !window.location.pathname.includes('video.html')) {
35
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
36
+ anchor.addEventListener('click', function (e) {
37
+ e.preventDefault();
38
+ document.querySelector(this.getAttribute('href')).scrollIntoView({
39
+ behavior: 'smooth'
40
+ });
41
+ });
42
+ });
43
+ }
44
+ }
45
+
46
+ // --- LANGUAGE MANAGEMENT ---
47
+ function initializeLanguage() {
48
+ const htmlEl = document.getElementById('html');
49
+ if (currentLanguage === 'ar') {
50
+ htmlEl.setAttribute('lang', 'ar');
51
+ htmlEl.setAttribute('dir', 'rtl');
52
+ htmlEl.classList.add('rtl');
53
+ htmlEl.classList.remove('ltr');
54
+ } else {
55
+ htmlEl.setAttribute('lang', 'en');
56
+ htmlEl.setAttribute('dir', 'ltr');
57
+ htmlEl.classList.add('ltr');
58
+ htmlEl.classList.remove('rtl');
59
+ }
60
+ updateLanguageUI();
61
+ updateTextContent();
62
+ }
63
+
64
+ function toggleLanguage() {
65
+ currentLanguage = currentLanguage === 'en' ? 'ar' : 'en';
66
+ localStorage.setItem('nabadLanguage', currentLanguage);
67
+ initializeLanguage();
68
+ }
69
+
70
+ function updateLanguageUI() {
71
+ if (document.getElementById('lang-toggle')) {
72
+ document.getElementById('lang-toggle').textContent = currentLanguage === 'en' ? 'ع' : 'En';
73
+ }
74
+ if (document.getElementById('lang-toggle-dash')) {
75
+ document.getElementById('lang-toggle-dash').textContent = currentLanguage === 'en' ? 'ع' : 'En';
76
+ }
77
+
78
+ // Handle placeholder text for search input
79
+ const searchInput = document.getElementById('video-search');
80
+ if (searchInput) {
81
+ const placeholderText = currentLanguage === 'ar' ? 'ابحث في الفيديوهات...' : 'Search videos...';
82
+ searchInput.setAttribute('placeholder', placeholderText);
83
+ }
84
+ }
85
+
86
+ function updateTextContent() {
87
+ if (!translations) return;
88
+ const trans = translations[currentLanguage];
89
+ document.querySelectorAll('[data-en]').forEach(el => {
90
+ const keyEn = el.getAttribute('data-en');
91
+ const keyAr = el.getAttribute('data-ar');
92
+ if (currentLanguage === 'ar' && keyAr) {
93
+ el.textContent = keyAr;
94
+ } else {
95
+ el.textContent = keyEn;
96
+ }
97
+ });
98
+
99
+ // Update dashboard title separately as it's not a static element
100
+ if (window.location.pathname.includes('dashboard.html')) {
101
+ const activeDashboard = document.querySelector('.sidebar-link.active');
102
+ if (activeDashboard) {
103
+ updateDashboardTitle(activeDashboard);
104
+ }
105
+ }
106
+ }
107
+
108
+ // --- HOME PAGE SPECIFIC ---
109
+ function initHomePage() {
110
+ // Scroll reveal animation
111
+ const observer = new IntersectionObserver((entries) => {
112
+ entries.forEach(entry => {
113
+ if (entry.isIntersecting) {
114
+ entry.target.classList.add('visible');
115
+ }
116
+ });
117
+ }, { threshold: 0.1 });
118
+
119
+ document.querySelectorAll('.scroll-reveal').forEach(el => {
120
+ observer.observe(el);
121
+ });
122
+ }
123
+
124
+
125
+ // --- DASHBOARD PAGE SPECIFIC ---
126
+ function initDashboards() {
127
+ const sidebarLinks = document.querySelectorAll('.sidebar-link');
128
+ sidebarLinks.forEach(link => {
129
+ link.addEventListener('click', (e) => {
130
+ e.preventDefault();
131
+
132
+ sidebarLinks.forEach(l => l.classList.remove('active'));
133
+ link.classList.add('active');
134
+
135
+ const dashboardId = link.getAttribute('data-dashboard');
136
+ document.querySelectorAll('.dashboard-content').forEach(content => {
137
+ content.classList.add('hidden');
138
+ });
139
+ document.getElementById(`dashboard-${dashboardId}`).classList.remove('hidden');
140
+ updateDashboardTitle(link);
141
+ });
142
+ });
143
+ // Set initial title
144
+ updateDashboardTitle(document.querySelector('.sidebar-link.active'));
145
+ }
146
+
147
+ function updateDashboardTitle(activeLink) {
148
+ const titleEl = document.getElementById('dashboard-title');
149
+ if (titleEl && activeLink) {
150
+ const titleText = activeLink.querySelector('span').textContent;
151
+ const dashboardText = currentLanguage === 'ar' ? 'لوحة تحكم: ' : 'Dashboard: ';
152
+ titleEl.textContent = dashboardText + titleText;
153
+ }
154
+ }
155
+
156
+
157
+ // --- VIDEO LIBRARY SPECIFIC ---
158
+ const ALL_VIDEOS = [
159
+ { id: 'dfrPtS4MSlw', title_en: "Vision 2030: A Reality Unfolding", title_ar: "رؤية 2030: واقع يتحقق", category: 'vision2030' },
160
+ { id: 'IzogBJpcEWg', title_en: "Saudi National Anthem", title_ar: "النشيد الوطني السعودي", category: 'pride' },
161
+ { id: '35g7UMVbfPc', title_en: "Rasd Platform Demo", title_ar: "عرض منصة رصد", category: 'technology' },
162
+ { id: 'kDqTPT1SQbU', title_en: "Saudi Tourism Impact", title_ar: "تأثير السياحة السعودية", category: 'vision2030' },
163
+ { id: 'h-KM2Z0YxtQ', title_en: "The Future of AI in KSA", title_ar: "مستقبل الذكاء الاصطناعي بالمملكة", category: 'technology' },
164
+ // You can add more videos here
165
+ ];
166
+
167
+ function initVideoLibrary() {
168
+ const grid = document.getElementById('video-grid');
169
+ const searchInput = document.getElementById('video-search');
170
+ const filterBtns = document.querySelectorAll('.filter-btn');
171
+
172
+ function renderVideos(videos) {
173
+ if (!grid) return;
174
+ grid.innerHTML = '';
175
+ videos.forEach(video => {
176
+ const title = currentLanguage === 'ar' ? video.title_ar : video.title_en;
177
+ const card = document.createElement('div');
178
+ card.className = 'video-card glass-card rounded-2xl overflow-hidden';
179
+ card.innerHTML = `
180
+ <div class="aspect-video">
181
+ <iframe class="w-full h-full" src="https://www.youtube.com/embed/${video.id}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
182
+ </div>
183
+ <div class="p-4">
184
+ <h3 class="font-bold text-white truncate">${title}</h3>
185
+ </div>
186
+ `;
187
+ grid.appendChild(card);
188
+ });
189
+ }
190
+
191
+ function filterAndSearch() {
192
+ const searchTerm = searchInput.value.toLowerCase();
193
+ const activeFilter = document.querySelector('.filter-btn.active').dataset.filter;
194
+
195
+ const filteredVideos = ALL_VIDEOS.filter(video => {
196
+ const matchesFilter = activeFilter === 'all' || video.category === activeFilter;
197
+ const matchesSearch = video.title_en.toLowerCase().includes(searchTerm) || video.title_ar.toLowerCase().includes(searchTerm);
198
+ return matchesFilter && matchesSearch;
199
+ });
200
+
201
+ renderVideos(filteredVideos);
202
+ }
203
+
204
+ searchInput.addEventListener('input', filterAndSearch);
205
+
206
+ filterBtns.forEach(btn => {
207
+ btn.addEventListener('click', () => {
208
+ filterBtns.forEach(b => b.classList.remove('active'));
209
+ btn.classList.add('active');
210
+ filterAndSearch();
211
+ });
212
+ });
213
+
214
+ renderVideos(ALL_VIDEOS);
215
+ }