function launchSlideshow()

in apps-rendering/src/client/nativeCommunication.ts [148:179]


function launchSlideshow(src: string | null): void {
	const images = Array.from(
		document.querySelectorAll('.js-launch-slideshow'),
	);
	const title = document.title;
	const imagesWithCaptions: Image[] = images.flatMap((image: Element) => {
		if (image instanceof HTMLImageElement) {
			const url = image.currentSrc === '' ? image.src : image.currentSrc;
			const caption = image.getAttribute('data-caption') ?? undefined;
			const credit = image.getAttribute('data-credit') ?? undefined;
			const width = getImageWidth(url);
			const height =
				width * parseFloat(image.getAttribute('data-ratio') ?? '0.56');
			if (isNaN(width) || isNaN(height)) {
				return [];
			}
			return new Image({ url, caption, credit, width, height });
		} else {
			return [];
		}
	});
	const clickedImageIndex = images.findIndex(
		(image: Element) => image.getAttribute('src') === src,
	);
	if (imagesWithCaptions.length && clickedImageIndex >= 0) {
		void galleryClient.launchSlideshow(
			imagesWithCaptions,
			clickedImageIndex,
			title,
		);
	}
}