Spaces:
Running
Running
File size: 9,863 Bytes
9da818d 5d19212 |
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
// NABAD - script.js
// --- GLOBAL STATE ---
let currentLanguage = localStorage.getItem('nabadLanguage') || 'ar';
// --- INITIALIZATION ---
document.addEventListener('DOMContentLoaded', () => {
console.log("🚀 NABAD Platform Initialized");
initializeLanguage();
setupEventListeners();
if (document.getElementById('year')) {
document.getElementById('year').textContent = new Date().getFullYear();
}
// Page specific initializations
if (window.location.pathname.includes('dashboard.html')) {
initDashboards();
} else if (window.location.pathname.includes('video.html')) {
initVideoLibrary();
} else {
initHomePage();
}
});
// --- EVENT LISTENERS SETUP ---
function setupEventListeners() {
// Language toggles
document.querySelectorAll('button[onclick="toggleLanguage()"]').forEach(btn => {
btn.addEventListener('click', toggleLanguage);
});
// Smooth scrolling for homepage links
if (!window.location.pathname.includes('dashboard.html') && !window.location.pathname.includes('video.html')) {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
}
}
// --- LANGUAGE MANAGEMENT ---
function initializeLanguage() {
const htmlEl = document.getElementById('html');
if (currentLanguage === 'ar') {
htmlEl.setAttribute('lang', 'ar');
htmlEl.setAttribute('dir', 'rtl');
htmlEl.classList.add('rtl');
htmlEl.classList.remove('ltr');
} else {
htmlEl.setAttribute('lang', 'en');
htmlEl.setAttribute('dir', 'ltr');
htmlEl.classList.add('ltr');
htmlEl.classList.remove('rtl');
}
updateLanguageUI();
updateTextContent();
}
function toggleLanguage() {
currentLanguage = currentLanguage === 'en' ? 'ar' : 'en';
localStorage.setItem('nabadLanguage', currentLanguage);
initializeLanguage();
}
function updateLanguageUI() {
if (document.getElementById('lang-toggle')) {
document.getElementById('lang-toggle').textContent = currentLanguage === 'en' ? 'ع' : 'En';
}
if (document.getElementById('lang-toggle-dash')) {
document.getElementById('lang-toggle-dash').textContent = currentLanguage === 'en' ? 'ع' : 'En';
}
// Handle placeholder text for search input
const searchInput = document.getElementById('video-search');
if (searchInput) {
const placeholderText = currentLanguage === 'ar' ? 'ابحث في الفيديوهات...' : 'Search videos...';
searchInput.setAttribute('placeholder', placeholderText);
}
}
function updateTextContent() {
if (!translations) return;
const trans = translations[currentLanguage];
document.querySelectorAll('[data-en]').forEach(el => {
const keyEn = el.getAttribute('data-en');
const keyAr = el.getAttribute('data-ar');
if (currentLanguage === 'ar' && keyAr) {
el.textContent = keyAr;
} else {
el.textContent = keyEn;
}
});
// Update dashboard title separately as it's not a static element
if (window.location.pathname.includes('dashboard.html')) {
const activeDashboard = document.querySelector('.sidebar-link.active');
if (activeDashboard) {
updateDashboardTitle(activeDashboard);
}
}
}
// --- HOME PAGE SPECIFIC ---
function initHomePage() {
// Scroll reveal animation
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.scroll-reveal').forEach(el => {
observer.observe(el);
});
}
// --- DASHBOARD PAGE SPECIFIC ---
function initDashboards() {
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.getAttribute('data-dashboard');
document.querySelectorAll('.dashboard-content').forEach(content => {
content.classList.add('hidden');
});
document.getElementById(`dashboard-${dashboardId}`).classList.remove('hidden');
updateDashboardTitle(link);
});
});
// Set initial title
updateDashboardTitle(document.querySelector('.sidebar-link.active'));
}
function updateDashboardTitle(activeLink) {
const titleEl = document.getElementById('dashboard-title');
if (titleEl && activeLink) {
const titleText = activeLink.querySelector('span').textContent;
const dashboardText = currentLanguage === 'ar' ? 'لوحة تحكم: ' : 'Dashboard: ';
titleEl.textContent = dashboardText + titleText;
}
}
// --- VIDEO LIBRARY SPECIFIC ---
const ALL_VIDEOS = [
{ id: 'dfrPtS4MSlw', title_en: "Vision 2030: A Reality Unfolding", title_ar: "رؤية 2030: واقع يتحقق", category: 'vision2030' },
{ id: 'IzogBJpcEWg', title_en: "Saudi National Anthem", title_ar: "النشيد الوطني السعودي", category: 'pride' },
{ id: '35g7UMVbfPc', title_en: "Rasd Platform Demo", title_ar: "عرض منصة رصد", category: 'technology' },
{ id: 'kDqTPT1SQbU', title_en: "Saudi Tourism Impact", title_ar: "تأثير السياحة السعودية", category: 'vision2030' },
{ id: 'h-KM2Z0YxtQ', title_en: "The Future of AI in KSA", title_ar: "مستقبل الذكاء الاصطناعي بالمملكة", category: 'technology' },
// You can add more videos here
];
function initVideoLibrary() {
const grid = document.getElementById('video-grid');
const searchInput = document.getElementById('video-search');
const filterBtns = document.querySelectorAll('.filter-btn');
function renderVideos(videos) {
if (!grid) return;
grid.innerHTML = '';
videos.forEach(video => {
const title = currentLanguage === 'ar' ? video.title_ar : video.title_en;
const card = document.createElement('div');
card.className = 'video-card glass-card rounded-2xl overflow-hidden';
card.innerHTML = `
<div class="aspect-video">
<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>
</div>
<div class="p-4">
<h3 class="font-bold text-white truncate">${title}</h3>
</div>
`;
grid.appendChild(card);
});
}
function filterAndSearch() {
const searchTerm = searchInput.value.toLowerCase();
const activeFilter = document.querySelector('.filter-btn.active').dataset.filter;
const filteredVideos = ALL_VIDEOS.filter(video => {
const matchesFilter = activeFilter === 'all' || video.category === activeFilter;
const matchesSearch = video.title_en.toLowerCase().includes(searchTerm) || video.title_ar.toLowerCase().includes(searchTerm);
return matchesFilter && matchesSearch;
});
renderVideos(filteredVideos);
}
searchInput.addEventListener('input', filterAndSearch);
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
filterAndSearch();
});
});
renderVideos(ALL_VIDEOS);
}
// --- BACKGROUND MUSIC PLAYER ---
let player;
let musicPlaying = false;
// This function creates an <iframe> (YouTube player) after the API code downloads.
function onYouTubeIframeAPIReady() {
player = new YT.Player('youtube-player', {
height: '0',
width: '0',
videoId: 'IzogBJpcEWg', // Saudi National Anthem Video ID
playerVars: {
'autoplay': 0,
'controls': 0,
'loop': 1,
'playlist': 'IzogBJpcEWg', // Required for loop to work
'volume': 30 // Set volume to 30%
},
events: {
'onReady': onPlayerReady
}
});
}
// The API will call this function when the video player is ready.
function onPlayerReady(event) {
// Player is ready, you could optionally play on load here, but we'll use a button
// event.target.playVideo();
}
// Function to toggle music play/pause
function toggleBackgroundMusic() {
const toggleButton = document.getElementById('music-toggle');
if (musicPlaying) {
player.pauseVideo();
toggleButton.innerHTML = '<i class="fas fa-music text-xl"></i>';
toggleButton.classList.remove('bg-brand-gold'); // Remove active state color
musicPlaying = false;
} else {
player.playVideo();
toggleButton.innerHTML = '<i class="fas fa-pause text-xl"></i>';
toggleButton.classList.add('bg-brand-gold'); // Add active state color
musicPlaying = true;
}
}
// Add event listener to the button
document.addEventListener('DOMContentLoaded', () => {
const musicButton = document.getElementById('music-toggle');
if (musicButton) {
musicButton.addEventListener('click', toggleBackgroundMusic);
}
}); |