Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: all issues #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions src/scripts.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
document.addEventListener("DOMContentLoaded", () => {
const modal = document.getElementById("modal");
const modalImage = document.getElementById("modalImage");
const closeBtn = document.getElementById("closeBtn");
const prevBtn = document.getElementById("prevBtn");
const nextBtn = document.getElementById("nextBtn");
const modal = document.getElementById("modal");
const modalImage = document.getElementById("modalImage");
const closeBtn = document.getElementById("closeBtn");
const prevBtn = document.getElementById("prevBtn");
const nextBtn = document.getElementById("nextBtn");

const images = Array.from(document.querySelectorAll(".image"));
let currentImageIndex = 0;
const images = Array.from(document.querySelectorAll(".image"));
let currentImageIndex = 0;

// TODO: (Issue #1) Add an event listener for each image in the gallery to show it in the modal when clicked
// TODO: (Issue #1) Add an event listener for each image in the gallery to show it in the modal when clicked
images.forEach(function (image) {
image.addEventListener("click", function (event) {
currentImageIndex = images.indexOf(image);
updateModalImage();
modal.classList.remove("hidden");
});
});
// TODO: (Issue #2) Add event listeners for the prevBtn and nextBtn for modal navigation functionality
function updateModalImage(indexUpdate = 0) {
currentImageIndex += indexUpdate;
prevBtn.disabled = currentImageIndex === 0;
nextBtn.disabled = currentImageIndex === images.length - 1;
//prettier-ignore
modalImage.setAttribute("src",images[currentImageIndex].getAttribute("src"));
}

// TODO: (Issue #2) Add event listeners for the prevBtn and nextBtn for modal navigation functionality
// Clean Code Hint: Issue #1 and #2 both deal with updating the modal image based on currentImageIndex. Consider creating a function to handle this functionality.
prevBtn.addEventListener("click", function () {
updateModalImage(-1);
});
nextBtn.addEventListener("click", function () {
updateModalImage(+1);
});

// TODO: (Issue #3) Add an event listener for the closeBtn to close the modal
// Clean Code Hint: Issue #1 and #2 both deal with updating the modal image based on currentImageIndex. Consider creating a function to handle this functionality.

// TODO: (Issue #3) Add an event listener to close the modal when clicking the modal background
// TODO: (Issue #3) Add an event listener for the closeBtn to close the modal
closeBtn.addEventListener("click", function () {
modal.classList.add("hidden");
});

// TODO: (Issue #4) Create a function to update the state of the navigation buttons based on currentImageIndex
// TODO: (Issue #3) Add an event listener to close the modal when clicking the modal background
modal.addEventListener("click", function (e) {
if (e.target.id === "modal") {
modal.classList.add("hidden");
}
});

// TODO: (Issue #4) Create a function to update the state of the navigation buttons based on currentImageIndex
});