-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathListing_11.10.js
31 lines (26 loc) · 1.16 KB
/
Listing_11.10.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
// Activates the image gallery.
// The main task is to attach an event listener to each image in the gallery
// and respond appropriately on click.
function activateGallery() {
let thumbnails = document.querySelectorAll("#gallery-thumbs > div > img");
let mainImage = document.querySelector("#gallery-photo img");
thumbnails.forEach(function(thumbnail) {
// Preload large images.
let newImageSrc = thumbnail.dataset.largeVersion;
let largeVersion = new Image();
largeVersion.src = FILL_IN;
thumbnail.addEventListener("click", function() {
// Set clicked image as display image.
mainImage.setAttribute("src", newImageSrc);
// Change which image is current.
document.querySelector(".current").classList.remove("current");
thumbnail.parentNode.classList.add("current");
// Update image info.
let galleryInfo = document.querySelector("#gallery-info");
let title = galleryInfo.querySelector(".title");
let description = galleryInfo.querySelector(".description");
title.innerHTML = thumbnail.dataset.title;
description.innerHTML = thumbnail.dataset.description;
});
});
}