fix: Listen for show.bs.modal on document (#5565)
Avoids losing the listener when DOM is changed dynamically.
This commit is contained in:
parent
1359a5998f
commit
6986cae1bf
|
@ -255,25 +255,26 @@ $(document)
|
||||||
|
|
||||||
// Bootstrap doesn't load modals via href anymore, so let's do it ourselves.
|
// Bootstrap doesn't load modals via href anymore, so let's do it ourselves.
|
||||||
// See https://stackoverflow.com/a/48934494/2240756
|
// 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)
|
$(document)
|
||||||
.ready(function () {
|
.on('show.bs.modal', '.modal', function (e) {
|
||||||
$('.modal')
|
var button = $(e.relatedTarget);
|
||||||
.on('show.bs.modal', function (e) {
|
if (!$(button)
|
||||||
var button = $(e.relatedTarget);
|
.attr("href")) {
|
||||||
if (!$(button)
|
return;
|
||||||
.attr("href")) {
|
}
|
||||||
return;
|
var loc = $(button)
|
||||||
}
|
.attr("href")
|
||||||
var loc = $(button)
|
.trim();
|
||||||
.attr("href")
|
// load content from value of button href
|
||||||
.trim();
|
if (loc !== undefined && loc !== "#") {
|
||||||
// load content from value of button href
|
$(this)
|
||||||
if (loc !== undefined && loc !== "#") {
|
.find('.modal-content')
|
||||||
$(this)
|
.load(loc);
|
||||||
.find('.modal-content')
|
}
|
||||||
.load(loc);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle history snippet expansion.
|
// Handle history snippet expansion.
|
||||||
|
|
Loading…
Reference in a new issue