fix: Listen for show.bs.modal on document (#5565)

Avoids losing the listener when DOM is changed dynamically.
This commit is contained in:
Jennifer Richards 2023-05-02 14:50:38 -04:00 committed by GitHub
parent 1359a5998f
commit 6986cae1bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -255,10 +255,12 @@ $(document)
// Bootstrap doesn't load modals via href anymore, so let's do it ourselves.
// See https://stackoverflow.com/a/48934494/2240756
// Instead of attaching to the modal elements as in that example, though,
// listen on document and filter with the .modal selector. This allows handling
// of modals that are added dynamically (e.g., list.js apparently replaces DOM
// elements with identical copies, minus any attached listeners).
$(document)
.ready(function () {
$('.modal')
.on('show.bs.modal', function (e) {
.on('show.bs.modal', '.modal', function (e) {
var button = $(e.relatedTarget);
if (!$(button)
.attr("href")) {
@ -274,7 +276,6 @@ $(document)
.load(loc);
}
});
});
// Handle history snippet expansion.
$(document)