PageSourceSearch

https://www.imedd.org/wp-content/plugins/imedd-2021/assets/slideshow-nav.js?ver=1638353381

js imedd.org collected 2026-10-02 02:57:28 UTC 3,479 bytes, 110 lines download raw bytes

1(function () {
2	'use strict';
3	const selector = '.wp-block-imedd-slideshow';
4	const buttons = document.querySelectorAll('.slideshow-nav--btn');
5	const body = document.body;
6	for (const button of buttons) {
7		const slideshow = button.closest(selector);
8		const nextBlock = slideshow.nextElementSibling;
9		const scrollContainer = slideshow.querySelector('.slideshow-container');
10		const firstSlide = slideshow.querySelector('.wp-block-imedd-slide');
11		const firstSlideHeight = firstSlide.offsetHeight;
12		button.onclick = function () {
13			const activeSlide = slideshow.querySelector('.wp-block-imedd-slide.is-visible');
14			const nextSlide = activeSlide.nextElementSibling;
15			if (nextSlide) {
16				nextSlide.scrollIntoView();
17			} else {
18				nextBlock.scrollIntoView({behavior: 'smooth'});
19			}
20		}
21		scrollEventThrottle((scrollPos) => {
22			const activeSlide = slideshow.querySelector('.wp-block-imedd-slide.is-visible');
23			if (scrollPos >= firstSlideHeight && activeSlide) {
24				body.classList.add('is-past-first-slide');
25			} else {
26				body.classList.remove('is-past-first-slide');
27			}
28		});
29		wheelEventThrottle();
30		keypressThrottle();
31
32		function scrollEventThrottle(fn) {
33			let last_known_scroll_position = 0;
34			let ticking = false;
35			scrollContainer.addEventListener('scroll', function () {
36				last_known_scroll_position = scrollContainer.scrollTop;
37				if (!ticking) {
38					window.requestAnimationFrame(function () {
39						fn(last_known_scroll_position);
40						ticking = false;
41					});
42					ticking = true;
43				}
44			});
45		}
46
47		function wheelEventThrottle() {
48			let isScrolling;
49			scrollContainer.addEventListener('wheel', function (e) {
50				let dir;
51				if (e.deltaY < 0) {
52					dir = 'up';
53				}
54				if (e.deltaY > 0) {
55					dir = 'down';
56				}
57				const activeSlide = slideshow.querySelector('.wp-block-imedd-slide.is-visible');
58				const prevSlide = activeSlide.previousElementSibling;
59				const nextSlide = activeSlide.nextElementSibling;
60				e.preventDefault();
61				clearTimeout(isScrolling);
62				if (('down' === dir && nextSlide) || ('up' === dir && prevSlide)) {
63					if (!scrollContainer.classList.contains('scrolling')) {
64						scrollContainer.classList.add('scrolling');
65					}
66					isScrolling = setTimeout(function () {
67						scrollContainer.classList.remove('scrolling');
68						if ('down' === dir) {
69							nextSlide.scrollIntoView();
70						} else {
71							prevSlide.scrollIntoView();
72						}
73					}, 200);
74				} else if ('down' === dir && !nextSlide) {
75					isScrolling = setTimeout(function () {
76						nextBlock.scrollIntoView({behavior: 'smooth'});
77					}, 200);
78
79				}
80			}, {passive: false});
81		}
82
83		function keypressThrottle() {
84			let isPressing;
85			document.addEventListener('keydown', function (e) {
86				const key = e.key;
87				if (!slideshow.classList.contains('is-visible') || !['ArrowUp', 'ArrowDown'].includes(key)) {
88					return;
89				}
90				const activeSlide = slideshow.querySelector('.wp-block-imedd-slide.is-visible');
91				const prevSlide = activeSlide.previousElementSibling;
92				const nextSlide = activeSlide.nextElementSibling;
93				clearTimeout(isPressing);
94				e.preventDefault();
95				isPressing = setTimeout(function () {
96					if ('ArrowUp' === key && prevSlide) {
97						prevSlide.scrollIntoView();
98					}
99					if ('ArrowDown' === key) {
100						if (nextSlide) {
101							nextSlide.scrollIntoView();
102						} else {
103							nextBlock.scrollIntoView({behavior: 'smooth'});
104						}
105					}
106				}, 300);
107			}, {passive: false});
108		}
109	}
110})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.