Skip to content

Commit

Permalink
modified popup.js
Browse files Browse the repository at this point in the history
  • Loading branch information
j0ell1 committed Oct 14, 2024
1 parent 4b2cf75 commit 6b65b07
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
const icon = document.getElementById('infoIcon');
const popup = document.getElementById('popupInfo');
const popup = document.getElementById('popupInfo');
let popupOpen = false; // Track if the popup is open

// Show popup when clicking on the icon
icon.addEventListener('click', (e) => {
e.stopPropagation(); // Prevents the click from triggering the window event
popup.style.display = 'block';
});
// Show popup when clicking on the icon
icon.addEventListener('click', (e) => {
e.stopPropagation(); // Prevents the window click event from firing
popup.style.display = popupOpen ? 'none' : 'block'; // Toggle the popup's visibility
popupOpen = !popupOpen; // Update the state
});

// Hide popup when clicking outside the popup or icon
window.addEventListener('click', (e) => {
if (!popup.contains(e.target) && e.target !== icon && !icon.contains(e.target)) {
popup.style.display = 'none';
}
});
// Hide popup when clicking outside the popup or icon
window.addEventListener('click', (e) => {
if (popupOpen && !popup.contains(e.target) && !icon.contains(e.target)) {
popup.style.display = 'none'; // Hide the popup
popupOpen = false; // Update the state
}
});

// Prevent closing the popup when clicking inside it
popup.addEventListener('click', (e) => {
e.stopPropagation(); // Prevents closing the popup when clicking inside it
});
// Prevent closing the popup when clicking inside it
popup.addEventListener('click', (e) => {
e.stopPropagation(); // Prevents closing the popup when clicking inside it
});

0 comments on commit 6b65b07

Please sign in to comment.