-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (127 loc) · 5.3 KB
/
Copy pathscript.js
File metadata and controls
149 lines (127 loc) · 5.3 KB
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
// قاموس الترجمة المخصص للمنصة بالاسم الجديد الفخم PixelPulse
const translations = {
ar: {
mainTitle: "PixelPulse المعرض الإبداعي",
subTitle: "مشروع الـ Frontend - التدريب العملي لـ CodeAlpha",
filterAll: "الكل",
filterNature: "طبيعة",
filterArch: "معمار",
filterTech: "تقنية",
filterAnimals: "حيوانات"
},
en: {
mainTitle: "PixelPulse Showcase",
subTitle: "Frontend Project - CodeAlpha Practical Internship",
filterAll: "All",
filterNature: "Nature",
filterArch: "Architecture",
filterTech: "Technology",
filterAnimals: "Animals"
}
};
const themeToggle = document.getElementById('theme-toggle');
const langToggle = document.getElementById('lang-toggle');
const langText = document.getElementById('lang-text');
const html = document.documentElement;
const galleryItems = document.querySelectorAll('.gallery-item');
const filterButtons = document.querySelectorAll('.filter-buttons .btn');
const lightbox = document.querySelector('.lightbox');
const lightboxImg = document.querySelector('.lightbox-content img');
const lightboxCaption = document.querySelector('.lightbox .caption');
const closeBtn = document.querySelector('.close-btn');
const prevBtn = document.querySelector('.prev-btn');
const nextBtn = document.querySelector('.next-btn');
let currentLang = 'ar';
let currentIndex = 0;
let activeImages = [...galleryItems];
// التبديل السلس بين اللغات
langToggle.addEventListener('click', () => {
currentLang = currentLang === 'ar' ? 'en' : 'ar';
updateLanguage();
});
function updateLanguage() {
langText.textContent = currentLang === 'ar' ? 'EN' : 'AR';
// ترجمة النصوص العامة المتواجدة في الصفحة
document.querySelectorAll('[data-i18n]').forEach(element => {
const key = element.getAttribute('data-i18n');
if (translations[currentLang][key]) {
element.textContent = translations[currentLang][key];
}
});
// ترجمة عناوين الصور ديناميكياً لتجنب اختلاف الطول والارتفاع
galleryItems.forEach(item => {
const titleSpan = item.querySelector('.title');
const text = titleSpan.getAttribute(`data-${currentLang}`);
titleSpan.textContent = text;
});
if (lightbox.classList.contains('active')) {
const activeItem = activeImages[currentIndex];
lightboxCaption.textContent = activeItem.querySelector('.title').textContent;
}
}
// التحكم بالوضع الليلي والنهاري (Dark / Light)
themeToggle.addEventListener('click', () => {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', newTheme);
const icon = themeToggle.querySelector('i');
icon.className = newTheme === 'dark' ? 'fas fa-sun' : 'fas fa-moon';
});
// تصفية الفئات بدقة عالية
filterButtons.forEach(button => {
button.addEventListener('click', () => {
document.querySelector('.filter-buttons .btn.active').classList.remove('active');
button.classList.add('active');
const filterValue = button.getAttribute('data-filter');
activeImages = [];
galleryItems.forEach(item => {
if (filterValue === 'all' || item.getAttribute('data-category') === filterValue) {
item.style.display = 'block';
activeImages.push(item);
} else {
item.style.display = 'none';
}
});
});
});
// تفعيل نافذة العرض الـ Lightbox
galleryItems.forEach(item => {
item.addEventListener('click', () => {
currentIndex = activeImages.indexOf(item);
if (currentIndex !== -1) {
showImage(activeImages[currentIndex]);
}
});
});
function showImage(item) {
const imgSrc = item.querySelector('img').getAttribute('src');
const imgCaption = item.querySelector('.title').textContent;
lightboxImg.setAttribute('src', imgSrc);
lightboxCaption.textContent = imgCaption;
lightbox.classList.add('active');
}
nextBtn.addEventListener('click', () => {
if (activeImages.length <= 1) return;
currentIndex++;
if (currentIndex >= activeImages.length) currentIndex = 0;
showImage(activeImages[currentIndex]);
});
prevBtn.addEventListener('click', () => {
if (activeImages.length <= 1) return;
currentIndex--;
if (currentIndex < 0) currentIndex = activeImages.length - 1;
showImage(activeImages[currentIndex]);
});
closeBtn.addEventListener('click', () => lightbox.classList.remove('active'));
lightbox.addEventListener('click', (e) => {
if (e.target === lightbox) lightbox.classList.remove('active');
});
// التصفح الذكي عن طريق لوحة المفاتيح الأزرار (Keyboard Navigation)
document.addEventListener('keydown', (e) => {
if (!lightbox.classList.contains('active')) return;
if (e.key === 'Escape') lightbox.classList.remove('active');
if (e.key === 'ArrowRight') prevBtn.click();
if (e.key === 'ArrowLeft') nextBtn.click();
});
// تشغيل اللغة الافتراضية
updateLanguage();