-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (42 loc) · 1.84 KB
/
script.js
File metadata and controls
50 lines (42 loc) · 1.84 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
document.addEventListener("DOMContentLoaded", function () {
const searchInput = document.getElementById("searchInput");
const searchForm = document.querySelector(".search-form");
const genreSelect = document.getElementById("genreSelect");
function filterSlides(swiperSelector) {
const query = searchInput.value.trim().toLowerCase();
const genre = genreSelect.value;
const swiperWrapper = document.querySelector(`${swiperSelector} .swiper-wrapper`);
const slides = swiperWrapper.querySelectorAll('.swiper-slide');
slides.forEach(slide => {
const name = slide.dataset.name ? slide.dataset.name.toLowerCase() : '';
const genres = slide.dataset.genre ? slide.dataset.genre.split(',') : [];
const matchesName = name.includes(query);
const matchesGenre = !genre || genres.map(g => g.trim().toLowerCase()).includes(genre.toLowerCase());
slide.style.display = (matchesName && matchesGenre) ? '' : 'none';
});
// Оновлення Swiper після фільтрації
const swiperInstance = document.querySelector(swiperSelector).swiper;
if (swiperInstance) {
swiperInstance.update();
}
}
// Початкова фільтрація при завантаженні
filterSlides('.friends-swiper');
filterSlides('.family-swiper');
// Події для пошуку
searchInput.addEventListener("input", function () {
filterSlides('.friends-swiper');
filterSlides('.family-swiper');
});
// Подія при зміні жанру
genreSelect.addEventListener("change", function () {
filterSlides('.friends-swiper');
filterSlides('.family-swiper');
});
// Подія при відправці форми
searchForm.addEventListener("submit", function (e) {
e.preventDefault();
filterSlides('.friends-swiper');
filterSlides('.family-swiper');
});
});