-
Notifications
You must be signed in to change notification settings - Fork 0
/
slideshow.js
85 lines (75 loc) · 2.26 KB
/
slideshow.js
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
import Swiper, { Navigation, HashNavigation } from "swiper";
import { setupNav } from "./setupNav";
import { headerAutoHideOnVerticalScroll } from "./header-auto-hide-on-vertical-scroll";
const swiper = new Swiper("#swiper-container", {
modules: [Navigation, HashNavigation],
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
hashNavigation: {
watchState: true,
},
loop: true,
});
const menuMosaicContainer = document.getElementById("menu-mosaic-container");
const hash = new URL(window.location.href).hash.substring(1);
const pictureIndex = parseInt(hash);
if (!isNaN(pictureIndex)) {
menuMosaicContainer.style.display = "none";
swiper.el.style.display = "block";
openSlideShowToPosition(pictureIndex - 1);
}
const { onNavChange, isNavOpen } = (function () {
const burgerMenuContainer = document.getElementById("burger-menu-container");
const header = document.querySelector("header");
let _isNavOpen = false;
return {
onNavChange: () => {
header.style.visibility = _isNavOpen ? "visible" : "hidden";
burgerMenuContainer.style.visibility = "visible";
burgerMenuContainer.style.position = _isNavOpen ? "absolute" : "fixed";
menuMosaicContainer.style.overflow = _isNavOpen ? "" : "hidden";
_isNavOpen = !_isNavOpen;
},
isNavOpen: () => _isNavOpen,
};
})();
setupNav(onNavChange);
document.addEventListener("keydown", (event) => {
switch (event.code) {
case "ArrowRight":
swiper.slideNext();
return;
case "ArrowLeft":
swiper.slidePrev();
return;
}
});
document.getElementById("close-swiper").addEventListener("click", () => {
menuMosaicContainer.style.display = "flex";
swiper.el.style.display = "none";
swiper.update();
});
function openSlideShowToPosition(index) {
menuMosaicContainer.style.display = "none";
swiper.el.style.display = "block";
swiper.update();
swiper.slideTo(parseInt(index) + 1, 0, false);
}
menuMosaicContainer.querySelectorAll(".thumbnail").forEach((thumbnail) => {
thumbnail.addEventListener(
"click",
({
target: {
dataset: { index },
},
}) => {
if (isNavOpen()) {
return;
}
openSlideShowToPosition(index);
}
);
});
headerAutoHideOnVerticalScroll(isNavOpen);