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

Let a click on backdrop behind modal close the modal #3452

Open
wants to merge 1 commit 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
10 changes: 6 additions & 4 deletions app/javascript/blacklight-frontend/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ const Modal = (() => {
};

modal.setupModal = function() {
// Register both trigger and preserve selectors in ONE event handler, combining
// into one selector with a comma, so if something matches BOTH selectors, it
// still only gets the event handler called once.
// Register several click handlers in ONE event handler for efficiency
//
// * close button OR click on backdrop (modal.modalSelector) closes modal
// * trigger and preserve link in modal functionality -- if somethign matches both trigger and
// preserve, still only called once.
document.addEventListener('click', (e) => {
if (e.target.closest(`${modal.triggerLinkSelector}, ${modal.preserveLinkSelector}`))
modal.modalAjaxLinkClick(e)
else if (e.target.closest('[data-bl-dismiss="modal"]'))
else if (e.target.matches(`${modal.modalSelector}`) || e.target.closest('[data-bl-dismiss="modal"]'))
modal.hide()
})
};
Expand Down