Skip to content

Commit

Permalink
Merge pull request #3452 from projectblacklight/click_in_modal_backdr…
Browse files Browse the repository at this point in the history
…op_closes

Let a click on backdrop behind modal close the modal
  • Loading branch information
jrochkind authored Dec 5, 2024
2 parents 391979b + f9b47b1 commit 6b1d698
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 6b1d698

Please sign in to comment.