Skip to content

Commit

Permalink
Merge branch 'development' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dofxo committed Sep 13, 2023
2 parents a5cf2b5 + 87832df commit ad35834
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
1 change: 1 addition & 0 deletions public/src/css/silverBox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ body {
left: 0;
justify-content: center;
background-color: var(--silverBox-overlay-background);
z-index: calc(var(--silverBox-z-index) - 1);
}

.silverBox {
Expand Down
2 changes: 1 addition & 1 deletion public/src/js/components/silverBox/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function silverBoxButtonComponent(
if (buttonName.closeOnClick !== false) {
// Closes silverBox on click an run onClose function if it exits
buttonEl.addEventListener("click", () => {
silverBoxClose({ onClose: onCloseConfig });
silverBoxClose({ onClose: onCloseConfig, element: buttonEl });
});
}

Expand Down
20 changes: 6 additions & 14 deletions public/src/js/helpers/closeButtonOnClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@
import silverBoxDisableScroll from "./silverBox/disableScroll";
/** selects the silverBox container and closes the element*/
function silverBoxClose({ uniqueID, timer, onClose, element }) {
// if the modal doesn't have a timer, the modal will be closed on click
if (!timer) {
// selects the all silverBox-container classes in the page
const silverBox = document.querySelectorAll(".silverBox-container");

if (silverBox[silverBox.length - 1])
silverBox[silverBox.length - 1].remove();
// checks for silverBoxAfter removing the wrapper
silverBoxDisableScroll(".silverBox-overlay");
}
// If timer exits specific modal will be removed from page
else if (timer) {
// If timer config exists, silverBoxCloseAfterTimeout would get a uniqueID and will close the silverBox using that ID
if (timer) {
silverBoxCloseAfterTimeout(uniqueID);
} else if (element) {
element.closest(".silverBox").remove();
}
// if there is a element passed to silverBoxClose object, the closest silverBox-container to that element would be removed
else if (element) {
element.closest(".silverBox-container").remove();
}

// Runs onClose function if it exits
Expand Down
25 changes: 12 additions & 13 deletions public/src/js/silverBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,21 @@ function silverBox(config = {}) {

// Select silverBox overlay to give it an eventListener.
let silverBoxOverlay = document.querySelectorAll(".silverBox-overlay");
silverBoxOverlay = silverBoxOverlay[silverBoxOverlay.length - 1];

// if the clicked element has classList of silverBox-overlay this code will be executed.
if (silverBoxOverlay) {
for (const overlay of silverBoxOverlay) {
overlay.addEventListener("click", (e) => {
// closes the modal if the user clicks on the overlay (outside of the modal).
if (e.target === overlay) {
silverBoxClose({
onClose: config.onClose,
element: overlay,
});
}
// checks for silverBox after removing wrapper.
silverBoxDisableScroll(".silverBox-overlay");
});
}
silverBoxOverlay.addEventListener("click", (e) => {
// closes the modal if the user clicks on the overlay (outside of the modal).
if (e.target === silverBoxOverlay) {
silverBoxClose({
onClose: config.onClose,
element: silverBoxOverlay,
});
}
// checks for silverBox after removing wrapper.
silverBoxDisableScroll(".silverBox-overlay");
});
}

// Checks for silverBox after it's created.
Expand Down

0 comments on commit ad35834

Please sign in to comment.