322 lines
10 KiB
TypeScript
322 lines
10 KiB
TypeScript
// import Swiper JS
|
|
import Swiper, { Navigation, Pagination, Autoplay } from "swiper";
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const swiperConfig = {
|
|
swiperHero: {
|
|
modules: [Autoplay, Pagination],
|
|
speed: 300, //default
|
|
loop: false,
|
|
loopedSlides: 4,
|
|
// autoplay: false,
|
|
autoplay: {
|
|
delay: 5000, // ALSO CHANGE CSS ".animate .slide-hero-progress-bar::after" SELECTOR TOO (home.scss)
|
|
disableOnInteraction: false,
|
|
},
|
|
pagination: {
|
|
el: ".swiper-hero-pagination",
|
|
clickable: true,
|
|
},
|
|
on: {
|
|
init: function () {
|
|
const swiperProgressBars = document.getElementsByClassName(
|
|
"swiper-hero-progress-bar"
|
|
) as HTMLCollectionOf<HTMLDivElement>;
|
|
|
|
for (const progressBar of swiperProgressBars) {
|
|
progressBar.classList.remove("animate");
|
|
progressBar.classList.remove("active");
|
|
progressBar.classList.add("animate");
|
|
progressBar.classList.add("active");
|
|
}
|
|
},
|
|
slideChangeTransitionStart: function () {
|
|
const swiperProgressBars = document.getElementsByClassName(
|
|
"swiper-hero-progress-bar"
|
|
) as HTMLCollectionOf<HTMLDivElement>;
|
|
|
|
for (const progressBar of swiperProgressBars) {
|
|
progressBar.classList.remove("animate");
|
|
progressBar.classList.remove("active");
|
|
progressBar.classList.add("active");
|
|
}
|
|
},
|
|
slideChangeTransitionEnd: function () {
|
|
const swiperProgressBars = document.getElementsByClassName(
|
|
"swiper-hero-progress-bar"
|
|
) as HTMLCollectionOf<HTMLDivElement>;
|
|
|
|
for (const progressBar of swiperProgressBars) {
|
|
progressBar.classList.add("animate");
|
|
}
|
|
},
|
|
},
|
|
},
|
|
|
|
swiperActivity: {
|
|
modules: [Navigation],
|
|
speed: 400,
|
|
loop: true,
|
|
slidesPerView: 1,
|
|
spaceBetween: 0,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-act-btn-next",
|
|
prevEl: ".swiper-act-btn-prev",
|
|
},
|
|
breakpoints: {
|
|
// when window width is >= 992px
|
|
992: {
|
|
slidesPerView: 2,
|
|
spaceBetween: 10,
|
|
},
|
|
// when window width is >= 1200px
|
|
1200: {
|
|
slidesPerView: 3,
|
|
spaceBetween: 10,
|
|
},
|
|
},
|
|
},
|
|
|
|
swiperRanges: {
|
|
modules: [Navigation],
|
|
loop: true,
|
|
slidesPerView: 1,
|
|
spaceBetween: 10,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-btn-ranges-next",
|
|
prevEl: ".swiper-btn-ranges-prev",
|
|
},
|
|
},
|
|
|
|
swiperIndicators: {
|
|
modules: [Navigation],
|
|
speed: 400,
|
|
loop: true,
|
|
slidesPerView: 1,
|
|
spaceBetween: 0,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-indic-btn-next",
|
|
prevEl: ".swiper-indic-btn-prev",
|
|
},
|
|
breakpoints: {
|
|
// when window width is >= 992px
|
|
992: {
|
|
slidesPerView: 2,
|
|
spaceBetween: 10,
|
|
},
|
|
// when window width is >= 1200px
|
|
1200: {
|
|
slidesPerView: 3,
|
|
spaceBetween: 10,
|
|
},
|
|
},
|
|
},
|
|
|
|
swiperEngagment: {
|
|
modules: [Navigation, Autoplay],
|
|
speed: 4000,
|
|
loop: true,
|
|
slidesPerView: 1,
|
|
spaceBetween: 0,
|
|
autoplay: {
|
|
delay: 3000,
|
|
disableOnInteraction: false,
|
|
},
|
|
navigation: {
|
|
nextEl: ".swiper-engag-btn-next",
|
|
prevEl: ".swiper-engag-btn-prev",
|
|
},
|
|
breakpoints: {
|
|
// when window width is >= 992px
|
|
992: {
|
|
slidesPerView: 2,
|
|
spaceBetween: 10,
|
|
},
|
|
// when window width is >= 1200px
|
|
1200: {
|
|
slidesPerView: 3,
|
|
spaceBetween: 10,
|
|
},
|
|
},
|
|
},
|
|
|
|
swiperNews: {
|
|
modules: [Navigation],
|
|
loop: true,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-news-btn-next",
|
|
prevEl: ".swiper-news-btn-prev",
|
|
},
|
|
},
|
|
|
|
swiperPosts: {
|
|
modules: [Navigation],
|
|
loop: true,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-posts-btn-next",
|
|
prevEl: ".swiper-posts-btn-prev",
|
|
},
|
|
},
|
|
|
|
swiperRecipes: {
|
|
modules: [Navigation],
|
|
loop: true,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-recipes-btn-next",
|
|
prevEl: ".swiper-recipes-btn-prev",
|
|
},
|
|
},
|
|
|
|
swiperStory: {
|
|
modules: [Navigation, Autoplay],
|
|
speed: 300,
|
|
loop: true,
|
|
slidesPerView: 1,
|
|
spaceBetween: 30,
|
|
centeredSlides: true,
|
|
autoplay: false,
|
|
navigation: {
|
|
nextEl: ".swiper-story-btn-next",
|
|
prevEl: ".swiper-story-btn-prev",
|
|
},
|
|
breakpoints: {
|
|
576: { spaceBetween: 50 },
|
|
768: { spaceBetween: 90 },
|
|
992: { spaceBetween: 125 },
|
|
},
|
|
},
|
|
|
|
swiperProduct: {
|
|
modules: [Pagination],
|
|
loop: true,
|
|
autoplay: false,
|
|
pagination: {
|
|
el: ".swiper-product-pagination",
|
|
clickable: true,
|
|
},
|
|
},
|
|
|
|
swiperOtherProducts: {
|
|
speed: 300,
|
|
loop: true,
|
|
slidesPerView: 1,
|
|
spaceBetween: 15,
|
|
centeredSlides: true,
|
|
autoplay: false,
|
|
breakpoints: {
|
|
576: { spaceBetween: 50 },
|
|
},
|
|
},
|
|
};
|
|
type SwiperSlider = {
|
|
element: HTMLElement;
|
|
swiper: Swiper;
|
|
};
|
|
const swiperLgp = document.getElementsByClassName(
|
|
"swiper-lgp"
|
|
) as HTMLCollectionOf<HTMLElement>,
|
|
sliders: SwiperSlider[] = [];
|
|
|
|
for (const htmlElt of swiperLgp) {
|
|
if (!swiperConfig[htmlElt.id as keyof typeof swiperConfig]) {
|
|
throw new Error(`Undefined swiper id ${htmlElt.id}`);
|
|
}
|
|
|
|
sliders.push({
|
|
element: htmlElt,
|
|
swiper: new Swiper(
|
|
htmlElt,
|
|
swiperConfig[htmlElt.id as keyof typeof swiperConfig]
|
|
),
|
|
});
|
|
}
|
|
|
|
const heroSwiperSlider = sliders.find((value) => {
|
|
if (value.element.id === "swiperHero") return value;
|
|
});
|
|
const itemsSlider = document.getElementsByClassName(
|
|
"thumbnails-item"
|
|
) as HTMLCollectionOf<HTMLDivElement>;
|
|
|
|
for (let iIndexThumb = 0; iIndexThumb < itemsSlider.length; iIndexThumb++) {
|
|
itemsSlider[iIndexThumb].addEventListener("click", () => {
|
|
if (heroSwiperSlider) {
|
|
heroSwiperSlider.swiper.slideTo(iIndexThumb);
|
|
}
|
|
});
|
|
}
|
|
|
|
const storySwiperSlider = sliders.find((value) => {
|
|
if (value.element.id === "swiperStory") return value;
|
|
});
|
|
|
|
if (storySwiperSlider) {
|
|
const prevBtnStory = document.querySelector(
|
|
".swiper-story-btn-prev"
|
|
) as HTMLDivElement | null;
|
|
const nextBtnStory = document.querySelector(
|
|
".swiper-story-btn-next"
|
|
) as HTMLDivElement | null;
|
|
|
|
if (prevBtnStory) {
|
|
prevBtnStory.addEventListener("click", (e: MouseEvent) => {
|
|
e.preventDefault();
|
|
moveDateWrapper();
|
|
});
|
|
}
|
|
if (nextBtnStory) {
|
|
nextBtnStory.addEventListener("click", (e: MouseEvent) => {
|
|
e.preventDefault();
|
|
moveDateWrapper();
|
|
});
|
|
}
|
|
const moveDateWrapper = () => {
|
|
const dateWrapper = document.querySelector(
|
|
".frame-wrapper"
|
|
) as HTMLDivElement | null;
|
|
if (dateWrapper) {
|
|
const dateText = document.querySelector(
|
|
".frame-text"
|
|
) as HTMLParagraphElement | null;
|
|
if (dateText) {
|
|
// dateText.textContent = "";
|
|
switch (storySwiperSlider.swiper.activeIndex) {
|
|
case 0:
|
|
dateWrapper.style.left = "100%";
|
|
dateText.textContent = "1970";
|
|
break;
|
|
case 1:
|
|
dateWrapper.style.left = "0%";
|
|
dateText.textContent = "1909";
|
|
break;
|
|
case 2:
|
|
dateWrapper.style.left = "33%";
|
|
dateText.textContent = "1937";
|
|
break;
|
|
case 3:
|
|
dateWrapper.style.left = "66%";
|
|
dateText.textContent = "1968";
|
|
break;
|
|
case 4:
|
|
dateWrapper.style.left = "100%";
|
|
dateText.textContent = "1970";
|
|
break;
|
|
case 5:
|
|
dateWrapper.style.left = "0%";
|
|
dateText.textContent = "1909";
|
|
break;
|
|
default:
|
|
dateWrapper.style.left = "0%";
|
|
dateText.textContent = "1909";
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|