Skip to content

Commit

Permalink
Merge pull request #337 from wri/issue-487-donate
Browse files Browse the repository at this point in the history
Issue #487 cta banners changes.
  • Loading branch information
mariacha authored Nov 27, 2024
2 parents 6404b7f + 4ec4c26 commit d8c2b6b
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions themes/custom/ts_wrin/js/components/wri_cta_banners.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ export default function(context) {
const modals = context.querySelectorAll(".region-top-modals .block-modal");
const ctaCookie = "wri_cta_displayed";
const thankYouCookie = "wri_cta_thank_you";
const modalButtons = context.querySelectorAll(
".region-top-modals .block-modal .button"
);

modalButtons.forEach(function(button) {
button.addEventListener("click", function() {
const modal = button.closest(".block-modal");
modal.style.display = "none";
});
});

// Accessibility: aria-live region for announcements
const announceRegion = document.createElement("div");
Expand Down Expand Up @@ -50,7 +60,7 @@ export default function(context) {
1
);
document.removeEventListener("keydown", closeOnEscape);
document.removeEventListener("click", clickOutsideModal);
//document.removeEventListener("click", clickOutsideModal);
announce("Modal closed.");
}

Expand All @@ -63,25 +73,25 @@ export default function(context) {
}
}

function clickOutsideModal(event) {
const visibleModal = context.querySelector(
'.block-modal[style*="display: block"]'
);
if (
visibleModal &&
!visibleModal.querySelector(".modal_inner").contains(event.target)
) {
closeModal(visibleModal);
}
}
// function clickOutsideModal(event) {
// const visibleModal = context.querySelector(
// '.block-modal[style*="display: block"]'
// );
// if (
// visibleModal &&
// !visibleModal.querySelector(".modal_inner").contains(event.target)
// ) {
// closeModal(visibleModal);
// }
// }

function showModal(modal) {
modal.style.display = "block";
modal.querySelector(".modal-close").addEventListener("click", function() {
closeModal(modal);
});
document.addEventListener("keydown", closeOnEscape);
document.addEventListener("click", clickOutsideModal);
//document.addEventListener("click", clickOutsideModal);
announce(
"A message for you: " +
modal.querySelector(".field--name-field-title").textContent
Expand Down Expand Up @@ -124,8 +134,7 @@ export default function(context) {
showModal(selectedModal);
}

const classyCookie = getCookie("classy_donation");
const hasDonated = classyCookie && classyCookie === "true";
const hasDonated = getCookie("donation_success");

if (!getCookie(thankYouCookie) && hasDonated) {
displayThankYouModal();
Expand Down

0 comments on commit d8c2b6b

Please sign in to comment.